Search in sources :

Example 6 with IDockerConnectionSettings

use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.

the class DefaultDockerConnectionSettingsFinder method getKnownConnectionSettings.

@Override
public List<IDockerConnectionSettings> getKnownConnectionSettings() {
    List<IDockerConnectionSettings> result = new ArrayList<>();
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        try {
            // $NON-NLS-1$
            Object obj = config.createExecutableExtension("provider");
            if (obj instanceof IDockerConnectionSettingsProvider) {
                List<IDockerConnectionSettings> settings = ((IDockerConnectionSettingsProvider) obj).getConnectionSettings();
                if (settings != null && !settings.isEmpty()) {
                    result.addAll(settings);
                }
            }
        } catch (CoreException e) {
        // continue, perhaps another configuration will succeed
        }
    }
    return result;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) ArrayList(java.util.ArrayList) IDockerConnectionSettingsProvider(org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsProvider) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 7 with IDockerConnectionSettings

use of org.eclipse.linuxtools.docker.core.IDockerConnectionSettings in project linuxtools by eclipse.

the class NewDockerConnectionPage method retrieveDefaultConnectionSettings.

/**
 * Sets the default settings by looking for the:
 * <ul>
 * <li>a Unix socket at /var/run/docker.sock</li>
 * <li>the following environment variables:
 * <ul>
 * <li>DOCKER_HOST</li>
 * <li>DOCKER_CERT_PATH</li>
 * <li>DOCKER_TLS_VERIFY</li>
 * </ul>
 * </li>
 * </ul>
 * and sets the default connection settings accordingly.
 */
private void retrieveDefaultConnectionSettings() {
    // progressbar
    try {
        getWizard().getContainer().run(true, true, monitor -> {
            monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.retrieveTask"), 1);
            final DockerConnectionManager dockerConnectionManager = DockerConnectionManager.getInstance();
            final IDockerConnectionSettings defaultConnectionSettings = dockerConnectionManager.findDefaultConnectionSettings();
            if (defaultConnectionSettings != null) {
                model.setCustomSettings(!defaultConnectionSettings.isSettingsResolved());
                model.setConnectionName(dockerConnectionManager.resolveConnectionName(defaultConnectionSettings));
                switch(defaultConnectionSettings.getType()) {
                    case TCP_CONNECTION:
                        final TCPConnectionSettings tcpConnectionSettings = (TCPConnectionSettings) defaultConnectionSettings;
                        model.setTcpConnectionBindingMode(true);
                        model.setTcpCertPath(tcpConnectionSettings.getPathToCertificates());
                        model.setTcpTLSVerify(tcpConnectionSettings.isTlsVerify());
                        model.setTcpHost(tcpConnectionSettings.getHost());
                        break;
                    case UNIX_SOCKET_CONNECTION:
                        model.setUnixSocketBindingMode(true);
                        final UnixSocketConnectionSettings unixSocketConnectionSettings = (UnixSocketConnectionSettings) defaultConnectionSettings;
                        model.setUnixSocketPath(unixSocketConnectionSettings.getPath());
                        break;
                }
            } else {
                // fall-back to custom settings, suggesting a
                // Unix Socket connection to the user.
                model.setCustomSettings(true);
                model.setUnixSocketBindingMode(true);
            }
            monitor.done();
        });
    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) InvocationTargetException(java.lang.reflect.InvocationTargetException) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager)

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