Search in sources :

Example 1 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepositoryTests method gitCredentialsProviderFactoryCreatesAwsCodeCommitProvider.

@Test
public void gitCredentialsProviderFactoryCreatesAwsCodeCommitProvider() throws Exception {
    GitCredentialsProviderFactory credentialsFactory = new GitCredentialsProviderFactory();
    Git mockGit = mock(Git.class);
    MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
    final String awsUri = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test";
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties());
    envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
    envRepository.setUri(awsUri);
    envRepository.setGitCredentialsProvider(credentialsFactory.createFor(envRepository.getUri(), null, null, null));
    envRepository.setCloneOnStart(true);
    envRepository.afterPropertiesSet();
    assertTrue(mockCloneCommand.getCredentialsProvider() instanceof AwsCodeCommitCredentialProvider);
}
Also used : Git(org.eclipse.jgit.api.Git) GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory) AwsCodeCommitCredentialProvider(org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class AwsCodeCommitCredentialsProviderTests method init.

@Before
public void init() {
    GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory();
    provider = (AwsCodeCommitCredentialProvider) factory.createFor(AWS_REPO, USER, PASSWORD, null);
}
Also used : GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory) Before(org.junit.Before)

Example 3 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class AwsCodeCommitCredentialsProviderTests method testUriWithCurlyBracesReturnsTrue.

@Test
public void testUriWithCurlyBracesReturnsTrue() throws UnsupportedCredentialItem, URISyntaxException {
    GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory();
    provider = (AwsCodeCommitCredentialProvider) factory.createFor(CURLY_BRACES_REPO, USER, PASSWORD, null);
    CredentialItem[] credentialItems = makeCredentialItems();
    assertTrue(provider.get(new URIish(CURLY_BRACES_REPO), credentialItems));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) Test(org.junit.Test)

Example 4 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class MultipleJGitEnvironmentRepository method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    GitCredentialsProviderFactory credentialFactory = new GitCredentialsProviderFactory();
    super.setGitCredentialsProvider(credentialFactory.createFor(getUri(), getUsername(), getPassword(), getPassphrase()));
    super.afterPropertiesSet();
    for (String name : this.repos.keySet()) {
        PatternMatchingJGitEnvironmentRepository repo = this.repos.get(name);
        repo.setEnvironment(getEnvironment());
        if (!StringUtils.hasText(repo.getName())) {
            repo.setName(name);
        }
        if (repo.getPattern() == null || repo.getPattern().length == 0) {
            repo.setPattern(new String[] { name });
        }
        if (repo.getTransportConfigCallback() == null) {
            repo.setTransportConfigCallback(getTransportConfigCallback());
        }
        if (getTimeout() != 0 && repo.getTimeout() == 0) {
            repo.setTimeout(getTimeout());
        }
        String user = repo.getUsername();
        String pass = repo.getPassword();
        String passphrase = repo.getPassphrase();
        if (user == null) {
            user = getUsername();
            pass = getPassword();
        }
        if (passphrase == null) {
            passphrase = getPassphrase();
        }
        repo.setGitCredentialsProvider(credentialFactory.createFor(repo.getUri(), user, pass, passphrase));
        repo.afterPropertiesSet();
    }
    if (!getBasedir().exists() && !getBasedir().mkdirs()) {
        throw new IllegalStateException("Basedir does not exist and can not be created: " + getBasedir());
    }
    if (!getBasedir().getParentFile().canWrite()) {
        throw new IllegalStateException("Cannot write parent of basedir (please configure a writable location): " + getBasedir());
    }
}
Also used : GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory)

Example 5 with GitCredentialsProviderFactory

use of org.springframework.cloud.config.server.support.GitCredentialsProviderFactory in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepositoryTests method gitCredentialsProviderFactoryCreatesPassphraseProvider.

@Test
public void gitCredentialsProviderFactoryCreatesPassphraseProvider() throws Exception {
    final String passphrase = "mypassphrase";
    final String gitUri = "git+ssh://git@somegitserver/somegitrepo";
    GitCredentialsProviderFactory credentialsFactory = new GitCredentialsProviderFactory();
    Git mockGit = mock(Git.class);
    MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties());
    envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
    envRepository.setUri(gitUri);
    envRepository.setBasedir(new File("./mybasedir"));
    envRepository.setGitCredentialsProvider(credentialsFactory.createFor(gitUri, null, null, passphrase));
    envRepository.setCloneOnStart(true);
    envRepository.afterPropertiesSet();
    assertTrue(mockCloneCommand.hasPassphraseCredentialsProvider());
    CredentialsProvider provider = mockCloneCommand.getCredentialsProvider();
    assertFalse(provider.isInteractive());
    CredentialItem.StringType stringCredential = new CredentialItem.StringType(PassphraseCredentialsProvider.PROMPT, true);
    assertTrue(provider.supports(stringCredential));
    provider.get(new URIish(), stringCredential);
    assertEquals(stringCredential.getValue(), passphrase);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) CredentialItem(org.eclipse.jgit.transport.CredentialItem) Matchers.anyString(org.mockito.Matchers.anyString) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) PassphraseCredentialsProvider(org.springframework.cloud.config.server.support.PassphraseCredentialsProvider) Git(org.eclipse.jgit.api.Git) GitCredentialsProviderFactory(org.springframework.cloud.config.server.support.GitCredentialsProviderFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

GitCredentialsProviderFactory (org.springframework.cloud.config.server.support.GitCredentialsProviderFactory)6 Test (org.junit.Test)4 Git (org.eclipse.jgit.api.Git)3 CredentialItem (org.eclipse.jgit.transport.CredentialItem)3 URIish (org.eclipse.jgit.transport.URIish)3 Matchers.anyString (org.mockito.Matchers.anyString)3 File (java.io.File)2 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)2 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)2 PassphraseCredentialsProvider (org.springframework.cloud.config.server.support.PassphraseCredentialsProvider)2 UnsupportedCredentialItem (org.eclipse.jgit.errors.UnsupportedCredentialItem)1 Before (org.junit.Before)1 AwsCodeCommitCredentialProvider (org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider)1