Skip to content

Commit 6972373

Browse files
authored
Merge pull request #905 from amido/feature/4944-4965-XRay-And-Secrets
feature/4944-4965-Added XRay and AWS Secret Support
2 parents 966f0e0 + 8870cde commit 6972373

File tree

12 files changed

+498
-31
lines changed

12 files changed

+498
-31
lines changed

java/.snyk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ ignore:
1212
SNYK:LIC:MAVEN:JUNIT:JUNIT:EPL-1.0:
1313
- '*':
1414
reason: Use of the library is consistent with commercial use as we are not making changes, only consuming it as part of commercial work.
15-
expires: '2030-01-01T00:00:00.000Z'
15+
expires: '2030-01-01T00:00:00.000Z'
16+
snyk:lic:maven:org.aspectj:aspectjweaver:EPL-1.0:
17+
- '*':
18+
reason: Use of the library is consistent with commercial use as we are not making changes, only consuming it as part of commercial work.
19+
expires: '2030-01-01T00:00:00.000Z'

java/pom.xml

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
<description>Demo project for Java</description>
2121

2222
<properties>
23-
<stacks.core.api.version>1.0.2.2-RELEASE</stacks.core.api.version>
23+
<stacks.core.api.version>1.0.3.2-RELEASE</stacks.core.api.version>
2424
<stacks.core.commons.version>1.0.3</stacks.core.commons.version>
2525

26+
<!-- Stacks features -->
27+
<aws.profile.name>no-aws</aws.profile.name>
28+
<azure.profile.name>no-azure</azure.profile.name>
29+
2630
<java.version>11</java.version>
2731
<org.projectlombok.version>1.18.0</org.projectlombok.version>
2832
<org.springdoc-openapi.version>1.6.1</org.springdoc-openapi.version>
@@ -52,6 +56,8 @@
5256
<au.com.dius.pact.provider.maven-version>4.2.7</au.com.dius.pact.provider.maven-version>
5357
<log4j-version>2.17.0</log4j-version>
5458
<org.mapstruct.version>1.5.2.Final</org.mapstruct.version>
59+
<aws-java-sdk-s3.version>1.12.273</aws-java-sdk-s3.version>
60+
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
5561

5662
<fmt-maven-plugin.version>2.13</fmt-maven-plugin.version>
5763
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
@@ -71,15 +77,6 @@
7177
<pact.api.port>9000</pact.api.port>
7278
</properties>
7379

74-
<repositories>
75-
<repository>
76-
<snapshots/>
77-
<id>snapshots</id>
78-
<name>default-maven-virtual</name>
79-
<url>https://amidostacks.jfrog.io/artifactory/default-maven-virtual</url>
80-
</repository>
81-
</repositories>
82-
8380
<dependencyManagement>
8481
<dependencies>
8582
<dependency>
@@ -98,6 +95,12 @@
9895
<groupId>com.amido.stacks.modules</groupId>
9996
<artifactId>stacks-core-api</artifactId>
10097
<version>${stacks.core.api.version}</version>
98+
<exclusions>
99+
<exclusion>
100+
<groupId>org.aspectj</groupId>
101+
<artifactId>aspectjweaver</artifactId>
102+
</exclusion>
103+
</exclusions>
101104
</dependency>
102105

103106
<dependency>
@@ -228,15 +231,6 @@
228231
<scope>provided</scope>
229232
</dependency>
230233

231-
<!--
232-
<dependency>
233-
<groupId>com.microsoft.azure</groupId>
234-
<artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
235-
<version>${azure.springboot.version}</version>
236-
<scope>runtime</scope>
237-
</dependency>
238-
-->
239-
240234
<dependency>
241235
<groupId>org.springframework.boot</groupId>
242236
<artifactId>spring-boot-starter-test</artifactId>
@@ -320,6 +314,12 @@
320314
<scope>runtime</scope>
321315
</dependency>
322316

