Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to load app props from AWS Parameter Store #126

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pass-deposit-services/deposit-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<artifactId>spring-cloud-aws-starter-s3</artifactId>
</dependency>

<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-parameter-store</artifactId>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
spring.jms.listener.auto-startup=true
aws.sqs.endpoint.override=

pass.client.url=${PASS_CLIENT_URL:localhost:8080}
pass.client.user=${PASS_CLIENT_USER:fakeuser}
pass.client.password=${PASS_CLIENT_PASSWORD:fakepassword}
pass.client.url=${PASS_CORE_URL:localhost:8080}
pass.client.user=${PASS_CORE_USER:fakeuser}
pass.client.password=${PASS_CORE_PASSWORD:fakepassword}

pmc.ftp.host=${PMC_FTP_HOST:localhost}
pmc.ftp.port=${PMC_FTP_PORT:21}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public abstract class AbstractDepositSubmissionIT {
@Container
protected static final GenericContainer<?> PASS_CORE_CONTAINER = new GenericContainer<>(PASS_CORE_IMG)
.withEnv("PASS_CORE_BASE_URL", "http://localhost:8080")
.withEnv("PASS_CORE_BACKEND_USER", "backend")
.withEnv("PASS_CORE_BACKEND_PASSWORD", "backend")
.withEnv("PASS_CORE_USER", "backend")
.withEnv("PASS_CORE_PASSWORD", "backend")
.waitingFor(Wait.forHttp("/data/grant").forStatusCode(200).withBasicCredentials("backend", "backend"))
.withExposedPorts(8080);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2024 Johns Hopkins University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.pass.deposit.config.spring;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;

import java.io.IOException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@SpringBootTest(
properties = {
"spring.cloud.aws.credentials.access-key=noop",
"spring.cloud.aws.credentials.secret-key=noop",
"spring.cloud.aws.region.static=us-east-1",
"spring.jms.listener.auto-startup=false"
})
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
@Testcontainers
class AwsParamStoreConfigTest {
private static final DockerImageName LOCALSTACK_IMG =
DockerImageName.parse("localstack/localstack:3.1.0");

@Container
private static final LocalStackContainer localStack = new LocalStackContainer(LOCALSTACK_IMG).withServices(SSM);

@Autowired private Environment environment;

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.cloud.aws.parameterstore.endpoint", () -> localStack.getEndpoint().toString());
registry.add("spring.cloud.aws.parameterstore.region", localStack::getRegion);
registry.add("spring.cloud.aws.endpoint", () -> localStack.getEndpoint().toString());
registry.add("spring.cloud.aws.region.static", localStack::getRegion);
registry.add("spring.config.import[0]", () -> "aws-parameterstore:/config/pass-core-client/");
registry.add("spring.config.import[1]", () -> "aws-parameterstore:/config/pass-deposit/");
}

@BeforeAll
static void beforeAll() throws IOException, InterruptedException {
localStack.execInContainer("awslocal", "ssm", "put-parameter",
"--name", "/config/pass-core-client/PASS_CORE_PASSWORD",
"--value", "aws-param-store-core-pw",
"--type", "SecureString");
localStack.execInContainer("awslocal", "ssm", "put-parameter",
"--name", "/config/pass-deposit/DSPACE_PASSWORD",
"--value", "aws-param-store-dspace-pw",
"--type", "SecureString");
}

@Test
public void testLoadPropFromParamStore() {
String userNameProp = environment.getProperty("dspace.user");
assertEquals("[email protected]", userNameProp);
String dspacePwProp = environment.getProperty("dspace.password");
assertEquals("aws-param-store-dspace-pw", dspacePwProp);
String passClientPwProp = environment.getProperty("pass.client.password");
assertEquals("aws-param-store-core-pw", passClientPwProp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@
<logger name="org.eclipse" additivity="false" level="${org.eclipse.level:-WARN}">
<appender-ref ref="STDERR"/>
</logger>
<logger name="org.eclipse.pass.deposit" additivity="false"
level="${org.eclipse.pass.deposit.level:-DEBUG}">
<appender-ref ref="STDERR"/>
</logger>
<logger name="org.eclipse.pass.client" additivity="false"
level="${org.eclipse.pass.client.level:-ERROR}">
<appender-ref ref="STDERR"/>
</logger>
<logger name="org.testcontainers" additivity="false"
level="${org.testcontainers:-INFO}">
<appender-ref ref="STDERR"/>
</logger>
</configuration>
1 change: 1 addition & 0 deletions pass-deposit-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
<!-- These come from bundled jars -->
<ignoredDependency>org.springframework*::</ignoredDependency>
<ignoredDependency>software.amazon.awssdk::</ignoredDependency>
<ignoredDependency>io.awspring.cloud::</ignoredDependency>
<!-- Comes from outdated sword2 client -->
<ignoredDependency>org.apache.abdera::</ignoredDependency>
<ignoredDependency>junit:junit:</ignoredDependency>
Expand Down
6 changes: 5 additions & 1 deletion pass-grant-loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-parameter-store</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -251,7 +255,7 @@
<excludes>
<exclude>com.squareup.okio:okio:*</exclude>
<exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk8:*</exclude>
<!-- TODO try removing -->
<!-- TODO try removing, strange conflict with pass-data-client -->
<exclude>org.apache.commons:commons-lang3:*</exclude>
</excludes>
</dependencyConvergence>
Expand Down
6 changes: 3 additions & 3 deletions pass-grant-loader/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ grant.db.url=${GRANT_DB_URL:}
grant.db.username=${GRANT_DB_USER:}
grant.db.password=${GRANT_DB_PASSWORD:}

pass.client.url=${PASS_CLIENT_URL:localhost:8080}
pass.client.user=${PASS_CLIENT_USER:fakeuser}
pass.client.password=${PASS_CLIENT_PASSWORD:fakepassword}
pass.client.url=${PASS_CORE_URL:localhost:8080}
pass.client.user=${PASS_CORE_USER:fakeuser}
pass.client.password=${PASS_CORE_PASSWORD:fakepassword}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public abstract class AbstractIntegrationTest {
@Container
protected static final GenericContainer<?> PASS_CORE_CONTAINER = new GenericContainer<>(PASS_CORE_IMG)
.withEnv("PASS_CORE_BASE_URL", "http://localhost:8080")
.withEnv("PASS_CORE_BACKEND_USER", "backend")
.withEnv("PASS_CORE_BACKEND_PASSWORD", "backend")
.withEnv("PASS_CORE_USER", "backend")
.withEnv("PASS_CORE_PASSWORD", "backend")
.waitingFor(Wait.forHttp("/data/grant").forStatusCode(200).withBasicCredentials("backend", "backend"))
.withExposedPorts(8080);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2024 Johns Hopkins University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.pass.support.grant;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;

import java.io.IOException;

import org.eclipse.pass.support.grant.data.GrantConnector;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@SpringBootTest(
properties = {
"spring.cloud.aws.credentials.access-key=noop",
"spring.cloud.aws.credentials.secret-key=noop",
"spring.cloud.aws.region.static=us-east-1",
"pass.policy.prop.path=file:./src/test/resources/policy.properties",
"pass.grant.update.ts.path=file:./src/test/resources/grant_update_timestamps"
})
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
@Testcontainers
class AwsParamStoreConfigTest {
private static final DockerImageName LOCALSTACK_IMG =
DockerImageName.parse("localstack/localstack:3.1.0");

@Container
private static final LocalStackContainer localStack = new LocalStackContainer(LOCALSTACK_IMG).withServices(SSM);

@Autowired private Environment environment;
@MockBean protected GrantConnector grantConnector;
@MockBean protected GrantLoaderCLIRunner grantLoaderCLIRunner;

@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.cloud.aws.parameterstore.endpoint", () -> localStack.getEndpoint().toString());
registry.add("spring.cloud.aws.parameterstore.region", localStack::getRegion);
registry.add("spring.cloud.aws.endpoint", () -> localStack.getEndpoint().toString());
registry.add("spring.cloud.aws.region.static", localStack::getRegion);
registry.add("spring.config.import[0]", () -> "aws-parameterstore:/config/pass-core-client/");
registry.add("spring.config.import[1]", () -> "aws-parameterstore:/config/pass-grant/");
}

@BeforeAll
static void beforeAll() throws IOException, InterruptedException {
localStack.execInContainer("awslocal", "ssm", "put-parameter",
"--name", "/config/pass-core-client/PASS_CORE_PASSWORD",
"--value", "aws-param-store-core-pw",
"--type", "SecureString");
localStack.execInContainer("awslocal", "ssm", "put-parameter",
"--name", "/config/pass-grant/GRANT_DB_PASSWORD",
"--value", "aws-param-store-grant-pw",
"--type", "SecureString");
}

@Test
public void testLoadPropFromParamStore() {
String userNameProp = environment.getProperty("grant.db.username");
assertEquals("", userNameProp);
String userPwProp = environment.getProperty("grant.db.password");
assertEquals("aws-param-store-grant-pw", userPwProp);
String passClientPwProp = environment.getProperty("pass.client.password");
assertEquals("aws-param-store-core-pw", passClientPwProp);
}

}
4 changes: 2 additions & 2 deletions pass-journal-loader/pass-journal-loader-nih/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
<platform>${docker.platforms}</platform>
<env>
<PASS_CORE_BASE_URL>${pass.core.url}</PASS_CORE_BASE_URL>
<PASS_CORE_BACKEND_USER>${pass.core.user}</PASS_CORE_BACKEND_USER>
<PASS_CORE_BACKEND_PASSWORD>${pass.core.password}</PASS_CORE_BACKEND_PASSWORD>
<PASS_CORE_USER>${pass.core.user}</PASS_CORE_USER>
<PASS_CORE_PASSWORD>${pass.core.password}</PASS_CORE_PASSWORD>
</env>
<wait>
<http>
Expand Down
23 changes: 23 additions & 0 deletions pass-nihms-loader/nihms-data-harvest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-parameter-store</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -87,6 +98,18 @@
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Loading
Loading