diff --git a/provider/legal-aws/pom.xml b/provider/legal-aws/pom.xml index cf1bbc782c6a2fff349dbbef3f44023464444d58..35f0029dc9114d5cc7d9e29542df46fc4981f484 100644 --- a/provider/legal-aws/pom.xml +++ b/provider/legal-aws/pom.xml @@ -27,7 +27,7 @@ <packaging>jar</packaging> <properties> - <aws.version>1.11.651</aws.version> + <aws.version>1.11.1018</aws.version> <deployment.environment>dev</deployment.environment> <version.number>0.9.0-SNAPSHOT</version.number> </properties> @@ -173,7 +173,7 @@ </property> </activation> <properties> - <aws.version>1.11.651</aws.version> + <aws.version>1.11.1018</aws.version> </properties> </profile> <profile> @@ -185,7 +185,7 @@ </property> </activation> <properties> - <aws.version>1.11.632</aws.version> + <aws.version>1.11.1018</aws.version> </properties> </profile> <profile> @@ -197,7 +197,7 @@ </property> </activation> <properties> - <aws.version>1.11.632</aws.version> + <aws.version>1.11.1018</aws.version> </properties> </profile> </profiles> diff --git a/provider/legal-aws/src/main/java/org/opengroup/osdu/legal/aws/countries/StorageReaderImpl.java b/provider/legal-aws/src/main/java/org/opengroup/osdu/legal/aws/countries/StorageReaderImpl.java index d4d54be607812b8c1a23b85caf6c75dc217e3422..12acb716b7a822187d1b49350a95c274a90cd498 100644 --- a/provider/legal-aws/src/main/java/org/opengroup/osdu/legal/aws/countries/StorageReaderImpl.java +++ b/provider/legal-aws/src/main/java/org/opengroup/osdu/legal/aws/countries/StorageReaderImpl.java @@ -17,12 +17,11 @@ package org.opengroup.osdu.legal.aws.countries; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.AmazonS3Exception; import org.opengroup.osdu.core.aws.s3.IS3ClientFactory; -import org.opengroup.osdu.core.aws.s3.S3ClientFactory; import org.opengroup.osdu.core.aws.s3.S3ClientWithBucket; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.legal.provider.interfaces.IStorageReader; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -51,18 +50,36 @@ public class StorageReaderImpl implements IStorageReader { public String getConfigFile(){ S3ClientWithBucket s3ClientWithBucket = s3ClientFactory.getS3ClientForPartition( - dpsHeaders.getPartitionId(), s3ConfigBucketParameterRelativePath); + dpsHeaders.getPartitionIdWithFallbackToAccountId(), s3ConfigBucketParameterRelativePath); AmazonS3 s3 = s3ClientWithBucket.getS3Client(); String legalConfigBucketName = s3ClientWithBucket.getBucketName(); String contents = ""; try { - contents = s3.getObjectAsString(legalConfigBucketName, legalConfigFileName); - } catch (AmazonServiceException e) { + contents = s3.getObjectAsString(legalConfigBucketName, String.format("%s/%s", dpsHeaders.getPartitionId(), legalConfigFileName)); + } catch (AmazonS3Exception e){ + if(e.getStatusCode() == 404){ + contents = createDefaultConfigFile(s3, legalConfigBucketName); + } else { + throw new AppException(500, "Amazon service exception getting config file", e.getMessage()); + } + } + catch (AmazonServiceException e) { throw new AppException(500, "Amazon service exception getting config file", e.getMessage()); } catch (SdkClientException e) { throw new AppException(500, "Amazon Sdk client exception getting config file", e.getMessage()); } return contents; } + + private String createDefaultConfigFile(AmazonS3 s3, String legalConfigBucketName){ + String contents = "[]"; + try { + s3.putObject(legalConfigBucketName, String.format("%s/%s", + dpsHeaders.getPartitionId(), legalConfigFileName), contents); + } catch (Exception e){ + throw new AppException(500, "Exception creating default config file", e.getMessage()); + } + return contents; + } } diff --git a/testing/legal-test-aws/pom.xml b/testing/legal-test-aws/pom.xml index 1b252c7a7d8103ce890280127ff6a4473305b650..fa9fd399153677912b0b8b5fce5578937d31909e 100644 --- a/testing/legal-test-aws/pom.xml +++ b/testing/legal-test-aws/pom.xml @@ -52,18 +52,18 @@ <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk</artifactId> - <version>1.11.651</version> + <version>1.11.1018</version> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> - <version>1.11.651</version> + <version>1.11.1018</version> <type>pom</type> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-dynamodb</artifactId> - <version>1.11.651</version> + <version>1.11.1018</version> </dependency> <!-- third party Apache 2.0 license packages --> diff --git a/testing/legal-test-aws/src/test/java/org/opengroup/osdu/legal/util/AwsLegalTagUtils.java b/testing/legal-test-aws/src/test/java/org/opengroup/osdu/legal/util/AwsLegalTagUtils.java index 9f84b54a99b104158d247c400f0ca0262e4e0294..2ed3b8f6060fbbeed48c8c165a52294e25dd2e65 100644 --- a/testing/legal-test-aws/src/test/java/org/opengroup/osdu/legal/util/AwsLegalTagUtils.java +++ b/testing/legal-test-aws/src/test/java/org/opengroup/osdu/legal/util/AwsLegalTagUtils.java @@ -46,12 +46,13 @@ public class AwsLegalTagUtils extends LegalTagUtils { public synchronized void uploadTenantTestingConfigFile() { String amazonS3Endpoint = System.getProperty("AWS_S3_ENDPOINT", System.getenv("AWS_S3_ENDPOINT")); String amazonS3Region = System.getProperty("AWS_S3_REGION", System.getenv("AWS_S3_REGION")); + String dataPartitionId = System.getProperty("MY_TENANT", System.getenv("MY_TENANT")); S3Config s3Config = new S3Config(amazonS3Endpoint, amazonS3Region); AmazonS3 s3Client = s3Config.amazonS3(); try { - s3Client.putObject(BUCKET_NAME_AWS, FILE_NAME, readTestFile("TenantConfigTestingPurpose.json")); + s3Client.putObject(BUCKET_NAME_AWS, String.format("%s/%s", dataPartitionId, FILE_NAME), readTestFile("TenantConfigTestingPurpose.json")); } catch(IOException e){ throw new RuntimeException(e.getMessage(), e); }