use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method fulfill.
@Override
public void fulfill() {
String server = TestUtils.getValueOrDefault(connectionSpec.server(), DatastoreOS3.SERVER);
String username = TestUtils.getValueOrDefault(connectionSpec.username(), DatastoreOS3.USERNAME);
String password = TestUtils.getValueOrDefault(connectionSpec.password(), DatastoreOS3.PASSWORD);
String token = TestUtils.getValueOrDefault(connectionSpec.token(), DatastoreOS3.TOKEN);
try {
ConnectionURL url;
if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(username)) {
url = getConnectionURL(username, server);
} else {
url = getConnectionURL(server);
}
Connection connection = ConnectionsRegistrySingleton.getInstance().getByUrl(url, Connection.class);
if (connection == null) {
LOGGER.debug(NLS.bind("No connection for {0} found. Creating a new one.", url));
connection = createConnection(server, username, password, token);
ConnectionsRegistrySingleton.getInstance().add(connection);
}
LOGGER.debug(NLS.bind("Connecting to OpenShift 3 server at {0}", url));
connection.connect();
this.connection = connection;
} catch (UnsupportedEncodingException | MalformedURLException e) {
throw new OpenShiftToolsException(NLS.bind("Could not create connection for {0} : {1}", server, e));
}
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method createConnectionWithCredentials.
private Connection createConnectionWithCredentials(String server, String username, String password) {
IClient client = createClient(server);
Connection connection = new Connection(client, null);
connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_BASIC);
connection.setUsername(username);
connection.setPassword(password);
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method createConnectionWithToken.
private Connection createConnectionWithToken(String server, String token) {
IClient client = createClient(server);
Connection connection = new Connection(client, null);
connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_OAUTH);
connection.setUsername(connection.getUsername());
connection.setToken(token);
connection.refresh();
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftProjectRequirement method fulfill.
@Override
public void fulfill() {
String projectName = TestUtils.getValueOrDefault(projectSpec.name(), DatastoreOS3.TEST_PROJECT);
Connection connection = ConnectionUtils.getConnectionOrDefault(projectSpec.connectionURL());
assertNotNull(NLS.bind("No connection {0} exists", projectSpec.connectionURL()), connection);
this.project = OpenShift3NativeProjectUtils.getOrCreateProject(projectName, projectSpec.displayName(), projectSpec.description(), connection);
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftProjectRequirement method cleanUp.
@Override
public void cleanUp() {
if (projectSpec.cleanup()) {
Connection connection = ConnectionUtils.getConnectionOrDefault(projectSpec.connectionURL());
connection.deleteResource(project);
new WaitWhile(new OpenShiftProjectExists(project.getName(), connection));
}
}
Aggregations