Fix s3client issue when using s3 endpoint
Client is immutable when created with the builder Fixes gh-1597
This commit is contained in:
@@ -91,13 +91,11 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
|
||||
|
||||
final Properties config = s3ConfigFile.read();
|
||||
config.putAll(serverProperties.getOverrides());
|
||||
StringBuilder propertySourceName = new StringBuilder().append("s3:")
|
||||
.append(app);
|
||||
StringBuilder propertySourceName = new StringBuilder().append("s3:").append(app);
|
||||
if (profile != null) {
|
||||
propertySourceName.append("-").append(profile);
|
||||
}
|
||||
environment
|
||||
.add(new PropertySource(propertySourceName.toString(), config));
|
||||
environment.add(new PropertySource(propertySourceName.toString(), config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,17 @@ public class AwsS3EnvironmentRepositoryFactory
|
||||
public AwsS3EnvironmentRepository build(AwsS3EnvironmentProperties environmentProperties) {
|
||||
final AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
|
||||
if (environmentProperties.getRegion() != null) {
|
||||
clientBuilder.withRegion(environmentProperties.getRegion());
|
||||
if (environmentProperties.getEndpoint() != null) {
|
||||
AmazonS3ClientBuilder.EndpointConfiguration endpointConfiguration = new AmazonS3ClientBuilder.EndpointConfiguration(
|
||||
environmentProperties.getEndpoint(), environmentProperties.getRegion());
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
}
|
||||
else {
|
||||
clientBuilder.withRegion(environmentProperties.getRegion());
|
||||
}
|
||||
}
|
||||
final AmazonS3 client = clientBuilder.build();
|
||||
if (environmentProperties.getEndpoint() != null) {
|
||||
client.setEndpoint(environmentProperties.getEndpoint());
|
||||
}
|
||||
|
||||
AwsS3EnvironmentRepository repository = new AwsS3EnvironmentRepository(client,
|
||||
environmentProperties.getBucket(), server);
|
||||
return repository;
|
||||
|
||||
@@ -339,8 +339,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
|
||||
// Check if git points to valid repository and default label is not empty or
|
||||
// null.
|
||||
if (null != git && git.getRepository() != null
|
||||
&& !StringUtils.isEmpty(getDefaultLabel())) {
|
||||
if (null != git && git.getRepository() != null && !StringUtils.isEmpty(getDefaultLabel())) {
|
||||
// Checkout the default branch set for repo in git. This may not always be
|
||||
// master. It depends on the
|
||||
// admin and organization settings.
|
||||
|
||||
@@ -185,6 +185,16 @@ public class AwsS3EnvironmentRepositoryTests {
|
||||
assertExpectedEnvironment(env, "foo,bar", null, null, 2, "profile1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryCustomizable() {
|
||||
AwsS3EnvironmentRepositoryFactory factory = new AwsS3EnvironmentRepositoryFactory(new ConfigServerProperties());
|
||||
AwsS3EnvironmentProperties properties = new AwsS3EnvironmentProperties();
|
||||
properties.setRegion("us-east-1");
|
||||
properties.setEndpoint("https://myawsendpoint/");
|
||||
AwsS3EnvironmentRepository repository = factory.build(properties);
|
||||
assertThat(repository).isNotNull();
|
||||
}
|
||||
|
||||
private void setupS3(String fileName, String propertyContent) throws UnsupportedEncodingException {
|
||||
setupS3(fileName, null, propertyContent);
|
||||
}
|
||||
|
||||
@@ -1064,8 +1064,7 @@ public class JGitEnvironmentRepositoryTests {
|
||||
* @throws Exception should throw any runtime exception.
|
||||
*/
|
||||
@Test
|
||||
public void afterPropertiesSet_CloneOnStartTrue_DefaultLabelSet_CloneAndCheckoutCalled()
|
||||
throws Exception {
|
||||
public void afterPropertiesSet_CloneOnStartTrue_DefaultLabelSet_CloneAndCheckoutCalled() throws Exception {
|
||||
final String LABEL_TO_CHECKOUT = "release";
|
||||
// Set the default branch of repository as master
|
||||
Repository mockRepository = mock(Repository.class);
|
||||
@@ -1104,8 +1103,8 @@ public class JGitEnvironmentRepositoryTests {
|
||||
when(mockListBranchCommand.call()).thenReturn(repositoryRefsList);
|
||||
when(mockCheckoutCommand.call()).thenReturn(mockReleaseRef);
|
||||
|
||||
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
|
||||
this.environment, new JGitEnvironmentProperties());
|
||||
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
|
||||
new JGitEnvironmentProperties());
|
||||
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
|
||||
envRepository.setUri("http://somegitserver/somegitrepo");
|
||||
envRepository.setCloneOnStart(true);
|
||||
@@ -1165,8 +1164,8 @@ public class JGitEnvironmentRepositoryTests {
|
||||
when(mockListBranchCommand.call()).thenReturn(repositoryRefsList);
|
||||
when(mockCheckoutCommand.call()).thenReturn(mockReleaseRef);
|
||||
|
||||
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
|
||||
this.environment, new JGitEnvironmentProperties());
|
||||
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
|
||||
new JGitEnvironmentProperties());
|
||||
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
|
||||
envRepository.setUri("http://somegitserver/somegitrepo");
|
||||
envRepository.setCloneOnStart(true);
|
||||
|
||||
Reference in New Issue
Block a user