Example usage for org.eclipse.jgit.transport OpenSshConfig get

List of usage examples for org.eclipse.jgit.transport OpenSshConfig get

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport OpenSshConfig get.

Prototype

public static OpenSshConfig get(FS fs) 

Source Link

Document

Obtain the user's configuration data.

Usage

From source file:org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftSshSessionFactory.java

License:Open Source License

public Session createSession(final IApplication application) throws OpenShiftSSHOperationException {
    final URIish uri = getSshUri(application);
    final Session session = cache.get(uri);
    if (session == null || !session.isConnected()) {
        final FS fs = FS.DETECTED;
        if (config == null) {
            config = OpenSshConfig.get(fs);
        }//from   w  ww .  j  a  v a 2s  .com
        String user = uri.getUser();
        String host = uri.getHost();
        int port = uri.getPort();
        JSch.setLogger(new JschToEclipseLogger());
        final OpenSshConfig.Host hc = config.lookup(host);
        try {
            cache.put(uri, createSession(hc, user, host, port, fs));
        } catch (JSchException e) {
            throw new OpenShiftSSHOperationException(e, "Unable to create SSH session for application ''{0}''",
                    application);
        }
    }
    return cache.get(uri);
}

From source file:org.jboss.tools.openshift.express.internal.ui.utils.SSHSessionRepository.java

License:Open Source License

public Session getSession(final IApplication application) throws OpenShiftSSHOperationException {
    try {//from  ww w .  j  a  v a  2s  .  com
        final URIish uri = getSshUri(application);
        final Session session = cache.get(uri);
        if (session == null || !session.isConnected()) {
            final FS fs = FS.DETECTED;
            if (config == null) {
                config = OpenSshConfig.get(fs);
            }
            String user = uri.getUser();
            String host = uri.getHost();
            int port = uri.getPort();
            JSch.setLogger(new JschToEclipseLogger());
            final OpenSshConfig.Host hc = config.lookup(host);
            try {
                cache.put(uri, createSession(hc, user, host, port, fs));
            } catch (JSchException e) {
                throw new OpenShiftSSHOperationException(e,
                        "Could not create SSH session for application ''{0}''", application.getName());
            }
        }
        return cache.get(uri);
    } catch (URISyntaxException e1) {
        throw new OpenShiftSSHOperationException(e1, "Could not create SSH Session for application ''{0}''",
                application.getName());
    }
}

From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java

License:Apache License

@Test
public void strictHostKeyCheckShouldCheck() throws Exception {
    String uri = "git+ssh://git@somegitserver/somegitrepo";
    SshSessionFactory.setInstance(null);
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
    envRepository.setUri(uri);//from   ww w  . ja v a 2  s  . co m
    envRepository.setBasedir(new File("./mybasedir"));
    assertTrue(envRepository.isStrictHostKeyChecking());
    envRepository.setCloneOnStart(true);
    try {
        // this will throw but we don't care about connecting.
        envRepository.afterPropertiesSet();
    } catch (Exception e) {
        final OpenSshConfig.Host hc = OpenSshConfig.get(FS.detect()).lookup("github.com");
        JschConfigSessionFactory factory = (JschConfigSessionFactory) SshSessionFactory.getInstance();
        // There's no public method that can be used to inspect the ssh configuration, so we'll reflect
        // the configure method to allow us to check that the config property is set as expected.
        Method configure = factory.getClass().getDeclaredMethod("configure", OpenSshConfig.Host.class,
                Session.class);
        configure.setAccessible(true);
        Session session = mock(Session.class);
        ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class);
        ArgumentCaptor<String> valueCaptor = ArgumentCaptor.forClass(String.class);
        configure.invoke(factory, hc, session);
        verify(session).setConfig(keyCaptor.capture(), valueCaptor.capture());
        configure.setAccessible(false);
        assertTrue("yes".equals(valueCaptor.getValue()));
    }
}