Skip to content

Commit

Permalink
Merge pull request #905 from amido/feature/4944-4965-XRay-And-Secrets
Browse files Browse the repository at this point in the history
feature/4944-4965-Added XRay and AWS Secret Support
  • Loading branch information
sdavis-amido authored Aug 3, 2022
2 parents 966f0e0 + 8870cde commit 6972373
Show file tree
Hide file tree
Showing 12 changed files with 498 additions and 31 deletions.
6 changes: 5 additions & 1 deletion java/.snyk
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ ignore:
SNYK:LIC:MAVEN:JUNIT:JUNIT:EPL-1.0:
- '*':
reason: Use of the library is consistent with commercial use as we are not making changes, only consuming it as part of commercial work.
expires: '2030-01-01T00:00:00.000Z'
expires: '2030-01-01T00:00:00.000Z'
snyk:lic:maven:org.aspectj:aspectjweaver:EPL-1.0:
- '*':
reason: Use of the library is consistent with commercial use as we are not making changes, only consuming it as part of commercial work.
expires: '2030-01-01T00:00:00.000Z'
73 changes: 54 additions & 19 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
<description>Demo project for Java</description>

<properties>
<stacks.core.api.version>1.0.2.2-RELEASE</stacks.core.api.version>
<stacks.core.api.version>1.0.3.2-RELEASE</stacks.core.api.version>
<stacks.core.commons.version>1.0.3</stacks.core.commons.version>

<!-- Stacks features -->
<aws.profile.name>no-aws</aws.profile.name>
<azure.profile.name>no-azure</azure.profile.name>

<java.version>11</java.version>
<org.projectlombok.version>1.18.0</org.projectlombok.version>
<org.springdoc-openapi.version>1.6.1</org.springdoc-openapi.version>
Expand Down Expand Up @@ -52,6 +56,8 @@
<au.com.dius.pact.provider.maven-version>4.2.7</au.com.dius.pact.provider.maven-version>
<log4j-version>2.17.0</log4j-version>
<org.mapstruct.version>1.5.2.Final</org.mapstruct.version>
<aws-java-sdk-s3.version>1.12.273</aws-java-sdk-s3.version>
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>

<fmt-maven-plugin.version>2.13</fmt-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
Expand All @@ -71,15 +77,6 @@
<pact.api.port>9000</pact.api.port>
</properties>

<repositories>
<repository>
<snapshots/>
<id>snapshots</id>
<name>default-maven-virtual</name>
<url>https://amidostacks.jfrog.io/artifactory/default-maven-virtual</url>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -98,6 +95,12 @@
<groupId>com.amido.stacks.modules</groupId>
<artifactId>stacks-core-api</artifactId>
<version>${stacks.core.api.version}</version>
<exclusions>
<exclusion>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -228,15 +231,6 @@
<scope>provided</scope>
</dependency>

<!--
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
<version>${azure.springboot.version}</version>
<scope>runtime</scope>
</dependency>
-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -320,6 +314,12 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws-java-sdk-s3.version}</version>
</dependency>

</dependencies>

<reporting>
Expand Down Expand Up @@ -546,6 +546,37 @@
</build>

<profiles>

<!-- START FEATURE PROFILES -->

<profile>
<id>aws</id>
<activation>
<file>
<exists>.</exists>
</file>
</activation>
<properties>
<aws.profile.name>aws</aws.profile.name>
</properties>
<dependencies>
</dependencies>
</profile>

<profile>
<id>azure</id>
<activation>
<file>
<exists>.</exists>
</file>
</activation>
<properties>
<azure.profile.name>azure</azure.profile.name>
</properties>
<dependencies>
</dependencies>
</profile>

<profile>
<id>owasp-dependency-check</id>
<build>
Expand All @@ -565,6 +596,7 @@
</plugins>
</build>
</profile>

<profile>
<id>test</id>
<activation>
Expand All @@ -575,6 +607,7 @@
</property>
</activation>
</profile>

<profile>
<id>local</id>
<build>
Expand All @@ -588,6 +621,7 @@
</resources>
</build>
</profile>

<profile>
<id>update-permissions</id>
<activation>
Expand Down Expand Up @@ -621,5 +655,6 @@
</plugins>
</build>
</profile>

</profiles>
</project>
7 changes: 7 additions & 0 deletions java/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export BASE_URL=http://localhost:9000

mvn -f ../api-tests/pom.xml clean verify
open ../api-tests/target/site/serenity/index.html

