Skip to content

Commit af971fe

Browse files
committed
Added XRay and AWS Secret Support
1 parent 966f0e0 commit af971fe

File tree

10 files changed

+203
-21
lines changed

10 files changed

+203
-21
lines changed

java/pom.xml

Lines changed: 40 additions & 10 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>
@@ -228,15 +232,6 @@
228232
<scope>provided</scope>
229233
</dependency>
230234

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-
240235
<dependency>
241236
<groupId>org.springframework.boot</groupId>
242237
<artifactId>spring-boot-starter-test</artifactId>
@@ -546,6 +541,37 @@
546541
</build>
547542

548543
<profiles>
544+
545+
<!-- START FEATURE PROFILES -->
546+
547+
<profile>
548+
<id>aws</id>
549+
<activation>
550+
<file>
551+
<exists>.</exists>
552+
</file>
553+
</activation>
554+
<properties>
555+
<aws.profile.name>aws</aws.profile.name>
556+
</properties>
557+
<dependencies>
558+
</dependencies>
559+
</profile>
560+
561+
<profile>
562+
<id>azure</id>
563+
<activation>
564+
<file>
565+
<exists>.</exists>
566+
</file>
567+
</activation>
568+
<properties>
569+
<azure.profile.name>azure</azure.profile.name>
570+
</properties>
571+
<dependencies>
572+
</dependencies>
573+
</profile>
574+
549575
<profile>
550576
<id>owasp-dependency-check</id>
551577
<build>
@@ -565,6 +591,7 @@
565591
</plugins>
566592
</build>
567593
</profile>
594+
568595
<profile>
569596
<id>test</id>
570597
<activation>
@@ -575,6 +602,7 @@
575602
</property>
576603
</activation>
577604
</profile>
605+
578606
<profile>
579607
<id>local</id>
580608
<build>
@@ -588,6 +616,7 @@
588616
</resources>
589617
</build>
590618
</profile>
619+
591620
<profile>
592621
<id>update-permissions</id>
593622
<activation>
@@ -621,5 +650,6 @@
621650
</plugins>
622651
</build>
623652
</profile>
653+
624654
</profiles>
625655
</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)