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);
}
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);
}
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));
}
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());
}
}
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);
}
Aggregations