Search in sources :

Example 1 with IDockerConnectionSettings

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;
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)

Example 2 with IDockerConnectionSettings

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;
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 3 with IDockerConnectionSettings

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();
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with IDockerConnectionSettings

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();
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with IDockerConnectionSettings

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();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Aggregations

IDockerConnectionSettings (org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)7 Properties (java.util.Properties)3 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 DockerConnectionManager (org.eclipse.linuxtools.docker.core.DockerConnectionManager)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 IDockerConnectionSettingsProvider (org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsProvider)1 TCPConnectionSettings (org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)1 UnixSocketConnectionSettings (org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings)1