Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 51 additions & 53 deletions src/main/java/com/openshift/client/OpenShiftConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,63 @@ protected IHttpClient createClient(final String clientId, final String username,
.client();
}

protected IOpenShiftConnection getConnection(final String clientId, final String username, final String password,
final String token, final String serverUrl, IHttpClient httpClient) throws OpenShiftException, IOException {
Assert.notNull(clientId);
Assert.notNull(serverUrl);
Assert.notNull(httpClient);

IRestService service = new RestService(serverUrl, clientId, new JsonMediaType(),
IHttpClient.MEDIATYPE_APPLICATION_JSON, new OpenShiftJsonDTOFactory(), httpClient);
return getConnection(service, username, password, token);
}

/**
* Establish a connection with the clientId along with a user's
* authorization token
*
* @param clientId
* http client id
* @param token
* authorization token.
* @param serverUrl
* the server url.
* @return a valid connection
* @throws FileNotFoundException
* @throws IOException
* @throws OpenShiftException
*/
public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token, final String serverUrl)
throws OpenShiftException {
return getConnection(clientId, null, null, null, null, token, serverUrl, null);
}

/**
* Establish a connection with the clientId along with a user's
* authorization token. Server URL is retrieved from the local configuration
* file (in see $USER_HOME/.openshift/express.conf)
*
* @param clientId
* http client id
* @param token
* authorization token.
* @return a valid connection
* @throws FileNotFoundException
* @throws IOException
* @throws OpenShiftException
*/
public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token)
throws OpenShiftException {
return getConnection(clientId, null, null, null, null, token, getConfiguration().getLibraServer(), null);
}

protected IOpenShiftConfiguration getConfiguration() throws OpenShiftException {
if (this.configuration == null) {
this.configuration = createConfiguration();
}
return this.configuration;
}

protected IOpenShiftConfiguration createConfiguration() throws OpenShiftException {
try {
return new OpenShiftConfiguration();
Expand All @@ -196,56 +246,4 @@ protected IOpenShiftConfiguration createConfiguration() throws OpenShiftExceptio
}
}

protected IOpenShiftConnection getConnection(final String clientId, final String username, final String password,
final String token, final String serverUrl, IHttpClient httpClient) throws OpenShiftException, IOException {
Assert.notNull(clientId);
Assert.notNull(serverUrl);
Assert.notNull(httpClient);

IRestService service = new RestService(serverUrl, clientId, new JsonMediaType(),
IHttpClient.MEDIATYPE_APPLICATION_JSON, new OpenShiftJsonDTOFactory(), httpClient);
return getConnection(service, username, password, token);
}

/**
* Establish a connection with the clientId along with a user's authorization token
*
* @param clientId
* http client id
* @param token
* authorization token.
* @param serverUrl
* the server url.
* @return a valid connection
* @throws FileNotFoundException
* @throws IOException
* @throws OpenShiftException
*/
public IOpenShiftConnection getAuthTokenConnection(final String clientId,final String token, final String serverUrl) throws OpenShiftException {
return getConnection(clientId, null, null, null, null, token, serverUrl, null);
}
/**
* Establish a connection with the clientId along with a user's authorization
* token. Server URL is retrieved from the local configuration file (in
* see $USER_HOME/.openshift/express.conf)
*
* @param clientId
* http client id
* @param token
* authorization token.
* @return a valid connection
* @throws FileNotFoundException
* @throws IOException
* @throws OpenShiftException
*/
public IOpenShiftConnection getAuthTokenConnection(final String clientId, final String token)
throws OpenShiftException {
try {
configuration = new OpenShiftConfiguration();
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to load OpenShift configuration file.");
}
return getConnection(clientId, null, null, null, null, token, configuration.getLibraServer(), null);
}

}