317+
<dependency>
318+
<groupId>com.amazonaws</groupId>
319+
<artifactId>aws-java-sdk-s3</artifactId>
320+
<version>${aws-java-sdk-s3.version}</version>
321+
</dependency>
322+
323323
</dependencies>
324324

325325
<reporting>
@@ -546,6 +546,37 @@
546546
</build>
547547

548548
<profiles>
549+
550+
<!-- START FEATURE PROFILES -->
551+
552+
<profile>
553+
<id>aws</id>
554+
<activation>
555+
<file>
556+
<exists>.</exists>
557+
</file>
558+
</activation>
559+
<properties>
560+
<aws.profile.name>aws</aws.profile.name>
561+
</properties>
562+
<dependencies>
563+
</dependencies>
564+
</profile>
565+
566+
<profile>
567+
<id>azure</id>
568+
<activation>
569+
<file>
570+
<exists>.</exists>
571+
</file>
572+
</activation>
573+
<properties>
574+
<azure.profile.name>azure</azure.profile.name>
575+
</properties>
576+
<dependencies>
577+
</dependencies>
578+
</profile>
579+
549580
<profile>
550581
<id>owasp-dependency-check</id>
551582
<build>
@@ -565,6 +596,7 @@
565596
</plugins>
566597
</build>
567598
</profile>
599+
568600
<profile>
569601
<id>test</id>
570602
<activation>
@@ -575,6 +607,7 @@
575607
</property>
576608
</activation>
577609
</profile>
610+
578611
<profile>
579612
<id>local</id>
580613
<build>
@@ -588,6 +621,7 @@
588621
</resources>
589622
</build>
590623
</profile>
624+
591625
<profile>
592626
<id>update-permissions</id>
593627
<activation>
@@ -621,5 +655,6 @@
621655
</plugins>
622656
</build>
623657
</profile>
658+
624659
</profiles>
625660
</project>

