use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.
the class DefaultDockerConnectionSettingsFinder method findDefaultConnectionSettings.
@Override
public IDockerConnectionSettings findDefaultConnectionSettings() {
final IDockerConnectionSettings defaultsWithUnixSocket = defaultsWithUnixSocket();
if (defaultsWithUnixSocket != null) {
return defaultsWithUnixSocket;
}
final IDockerConnectionSettings defaultsWithSystemEnv = defaultsWithSystemEnv();
if (defaultsWithSystemEnv != null) {
return defaultsWithSystemEnv;
}
final IDockerConnectionSettings defaultsWithShellEnv = defaultsWithShellEnv();
if (defaultsWithShellEnv != null) {
return defaultsWithShellEnv;
}
return null;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.
the class ConnectionSettingsContentProvider method getElements.
@Override
public Object[] getElements(final Object inputElement) {
if (inputElement instanceof IDockerConnection) {
final IDockerConnection connection = (IDockerConnection) inputElement;
IDockerConnectionSettings data = connection.getSettings();
if (data != null) {
return data.getProperties();
}
}
return EMPTY;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.
the class DefaultDockerConnectionSettingsFinderSWTBotTest method shouldCreateSecuredConnectionSettingsFromProperties.
@Test
public void shouldCreateSecuredConnectionSettingsFromProperties() {
// given
final Properties properties = new Properties();
properties.setProperty(DefaultDockerConnectionSettingsFinder.DOCKER_HOST, "tcp://foo");
properties.setProperty(DefaultDockerConnectionSettingsFinder.DOCKER_CERT_PATH, "/path/to/certs");
// actually, the DOCKER_TLS_VERIFY is not used. If DOCKER_CERT_PATH is set, the we assume that DOCKER_TLS_VERIFY is '1'
// properties.setProperty(DefaultDockerConnectionSettingsFinder.DOCKER_TLS_VERIFY, "1");
// when
final IDockerConnectionSettings connectionSettings = ShellConnectionSettingsProvider.createDockerConnectionSettings(properties);
// then
assertThat(connectionSettings.isSettingsResolved()).isFalse();
assertThat(connectionSettings.getType()).isEqualTo(BindingType.TCP_CONNECTION);
assertThat(((TCPConnectionSettings) connectionSettings).getHost()).isEqualTo("https://foo");
assertThat(((TCPConnectionSettings) connectionSettings).getPathToCertificates()).isEqualTo("/path/to/certs");
Object[] connectionProperties = ((TCPConnectionSettings) connectionSettings).getProperties();
assertThat(connectionProperties.length == 3);
Object[] firstProperty = (Object[]) connectionProperties[0];
assertThat(((String) firstProperty[0]).equals("Type"));
assertThat(((String) firstProperty[1]).equals("TCP_CONNECTION"));
Object[] secondProperty = (Object[]) connectionProperties[1];
assertThat(((String) secondProperty[0]).equals("Host"));
assertThat(((String) secondProperty[1]).equals("https://foo"));
Object[] thirdProperty = (Object[]) connectionProperties[2];
assertThat(((String) thirdProperty[0]).equals("Certificates"));
assertThat(((String) thirdProperty[1]).equals("/path/to/certs"));
assertThat(((TCPConnectionSettings) connectionSettings).isTlsVerify()).isTrue();
}
use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.
the class DefaultDockerConnectionSettingsFinderSWTBotTest method shouldNotCreateConnectionSettingsWhenMissingHost.
@Test
public void shouldNotCreateConnectionSettingsWhenMissingHost() {
// given
final Properties properties = new Properties();
properties.setProperty(DefaultDockerConnectionSettingsFinder.DOCKER_CERT_PATH, "/path/to/certs");
// actually, the DOCKER_TLS_VERIFY is not used. If DOCKER_CERT_PATH is set, the we assume that DOCKER_TLS_VERIFY is '1'
// properties.setProperty(DefaultDockerConnectionSettingsFinder.DOCKER_TLS_VERIFY, "1");
// when
final IDockerConnectionSettings connectionSettings = ShellConnectionSettingsProvider.createDockerConnectionSettings(properties);
// then
assertThat(connectionSettings).isNull();
}
use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.
the class ShellConnectionSettingsProvider method getConnectionSettings.
@Override
public List<IDockerConnectionSettings> getConnectionSettings() {
try {
final String connectionSettingsDetectionScriptName = getConnectionSettingsDetectionScriptName();
if (connectionSettingsDetectionScriptName == null) {
Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.Docker_No_Settings_Description_Script));
return Collections.emptyList();
}
final File connectionSettingsDetectionScript = getConnectionSettingsDetectionScript(connectionSettingsDetectionScriptName);
final String[] cmdArray = getConnectionSettingsDetectionCommandArray(connectionSettingsDetectionScript);
final Process process = Runtime.getRuntime().exec(cmdArray);
process.waitFor();
final int exitValue = process.exitValue();
if (exitValue == 0) {
final InputStream processInputStream = process.getInputStream();
// read content from process input stream
final Properties dockerSettings = new Properties();
dockerSettings.load(processInputStream);
IDockerConnectionSettings setting = createDockerConnectionSettings(dockerSettings);
if (setting == null) {
return Collections.emptyList();
}
return Arrays.asList(setting);
} else {
// an exit value of 1 should indicate no connection found
if (exitValue != 1) {
final InputStream processErrorStream = process.getErrorStream();
final String errorMessage = streamToString(processErrorStream);
Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage));
}
}
} catch (IOException | IllegalArgumentException | InterruptedException e) {
Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.Retrieve_Default_Settings_Failure, e));
}
return Collections.emptyList();
}
Aggregations