Search in sources :

Example 6 with TransportConfigCallback

use of org.eclipse.jgit.api.TransportConfigCallback in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepositoryTests method shouldSetTransportConfigCallbackOnCloneAndFetch.

@Test
public void shouldSetTransportConfigCallbackOnCloneAndFetch() throws Exception {
    Git mockGit = mock(Git.class);
    FetchCommand fetchCommand = mock(FetchCommand.class);
    when(mockGit.fetch()).thenReturn(fetchCommand);
    when(fetchCommand.call()).thenReturn(mock(FetchResult.class));
    CloneCommand mockCloneCommand = mock(CloneCommand.class);
    when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
    when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
    TransportConfigCallback configCallback = mock(TransportConfigCallback.class);
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties());
    envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
    envRepository.setUri("http://somegitserver/somegitrepo");
    envRepository.setTransportConfigCallback(configCallback);
    envRepository.setCloneOnStart(true);
    envRepository.afterPropertiesSet();
    verify(mockCloneCommand, times(1)).setTransportConfigCallback(configCallback);
    envRepository.fetch(mockGit, "master");
    verify(fetchCommand, times(1)).setTransportConfigCallback(configCallback);
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) Git(org.eclipse.jgit.api.Git) FetchResult(org.eclipse.jgit.transport.FetchResult) FetchCommand(org.eclipse.jgit.api.FetchCommand) TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) File(java.io.File) Test(org.junit.Test)

Example 7 with TransportConfigCallback

use of org.eclipse.jgit.api.TransportConfigCallback in project spring-cloud-config by spring-cloud.

the class TransportConfigurationTest method fileBasedSshTransportCallbackCreated.

@Test
public void fileBasedSshTransportCallbackCreated() throws Exception {
    SshUriProperties dontIgnoreLocalSettings = SshUri.builder().uri("user@gitrepo.com:proj/repo").ignoreLocalSshSettings(false).build();
    TransportConfiguration transportConfiguration = new TransportConfiguration();
    TransportConfigCallback transportConfigCallback = transportConfiguration.propertiesBasedSshTransportCallback(dontIgnoreLocalSettings);
    assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.FileBasedSshTransportConfigCallback.class)));
}
Also used : TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) SshUriProperties(org.springframework.cloud.config.server.ssh.SshUriProperties) Test(org.junit.Test)

Example 8 with TransportConfigCallback

use of org.eclipse.jgit.api.TransportConfigCallback in project spring-cloud-config by spring-cloud.

the class TransportConfigurationTest method propertiesBasedSshTransportCallbackCreated.

@Test
public void propertiesBasedSshTransportCallbackCreated() throws Exception {
    SshUriProperties ignoreLocalSettings = SshUri.builder().uri("user@gitrepo.com:proj/repo").ignoreLocalSshSettings(true).build();
    TransportConfiguration transportConfiguration = new TransportConfiguration();
    TransportConfigCallback transportConfigCallback = transportConfiguration.propertiesBasedSshTransportCallback(ignoreLocalSettings);
    assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.PropertiesBasedSshTransportConfigCallback.class)));
}
Also used : TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) SshUriProperties(org.springframework.cloud.config.server.ssh.SshUriProperties) Test(org.junit.Test)

Example 9 with TransportConfigCallback

use of org.eclipse.jgit.api.TransportConfigCallback in project fabric8 by fabric8io.

the class GitUtils method configureCommand.

/**
 * Configures the transport of the command to deal with things like SSH
 */
public static <C extends GitCommand> void configureCommand(TransportCommand<C, ?> command, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey) {
    LOG.info("Using " + credentialsProvider);
    if (sshPrivateKey != null) {
        final CredentialsProvider provider = credentialsProvider;
        command.setTransportConfigCallback(new TransportConfigCallback() {

            @Override
            public void configure(Transport transport) {
                if (transport instanceof SshTransport) {
                    SshTransport sshTransport = (SshTransport) transport;
                    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {

                        @Override
                        protected void configure(OpenSshConfig.Host host, Session session) {
                            session.setConfig("StrictHostKeyChecking", "no");
                            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
                            session.setUserInfo(userInfo);
                        }

                        @Override
                        protected JSch createDefaultJSch(FS fs) throws JSchException {
                            JSch jsch = super.createDefaultJSch(fs);
                            jsch.removeAllIdentity();
                            String absolutePath = sshPrivateKey.getAbsolutePath();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Adding identity privateKey: " + sshPrivateKey + " publicKey: " + sshPublicKey);
                            }
                            if (sshPublicKey != null) {
                                jsch.addIdentity(absolutePath, sshPublicKey.getAbsolutePath(), null);
                            } else {
                                jsch.addIdentity(absolutePath);
                            }
                            return jsch;
                        }
                    };
                    sshTransport.setSshSessionFactory(sshSessionFactory);
                }
            }
        });
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) UserInfo(com.jcraft.jsch.UserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) SshSessionFactory(org.eclipse.jgit.transport.SshSessionFactory) JSch(com.jcraft.jsch.JSch) FS(org.eclipse.jgit.util.FS) OpenSshConfig(org.eclipse.jgit.transport.OpenSshConfig) TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) JschConfigSessionFactory(org.eclipse.jgit.transport.JschConfigSessionFactory) SshTransport(org.eclipse.jgit.transport.SshTransport) Transport(org.eclipse.jgit.transport.Transport) SshTransport(org.eclipse.jgit.transport.SshTransport) Session(com.jcraft.jsch.Session) SSLSession(javax.net.ssl.SSLSession)

Aggregations

TransportConfigCallback (org.eclipse.jgit.api.TransportConfigCallback)9 Test (org.junit.Test)4 JSch (com.jcraft.jsch.JSch)3 SshTransport (org.eclipse.jgit.transport.SshTransport)3 FS (org.eclipse.jgit.util.FS)3 Session (com.jcraft.jsch.Session)2 UserInfo (com.jcraft.jsch.UserInfo)2 File (java.io.File)2 CloneCommand (org.eclipse.jgit.api.CloneCommand)2 JschConfigSessionFactory (org.eclipse.jgit.transport.JschConfigSessionFactory)2 SshSessionFactory (org.eclipse.jgit.transport.SshSessionFactory)2 Transport (org.eclipse.jgit.transport.Transport)2 SshUriProperties (org.springframework.cloud.config.server.ssh.SshUriProperties)2 Test (org.testng.annotations.Test)2 JSchException (com.jcraft.jsch.JSchException)1 KeyPair (com.jcraft.jsch.KeyPair)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 SSLSession (javax.net.ssl.SSLSession)1 FetchCommand (org.eclipse.jgit.api.FetchCommand)1