java/run_tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export BASE_URL=http://localhost:9000
2+
3+
mvn -f ../api-tests/pom.xml clean verify
4+
open ../api-tests/target/site/serenity/index.html
5+
6+
mvn -f ../api-tests-karate/pom.xml clean test
7+
open ../api-tests-karate/target/surefire-reports/karate-summary.html
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.amido.stacks.workloads.menu.api.v1;
2+
3+
import com.amido.stacks.workloads.menu.service.v1.SecretsService;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RequestMapping(
13+
path = "/v1/secrets",
14+
produces = MediaType.APPLICATION_JSON_VALUE + "; charset=utf-8")
15+
@RequiredArgsConstructor
16+
public class SecretsController {
17+
18+
private final SecretsService secretsService;
19+
20+
@GetMapping
21+
public ResponseEntity<String> getSecrets() {
22+
23+
return ResponseEntity.ok(secretsService.getSecrets());
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.amido.stacks.workloads.menu.service.v1;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
@Slf4j
9+
public class SecretsService {
10+
11+
@Value(value = "${stacks-secret-1:secret-not-available}")
12+
private String secret1;
13+
14+
@Value(value = "${stacks-secret-2:secret-not-available}")
15+
private String secret2;
16+
17+
@Value(value = "${stacks-secret-3:secret-not-available}")
18+
private String secret3;
19+
20+
@Value(value = "${stacks-secret-4:secret-not-available}")
21+
private String secret4;
22+
23+
public String getSecrets() {
24+
25+
log.info("Getting some secrets...");
26+
27+
return showSecrets();
28+
}
29+
30+
private String showSecrets() {
31+
return "Secrets -> " + secret1 + ", " + secret2 + ", " + secret3 + ", " + secret4;
32+
}
33+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring.config.import:
2+
- optional:aws-secretsmanager:/stacks-secret/example-1/
3+
- optional:aws-secretsmanager:/stacks-secret/example-2/
4+
5+
aws:
6+
xray:
7+
enabled: ${AWS_XRAY_ENABLED:false}
8+
secretsmanager:
9+
enabled: ${AWS_SECRETS_ENABLED:false}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
azure:
2+
application-insights:
3+
instrumentation-key: xxxxxx
4+
enabled: true
5+
keyvault:
6+
enabled: false
7+
uri: https://amido.stacks-tmp.vault.azure.net/
8+
client-id: xxxxxx
9+
client-key: xxxxxx
10+
tenant-id: xxxxxx

java/src/main/resources/application.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
spring:
2+
profiles:
3+
include:
4+
- "@aws.profile.name@"
5+
- "@azure.profile.name@"
6+
27
application:
38
name: stacks-api
49
data:
@@ -31,14 +36,3 @@ springdoc:
3136
enabled: true
3237
enabled: true
3338
path: /swagger/oas-json
34-
35-
azure:
36-
application-insights:
37-
instrumentation-key: xxxxxx
38-
enabled: true
39-
keyvault:
40-
enabled: false
41-
uri: https://amido-stacks-tmp.vault.azure.net/
42-
client-id: xxxxxx
43-
client-key: xxxxxx
44-
tenant-id: xxxxxx
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring.config.import:
2+
- optional:aws-secretsmanager:/stacks-secret/example-1/
3+
- optional:aws-secretsmanager:/stacks-secret/example-2/
4+
5+
aws:
6+
xray:
7+
enabled: ${AWS_XRAY_ENABLED:false}
8+
secretsmanager:
9+
enabled: ${AWS_SECRETS_ENABLED:false}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
azure:
2+
application-insights:
3+
instrumentation-key: xxxxxx
4+
enabled: true
5+
keyvault:
6+
enabled: false
7+
uri: https://amido.stacks-tmp.vault.azure.net/
8+
client-id: xxxxxx
9+
client-key: xxxxxx
10+
tenant-id: xxxxxx
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.amido.stacks.workloads.menu.api.v1;
2+
3+
import static org.assertj.core.api.BDDAssertions.then;
4+
5+
import com.amido.stacks.workloads.Application;
6+
import com.amido.stacks.workloads.util.TestHelper;
7+
import org.junit.jupiter.api.Tag;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.boot.test.web.client.TestRestTemplate;
12+
import org.springframework.boot.web.server.LocalServerPort;
13+
import org.springframework.http.HttpStatus;
14+
import org.springframework.test.context.ActiveProfiles;
15+
import org.springframework.test.context.TestPropertySource;
16+
17+
@SpringBootTest(
18+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
19+
classes = Application.class,
20+
properties = {
21+
"stacks-secret-1=SEC1",
22+
"stacks-secret-2=SEC2",
23+
"stacks-secret-3=SEC3",
24+
"stacks-secret-4=SEC4"
25+
})
26+
@TestPropertySource(
27+
properties = {
28+
"management.port=0",
29+
"aws.xray.enabled=false",
30+
"aws.secretsmanager.enabled=false"
31+
})
32+
@Tag("Integration")
33+
@ActiveProfiles("test")
34+
class SecretsControllerTest {
35+
36+
public static final String GET_SECRETS = "/v1/secrets";
37+
38+
@LocalServerPort private int port;
39+
40+
@Autowired private TestRestTemplate testRestTemplate;
41+
42+
@Test
43+
void shouldReturnValidSecrets() {
44+
// Given
45+
46+
// When
47+
var response =
48+
this.testRestTemplate.getForEntity(
49+
String.format("%s/v1/secrets", TestHelper.getBaseURL(port)), String.class);
50+
51+
// Then
52+
then(response.getStatusCode()).isEqualTo(HttpStatus.OK);
53+
then(response.getBody()).isEqualTo("Secrets -> SEC1, SEC2, SEC3, SEC4");
54+
}
55+
}

0 commit comments

Comments
 (0)