From 987c17d9409529423b1ff8a51017d76c1ef55623 Mon Sep 17 00:00:00 2001 From: Anna Smirnova <132938234+smirnovaae@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:00:13 -0800 Subject: [PATCH] Ab2d/sonarqube fix (#116) --- .../AttributionDataShareConstants.java | 2 +- .../AttributionParameterStore.java | 5 ++--- lambda-lib/build.gradle | 1 + .../gov/cms/ab2d/lambdalibs/lib/SsmClientUtil.java | 13 +++++++++++++ .../cms/ab2d/testutils/AB2DLocalstackContainer.java | 5 +---- .../gov/cms/ab2d/optout/OptOutParameterStore.java | 5 ++--- 6 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 lambda-lib/src/main/java/gov/cms/ab2d/lambdalibs/lib/SsmClientUtil.java diff --git a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionDataShareConstants.java b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionDataShareConstants.java index 39a833f..1d5d46e 100644 --- a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionDataShareConstants.java +++ b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionDataShareConstants.java @@ -2,7 +2,7 @@ import software.amazon.awssdk.regions.Region; -public class AttributionDataShareConstants { +public final class AttributionDataShareConstants { public static final String ROLE_PARAM = "/ab2d/opt-out/bfd-bucket-role-arn"; public static final String DB_HOST_PARAM = "/ab2d/opt-out/db-host"; diff --git a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionParameterStore.java b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionParameterStore.java index 3fcf6b1..74b5592 100644 --- a/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionParameterStore.java +++ b/attribution-data-file-share/src/main/java/gov/cms/ab2d/attributiondatashare/AttributionParameterStore.java @@ -1,5 +1,6 @@ package gov.cms.ab2d.attributiondatashare; +import gov.cms.ab2d.lambdalibs.lib.SsmClientUtil; import software.amazon.awssdk.services.ssm.SsmClient; import software.amazon.awssdk.services.ssm.model.GetParameterRequest; @@ -20,9 +21,7 @@ public AttributionParameterStore(String role, String dbHost, String dbUser, Stri } public static AttributionParameterStore getParameterStore() { - var ssmClient = SsmClient.builder() - .region(S3_REGION) - .build(); + var ssmClient = SsmClientUtil.getClient(); var role = getValueFromParameterStore(ROLE_PARAM, ssmClient); var dbHost = getValueFromParameterStore(DB_HOST_PARAM, ssmClient); diff --git a/lambda-lib/build.gradle b/lambda-lib/build.gradle index 574357a..c59f20d 100644 --- a/lambda-lib/build.gradle +++ b/lambda-lib/build.gradle @@ -18,6 +18,7 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' testImplementation 'org.junit.platform:junit-platform-commons:1.9.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' + implementation 'software.amazon.awssdk:ssm:2.25.7' } diff --git a/lambda-lib/src/main/java/gov/cms/ab2d/lambdalibs/lib/SsmClientUtil.java b/lambda-lib/src/main/java/gov/cms/ab2d/lambdalibs/lib/SsmClientUtil.java new file mode 100644 index 0000000..10f6f02 --- /dev/null +++ b/lambda-lib/src/main/java/gov/cms/ab2d/lambdalibs/lib/SsmClientUtil.java @@ -0,0 +1,13 @@ +package gov.cms.ab2d.lambdalibs.lib; + +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.ssm.SsmClient; + +public class SsmClientUtil { + + public static SsmClient getClient(){ + return SsmClient.builder() + .region(Region.US_EAST_1) + .build(); + } +} diff --git a/lambda-test-utils/src/main/java/gov/cms/ab2d/testutils/AB2DLocalstackContainer.java b/lambda-test-utils/src/main/java/gov/cms/ab2d/testutils/AB2DLocalstackContainer.java index 82c86ae..f02d4a6 100644 --- a/lambda-test-utils/src/main/java/gov/cms/ab2d/testutils/AB2DLocalstackContainer.java +++ b/lambda-test-utils/src/main/java/gov/cms/ab2d/testutils/AB2DLocalstackContainer.java @@ -1,14 +1,11 @@ package gov.cms.ab2d.testutils; -import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.localstack.LocalStackContainer; import org.testcontainers.utility.DockerImageName; -import java.util.Collections; - public class AB2DLocalstackContainer extends LocalStackContainer { - private static final DockerImageName IMAGE_VERSION = DockerImageName.parse("localstack/localstack:1.4.0"); + private static final DockerImageName IMAGE_VERSION = DockerImageName.parse("localstack/localstack:3.5.0"); public AB2DLocalstackContainer() { super(IMAGE_VERSION); diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutParameterStore.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutParameterStore.java index 4a275a3..d32bf89 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutParameterStore.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutParameterStore.java @@ -1,5 +1,6 @@ package gov.cms.ab2d.optout; +import gov.cms.ab2d.lambdalibs.lib.SsmClientUtil; import software.amazon.awssdk.services.ssm.SsmClient; import software.amazon.awssdk.services.ssm.model.GetParameterRequest; @@ -19,9 +20,7 @@ public OptOutParameterStore(String role, String dbHost, String dbUser, String d } public static OptOutParameterStore getParameterStore() { - var ssmClient = SsmClient.builder() - .region(S3_REGION) - .build(); + var ssmClient = SsmClientUtil.getClient(); var role = getValueFromParameterStore(ROLE_PARAM, ssmClient); var dbHost = getValueFromParameterStore(DB_HOST_PARAM, ssmClient);