diff --git a/src/main/java/org/ga4gh/drs/AppConfig.java b/src/main/java/org/ga4gh/drs/AppConfig.java index 0f15e1f..b8dda19 100644 --- a/src/main/java/org/ga4gh/drs/AppConfig.java +++ b/src/main/java/org/ga4gh/drs/AppConfig.java @@ -10,8 +10,10 @@ import org.ga4gh.drs.configuration.DataSourceRegistry; import org.ga4gh.drs.configuration.DrsConfig; import org.ga4gh.drs.configuration.DrsConfigContainer; +import org.ga4gh.drs.configuration.S3; import org.ga4gh.drs.configuration.ServerProps; import org.ga4gh.drs.constant.DataSourceDefaults; +import org.ga4gh.drs.constant.S3Defaults; import org.ga4gh.drs.constant.ServerPropsDefaults; import org.ga4gh.drs.constant.ServiceInfoDefaults; import org.ga4gh.drs.model.ServiceInfo; @@ -31,6 +33,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import software.amazon.awssdk.regions.Region; import java.io.File; import java.io.FileNotFoundException; @@ -85,6 +88,10 @@ public DrsConfigContainer defaultDrsConfigContainer( DataSourceRegistry dataSourceRegistry = drsConfigContainer.getDrsConfig().getDataSourceRegistry(); dataSourceRegistry.setDataSources(DataSourceDefaults.REGISTRY); + + S3 s3 = drsConfigContainer.getDrsConfig().getS3(); + s3.setRegion(S3Defaults.S3_REGION); + return drsConfigContainer; } @@ -183,4 +190,11 @@ public DataSourceLookup dataSourceLookup() { public DrsObjectLoaderFactory drsObjectLoaderFactory() { return new DrsObjectLoaderFactory(); } + + @Bean + public Region defaultRegion( + @Qualifier(AppConfigConstants.MERGED_DRS_CONFIG_CONTAINER) DrsConfigContainer drsConfigContainer + ) { + return Region.of(drsConfigContainer.getDrsConfig().getS3().getRegion()); + } } diff --git a/src/main/java/org/ga4gh/drs/configuration/DrsConfig.java b/src/main/java/org/ga4gh/drs/configuration/DrsConfig.java index 113a969..43c4bf7 100644 --- a/src/main/java/org/ga4gh/drs/configuration/DrsConfig.java +++ b/src/main/java/org/ga4gh/drs/configuration/DrsConfig.java @@ -1,5 +1,6 @@ package org.ga4gh.drs.configuration; +import com.fasterxml.jackson.annotation.JsonProperty; import org.ga4gh.drs.model.ServiceInfo; public class DrsConfig { @@ -8,10 +9,14 @@ public class DrsConfig { private ServiceInfo serviceInfo; private DataSourceRegistry dataSourceRegistry; + @JsonProperty("S3") + private S3 s3; + public DrsConfig() { serverProps = new ServerProps(); serviceInfo = new ServiceInfo(); dataSourceRegistry = new DataSourceRegistry(); + s3 = new S3(); } public void setServerProps(ServerProps serverProps) { @@ -37,4 +42,12 @@ public void setDataSourceRegistry(DataSourceRegistry dataSourceRegistry) { public DataSourceRegistry getDataSourceRegistry() { return dataSourceRegistry; } + + public S3 getS3() { + return s3; + } + + public void setS3(S3 S3) { + this.s3 = S3; + } } diff --git a/src/main/java/org/ga4gh/drs/configuration/S3.java b/src/main/java/org/ga4gh/drs/configuration/S3.java new file mode 100644 index 0000000..bffc7bf --- /dev/null +++ b/src/main/java/org/ga4gh/drs/configuration/S3.java @@ -0,0 +1,17 @@ +package org.ga4gh.drs.configuration; + +public class S3 { + private String region; + + public S3() { + + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } +} diff --git a/src/main/java/org/ga4gh/drs/constant/S3Defaults.java b/src/main/java/org/ga4gh/drs/constant/S3Defaults.java new file mode 100644 index 0000000..04b6fa0 --- /dev/null +++ b/src/main/java/org/ga4gh/drs/constant/S3Defaults.java @@ -0,0 +1,6 @@ +package org.ga4gh.drs.constant; + +public class S3Defaults { + + public static final String S3_REGION = "us-east-1"; +} diff --git a/src/main/java/org/ga4gh/drs/utils/S3ClientRegionBasedProvider.java b/src/main/java/org/ga4gh/drs/utils/S3ClientRegionBasedProvider.java index 05c87c6..3d7aa1d 100644 --- a/src/main/java/org/ga4gh/drs/utils/S3ClientRegionBasedProvider.java +++ b/src/main/java/org/ga4gh/drs/utils/S3ClientRegionBasedProvider.java @@ -1,5 +1,6 @@ package org.ga4gh.drs.utils; +import org.springframework.beans.factory.annotation.Autowired; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.HeadBucketRequest; @@ -10,12 +11,15 @@ public class S3ClientRegionBasedProvider { + @Autowired + private static Region DEFAULT_REGION; + public S3ClientRegionBasedProvider() { } private static S3Client mainClient = S3Client.builder() - .region(Region.US_EAST_1) + .region(DEFAULT_REGION) .build(); private static Map clients = new HashMap<>(); @@ -47,6 +51,6 @@ private static Region getRegion(String bucket) { } } // Default US_EAST_1 - return Region.US_EAST_1; + return DEFAULT_REGION; } } diff --git a/src/main/java/org/ga4gh/drs/utils/objectloader/S3DrsObjectLoader.java b/src/main/java/org/ga4gh/drs/utils/objectloader/S3DrsObjectLoader.java index eb09ab8..5a48094 100644 --- a/src/main/java/org/ga4gh/drs/utils/objectloader/S3DrsObjectLoader.java +++ b/src/main/java/org/ga4gh/drs/utils/objectloader/S3DrsObjectLoader.java @@ -52,7 +52,7 @@ public S3DrsObjectLoader(String objectId, String objectPath) { URI uri = URI.create(objectPath); bucket = uri.getHost(); // Strip leading / - key = uri.getPath().substring(1); + key = uri.getPath().replaceAll("^/+$", ""); // Get client based on region client = S3ClientRegionBasedProvider.getClient(bucket); diff --git a/src/test/resources/config/test-config-00.yml b/src/test/resources/config/test-config-00.yml index 5124c7a..2f1427a 100644 --- a/src/test/resources/config/test-config-00.yml +++ b/src/test/resources/config/test-config-00.yml @@ -9,4 +9,6 @@ drsConfig: dataSources: - drsIdPattern: ^testdata\.(?.+?)\.(?.+?)\.(?.+?)$ objectPathTemplate: ./src/test/resources/data/{acc1}/{acc2}/{acc3} - protocol: FILE \ No newline at end of file + protocol: FILE + S3: + region: us-east-1 \ No newline at end of file