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 #93

Merged
merged 2 commits into from
Oct 8, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Environment variables:
* PASS_CORE_DATABASE_PASSWORD=moo
* PASS_CORE_PORT=8080
* PASS_CORE_LOG_DIR=${java.io.tmpdir}/pass-core
* PASS_CORE_BACKEND_USER=backend
* PASS_CORE_BACKEND_PASSWORD=moo
* PASS_CORE_USER=backend
* PASS_CORE_PASSWORD=moo
* PASS_CORE_USE_SQS=false
* PASS_CORE_EMBED_JMS_BROKER=true
* PASS_CORE_SUBMISSION_QUEUE=pass-submission
Expand Down
4 changes: 2 additions & 2 deletions pass-core-main/.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ PASS_CORE_DATABASE_URL=jdbc:postgresql://postgres:5432/pass
PASS_CORE_DATABASE_USERNAME=pass
PASS_CORE_DATABASE_PASSWORD=moo

PASS_CORE_BACKEND_USER=backend
PASS_CORE_BACKEND_PASSWORD=moo
PASS_CORE_USER=backend
PASS_CORE_PASSWORD=moo

PASS_CORE_PORT=8080
PASS_CORE_BASE_URL=http://localhost:8080
Expand Down
5 changes: 5 additions & 0 deletions pass-core-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@
<artifactId>spring-security-saml2-service-provider</artifactId>
</dependency>

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

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
8 changes: 4 additions & 4 deletions pass-core-main/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ spring:
assertingparty:
metadata-uri: ${PASS_CORE_IDP_METADATA:classpath:saml2/idp-metadata.xml}
user:
name: ${PASS_CORE_BACKEND_USER:backend}
password: ${PASS_CORE_BACKEND_PASSWORD:moo}
name: ${PASS_CORE_USER:backend}
password: ${PASS_CORE_PASSWORD:moo}
roles: BACKEND
servlet:
multipart:
Expand Down Expand Up @@ -146,8 +146,8 @@ spring:
driver-class-name: 'org.postgresql.Driver'
security:
user:
name: ${PASS_CORE_BACKEND_USER}
password: ${PASS_CORE_BACKEND_PASSWORD}
name: ${PASS_CORE_USER}
password: ${PASS_CORE_PASSWORD}
roles: BACKEND

server:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.main;

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(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"spring.cloud.aws.credentials.access-key=noop",
"spring.cloud.aws.credentials.secret-key=noop",
"spring.cloud.aws.region.static=us-east-1"
})
@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-core/");
}

@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-pw",
"--type", "SecureString");
localStack.execInContainer("awslocal", "ssm", "put-parameter",
"--name", "/config/pass-core/PASS_CORE_INSTN_CHG_LOG",
"--value", "test-chg-log",
"--type", "SecureString");
}

@Test
public void testLoadPropFromParamStore() {
String userNameProp = environment.getProperty("spring.security.user.name");
assertEquals("backend", userNameProp);
String userPwProp = environment.getProperty("spring.security.user.password");
assertEquals("aws-param-store-pw", userPwProp);
String changeLogProp = environment.getProperty("spring.liquibase.parameters.institution-changelog-file");
assertEquals("test-chg-log", changeLogProp);
}

}
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<properties>
<maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version>
<spring-boot-maven-plugin.version>3.2.2</spring-boot-maven-plugin.version>
<awsspring.version>3.1.0</awsspring.version>
<amazon.pom.version>2.25.16</amazon.pom.version>
<elide.version>7.0.2</elide.version>
<amazon.sqs.version>2.1.2</amazon.sqs.version>
Expand Down Expand Up @@ -143,6 +144,14 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>${awsspring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
Expand Down Expand Up @@ -247,6 +256,7 @@
<!-- These come from bundled jars -->
<ignoredDependency>org.springframework*::</ignoredDependency>
<ignoredDependency>software.amazon.awssdk::</ignoredDependency>
<ignoredDependency>io.awspring.cloud::</ignoredDependency>
</ignoredDependencies>
<ignoredUsedUndeclaredDependencies>
<!-- These come from elide starter -->
Expand Down
Loading