diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java index b3a52831..d23bce78 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java @@ -132,30 +132,37 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere private S3ConfigFile getS3ConfigFile(S3ObjectIdBuilder s3ObjectIdBuilder, String keyPrefix) { try { - final S3Object properties = s3Client - .getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".properties").build())); + final S3Object properties = getObject(s3ObjectIdBuilder, keyPrefix + ".properties"); return new PropertyS3ConfigFile(properties.getObjectMetadata().getVersionId(), properties.getObjectContent()); } catch (Exception eProperties) { try { - final S3Object yaml = s3Client - .getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".yml").build())); + final S3Object yaml = getObject(s3ObjectIdBuilder, keyPrefix + ".yaml"); return new YamlS3ConfigFile(yaml.getObjectMetadata().getVersionId(), yaml.getObjectContent()); } catch (Exception eYaml) { try { - final S3Object json = s3Client - .getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".json").build())); - return new JsonS3ConfigFile(json.getObjectMetadata().getVersionId(), json.getObjectContent()); + final S3Object json = getObject(s3ObjectIdBuilder, keyPrefix + ".yml"); + return new YamlS3ConfigFile(json.getObjectMetadata().getVersionId(), json.getObjectContent()); } - catch (Exception eJson) { - return null; + catch (Exception eYml) { + try { + final S3Object json = getObject(s3ObjectIdBuilder, keyPrefix + ".json"); + return new JsonS3ConfigFile(json.getObjectMetadata().getVersionId(), json.getObjectContent()); + } + catch (Exception eJson) { + return null; + } } } } } + private S3Object getObject(S3ObjectIdBuilder s3ObjectIdBuilder, String key) throws Exception { + return s3Client.getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(key).build())); + } + @Override public Locations getLocations(String application, String profiles, String label) { String baseLocation = AWS_S3_RESOURCE_SCHEME + bucketName + PATH_SEPARATOR + application; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java index d1213a19..505a30a8 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java @@ -113,6 +113,15 @@ public class AwsS3EnvironmentRepositoryTests { @Test public void findYamlObject() throws UnsupportedEncodingException { + setupS3("foo-bar.yaml", yamlContent); + + final Environment env = envRepo.findOne("foo", "bar", null); + + assertExpectedEnvironment(env, "foo", null, null, 1, "bar"); + } + + @Test + public void findYmlObject() throws UnsupportedEncodingException { setupS3("foo-bar.yml", yamlContent); final Environment env = envRepo.findOne("foo", "bar", null);