mvn -f ../api-tests-karate/pom.xml clean test
open ../api-tests-karate/target/surefire-reports/karate-summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.amido.stacks.workloads.menu.api.v1;

import com.amido.stacks.workloads.menu.service.v1.SecretsService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(
path = "/v1/secrets",
produces = MediaType.APPLICATION_JSON_VALUE + "; charset=utf-8")
@RequiredArgsConstructor
public class SecretsController {

private final SecretsService secretsService;

@GetMapping
public ResponseEntity<String> getSecrets() {

return ResponseEntity.ok(secretsService.getSecrets());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.amido.stacks.workloads.menu.service.v1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SecretsService {

@Value(value = "${stacks-secret-1:secret-not-available}")
private String secret1;

@Value(value = "${stacks-secret-2:secret-not-available}")
private String secret2;

@Value(value = "${stacks-secret-3:secret-not-available}")
private String secret3;

@Value(value = "${stacks-secret-4:secret-not-available}")
private String secret4;

public String getSecrets() {

log.info("Getting some secrets...");

return showSecrets();
}

private String showSecrets() {
return "Secrets -> " + secret1 + ", " + secret2 + ", " + secret3 + ", " + secret4;
}
}
9 changes: 9 additions & 0 deletions java/src/main/resources/application-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.config.import:
- optional:aws-secretsmanager:/stacks-secret/example-1/
- optional:aws-secretsmanager:/stacks-secret/example-2/

aws:
xray:
enabled: ${AWS_XRAY_ENABLED:false}
secretsmanager:
enabled: ${AWS_SECRETS_ENABLED:false}
10 changes: 10 additions & 0 deletions java/src/main/resources/application-azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
azure:
application-insights:
instrumentation-key: xxxxxx
enabled: true
keyvault:
enabled: false
uri: https://amido.stacks-tmp.vault.azure.net/
client-id: xxxxxx
client-key: xxxxxx
tenant-id: xxxxxx
16 changes: 5 additions & 11 deletions java/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
spring:
profiles:
include:
- "@aws.profile.name@"
- "@azure.profile.name@"

application:
name: stacks-api
data:
Expand Down Expand Up @@ -31,14 +36,3 @@ springdoc:
enabled: true
enabled: true
path: /swagger/oas-json

azure:
application-insights:
instrumentation-key: xxxxxx
enabled: true
keyvault:
enabled: false
uri: https://amido-stacks-tmp.vault.azure.net/
client-id: xxxxxx
client-key: xxxxxx
tenant-id: xxxxxx
9 changes: 9 additions & 0 deletions java/src/main/resources/local/application-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.config.import:
- optional:aws-secretsmanager:/stacks-secret/example-1/
- optional:aws-secretsmanager:/stacks-secret/example-2/

aws:
xray:
enabled: ${AWS_XRAY_ENABLED:false}
secretsmanager:
enabled: ${AWS_SECRETS_ENABLED:false}
10 changes: 10 additions & 0 deletions java/src/main/resources/local/application-azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
azure:
application-insights:
instrumentation-key: xxxxxx
enabled: true
keyvault:
enabled: false
uri: https://amido.stacks-tmp.vault.azure.net/
client-id: xxxxxx
client-key: xxxxxx
tenant-id: xxxxxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.amido.stacks.workloads.menu.api.v1;

import static org.assertj.core.api.BDDAssertions.then;

import com.amido.stacks.workloads.Application;
import com.amido.stacks.workloads.util.TestHelper;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = Application.class,
properties = {
"stacks-secret-1=SEC1",
"stacks-secret-2=SEC2",
"stacks-secret-3=SEC3",
"stacks-secret-4=SEC4"
})
@TestPropertySource(
properties = {
"management.port=0",
"aws.xray.enabled=false",
"aws.secretsmanager.enabled=false"
})
@Tag("Integration")
@ActiveProfiles("test")
class SecretsControllerTest {

public static final String GET_SECRETS = "/v1/secrets";

@LocalServerPort private int port;

@Autowired private TestRestTemplate testRestTemplate;

@Test
void shouldReturnValidSecrets() {
// Given

// When
var response =
this.testRestTemplate.getForEntity(
String.format("%s/v1/secrets", TestHelper.getBaseURL(port)), String.class);

// Then
then(response.getStatusCode()).isEqualTo(HttpStatus.OK);
then(response.getBody()).isEqualTo("Secrets -> SEC1, SEC2, SEC3, SEC4");
}
}
Loading

0 comments on commit 6972373

Please sign in to comment.