Support files with yaml extension in S3. Fixes #2146 (#2150)

This commit is contained in:
Ryan Baxter
2022-09-15 09:56:52 -04:00
committed by GitHub
parent 15f26c0040
commit a0b76c1c96
2 changed files with 25 additions and 9 deletions

View File

@@ -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;

View File

@@ -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);