diff --git a/java/.snyk b/java/.snyk index 7d6f94f3..9a7ac1c5 100644 --- a/java/.snyk +++ b/java/.snyk @@ -11,5 +11,15 @@ ignore: expires: '2030-01-01T00:00:00.000Z' 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' + + SNYK:LIC:MAVEN:ORG.ASPECTJ:ASPECTJRT: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' + + 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' \ No newline at end of file diff --git a/java/pom.xml b/java/pom.xml index e37fbd2f..7dee69b1 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -20,9 +20,15 @@ + + no-aws + no-azure + no-cosmosdb + no-dynamodb + 1.0.3 - 1.0.2.2-RELEASE - 1.0.0 + 1.0.3.2-RELEASE + 2.0.0 1.0.0 11 @@ -31,10 +37,9 @@ 2.6.3 3.6.0 3.6.0 - 7.3.0 2.12.3 3.11.2 - 1.18.20 + 1.18.24 2.2 1.6.7 0.8.7 @@ -56,14 +61,6 @@ 4.5.2 3.0.0 - - - - - - - - 4.0.10 4.3.2 @@ -94,11 +91,7 @@ stacks-core-commons ${stacks.core.commons.version} - - com.amido.stacks.modules - stacks-azure-cosmos - ${stacks.azure.cosmos.version} - + com.amido.stacks.modules stacks-core-api @@ -252,36 +245,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.coveo @@ -378,6 +341,76 @@ + + + aws + + + . + + + + aws + + + + org.aspectj + aspectjweaver + 1.9.9 + runtime + + + org.aspectj + aspectjrt + 1.9.9 + runtime + + + + + + azure + + + . + + + + azure + + + + + + + cosmosdb + + + . + + + + cosmosdb + + + + com.amido.stacks.modules + stacks-azure-cosmos + ${stacks.azure.cosmos.version} + + + + + + dynamodb + + dynamodb + + + + + + owasp-dependency-check diff --git a/java/src/main/java/com/amido/stacks/workloads/menu/api/v1/SecretsController.java b/java/src/main/java/com/amido/stacks/workloads/menu/api/v1/SecretsController.java new file mode 100644 index 00000000..46643dd2 --- /dev/null +++ b/java/src/main/java/com/amido/stacks/workloads/menu/api/v1/SecretsController.java @@ -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 getSecrets() { + + return ResponseEntity.ok(secretsService.getSecrets()); + } +} diff --git a/java/src/main/java/com/amido/stacks/workloads/menu/repository/MenuRepository.java b/java/src/main/java/com/amido/stacks/workloads/menu/repository/MenuRepository.java index aabd549d..225d4a2f 100644 --- a/java/src/main/java/com/amido/stacks/workloads/menu/repository/MenuRepository.java +++ b/java/src/main/java/com/amido/stacks/workloads/menu/repository/MenuRepository.java @@ -1,13 +1,13 @@ package com.amido.stacks.workloads.menu.repository; +import com.amido.stacks.cosmosdb.repository.StacksCosmosRepository; import com.amido.stacks.workloads.menu.domain.Menu; -import com.azure.spring.data.cosmos.repository.CosmosRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; @Repository -public interface MenuRepository extends CosmosRepository { +public interface MenuRepository extends StacksCosmosRepository { @Override Menu save(Menu menu); diff --git a/java/src/main/java/com/amido/stacks/workloads/menu/service/v1/SecretsService.java b/java/src/main/java/com/amido/stacks/workloads/menu/service/v1/SecretsService.java new file mode 100644 index 00000000..931e9b5e --- /dev/null +++ b/java/src/main/java/com/amido/stacks/workloads/menu/service/v1/SecretsService.java @@ -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; + } +} diff --git a/java/src/main/resources/application-aws.yml b/java/src/main/resources/application-aws.yml new file mode 100644 index 00000000..22d8e757 --- /dev/null +++ b/java/src/main/resources/application-aws.yml @@ -0,0 +1,10 @@ +aws: + xray: + enabled: ${AWS_XRAY_ENABLED:false} + secretsmanager: + enabled: ${AWS_SECRETS_ENABLED:false} + +# AWS Secrets Manager imports +spring.config.import: + - optional:aws-secretsmanager:/stacks-secret/example-1/ + - optional:aws-secretsmanager:/stacks-secret/example-2/ diff --git a/java/src/main/resources/application-azure.yml b/java/src/main/resources/application-azure.yml new file mode 100644 index 00000000..1d2be838 --- /dev/null +++ b/java/src/main/resources/application-azure.yml @@ -0,0 +1,10 @@ +azure: + application-insights: + instrumentation-key: xxxxxx + enabled: false + keyvault: + enabled: false + uri: https://amido-stacks-tmp.vault.azure.net/ + client-id: xxxxxx + client-key: xxxxxx + tenant-id: xxxxxx diff --git a/java/src/main/resources/application-cosmosdb.yml b/java/src/main/resources/application-cosmosdb.yml new file mode 100644 index 00000000..2db32bbb --- /dev/null +++ b/java/src/main/resources/application-cosmosdb.yml @@ -0,0 +1,5 @@ +azure: + cosmos: + uri: https://localhost:8081 + database: Stacks + key: ${COSMOSDB_KEY} diff --git a/java/src/main/resources/application-dynamodb.yml b/java/src/main/resources/application-dynamodb.yml new file mode 100644 index 00000000..e69de29b diff --git a/java/src/main/resources/application.yml b/java/src/main/resources/application.yml index 3d231594..7b37bb4d 100644 --- a/java/src/main/resources/application.yml +++ b/java/src/main/resources/application.yml @@ -1,4 +1,11 @@ spring: + profiles: + include: + - "@aws.profile.name@" + - "@azure.profile.name@" + - "@cosmosdb.profile.name@" + - "@dynamodb.profile.name@" + application: name: stacks-api-cqrs data: @@ -31,18 +38,3 @@ springdoc: enabled: true enabled: true path: /swagger/oas-json - -azure: - cosmos: - uri: https://localhost:8081 - database: Stacks - key: ${COSMOSDB_KEY} - application-insights: - instrumentation-key: xxxxxx - enabled: false - keyvault: - enabled: false - uri: https://amido-stacks-tmp.vault.azure.net/ - client-id: xxxxxx - client-key: xxxxxx - tenant-id: xxxxxx diff --git a/java/src/main/resources/local/application-aws.yml b/java/src/main/resources/local/application-aws.yml new file mode 100644 index 00000000..22d8e757 --- /dev/null +++ b/java/src/main/resources/local/application-aws.yml @@ -0,0 +1,10 @@ +aws: + xray: + enabled: ${AWS_XRAY_ENABLED:false} + secretsmanager: + enabled: ${AWS_SECRETS_ENABLED:false} + +# AWS Secrets Manager imports +spring.config.import: + - optional:aws-secretsmanager:/stacks-secret/example-1/ + - optional:aws-secretsmanager:/stacks-secret/example-2/ diff --git a/java/src/main/resources/local/application-azure.yml b/java/src/main/resources/local/application-azure.yml new file mode 100644 index 00000000..1d2be838 --- /dev/null +++ b/java/src/main/resources/local/application-azure.yml @@ -0,0 +1,10 @@ +azure: + application-insights: + instrumentation-key: xxxxxx + enabled: false + keyvault: + enabled: false + uri: https://amido-stacks-tmp.vault.azure.net/ + client-id: xxxxxx + client-key: xxxxxx + tenant-id: xxxxxx diff --git a/java/src/main/resources/local/application-cosmodb.yml b/java/src/main/resources/local/application-cosmodb.yml new file mode 100644 index 00000000..2db32bbb --- /dev/null +++ b/java/src/main/resources/local/application-cosmodb.yml @@ -0,0 +1,5 @@ +azure: + cosmos: + uri: https://localhost:8081 + database: Stacks + key: ${COSMOSDB_KEY} diff --git a/java/src/main/resources/local/application-dynamodb.yml b/java/src/main/resources/local/application-dynamodb.yml new file mode 100644 index 00000000..e69de29b diff --git a/java/src/main/resources/local/application.yml b/java/src/main/resources/local/application.yml index a83400e3..bb7bdd9d 100644 --- a/java/src/main/resources/local/application.yml +++ b/java/src/main/resources/local/application.yml @@ -1,4 +1,11 @@ spring: + profiles: + include: + - aws + - azure + - cosmodb + - servicebus + application: name: stacks-api-cqrs data: @@ -31,18 +38,3 @@ springdoc: enabled: true enabled: true path: /swagger/oas-json - -azure: - cosmos: - uri: http://192.168.50.169:8081/ - database: Stacks - key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== - application-insights: - instrumentation-key: xxxxxx - enabled: false - keyvault: - enabled: false - uri: https://amido-stacks-tmp.vault.azure.net/ - client-id: xxxxxx - client-key: xxxxxx - tenant-id: xxxxxx diff --git a/java/src/test/java/com/amido/stacks/workloads/menu/api/v1/SecretsControllerTest.java b/java/src/test/java/com/amido/stacks/workloads/menu/api/v1/SecretsControllerTest.java new file mode 100644 index 00000000..4e6a17fa --- /dev/null +++ b/java/src/test/java/com/amido/stacks/workloads/menu/api/v1/SecretsControllerTest.java @@ -0,0 +1,62 @@ +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.menu.repository.MenuRepository; +import com.amido.stacks.workloads.util.TestHelper; +import com.azure.spring.autoconfigure.cosmos.CosmosAutoConfiguration; +import com.azure.spring.autoconfigure.cosmos.CosmosHealthConfiguration; +import com.azure.spring.autoconfigure.cosmos.CosmosRepositoriesAutoConfiguration; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +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; + +@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" + }) +@EnableAutoConfiguration( + exclude = { + CosmosRepositoriesAutoConfiguration.class, + CosmosAutoConfiguration.class, + CosmosHealthConfiguration.class + }) +@Tag("Integration") +@ActiveProfiles("test") +class SecretsControllerTest { + + public static final String GET_SECRETS = "/v1/secrets"; + + @LocalServerPort private int port; + + @Autowired private TestRestTemplate testRestTemplate; + + @MockBean private MenuRepository menuRepository; + + @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"); + } +}