From 6b844adf4b8d739e5d2fbfaa831913e225ad6f58 Mon Sep 17 00:00:00 2001 From: g-otn <44736064+g-otn@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:20:18 -0300 Subject: [PATCH] fix: prepare cloud --- pom.xml | 27 +++++++++++---- .../ServiceProductionApplication.java | 6 ++-- .../config/DynamoDBConfig.java | 31 ++++++++++------- src/main/resources/application-dev.yml | 9 ----- src/main/resources/application.yml | 34 ++++++++++++++----- 5 files changed, 69 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 404ee24..ef86a37 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,13 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 3.1.0 - + br.com.grupo63 serviceproduction @@ -16,6 +16,10 @@ FIAP SOAT1 2023 - Group 63 - Phase 4 17 + + **/config/*, + **/dto/*DTO.*, + @@ -105,7 +109,6 @@ - app org.springframework.boot @@ -118,6 +121,17 @@ + + + + build-info + + + + + + io.github.git-commit-id + git-commit-id-maven-plugin @@ -166,7 +180,8 @@ - **/br/com/grupo63/serviceproduction/config/DynamoDBConfig.class + **/dto/*DTO.* + **/config/** XML @@ -179,4 +194,4 @@ - + \ No newline at end of file diff --git a/src/main/java/br/com/grupo63/serviceproduction/ServiceProductionApplication.java b/src/main/java/br/com/grupo63/serviceproduction/ServiceProductionApplication.java index 1ad8859..4b2fbb3 100644 --- a/src/main/java/br/com/grupo63/serviceproduction/ServiceProductionApplication.java +++ b/src/main/java/br/com/grupo63/serviceproduction/ServiceProductionApplication.java @@ -12,9 +12,9 @@ @OpenAPIDefinition( info = @Info(title = "${info.name}", description = "${info.description}", version = "${info.version}"), servers ={ - @Server(url = "${server.servlet.context-path}", description = "Current URL"), - @Server(url = "localhost:8080", description = "Local"), - @Server(url = "${docs.api.url}", description = "API Gateway Invoke URL") + @Server(url = "${server.servlet.context-path:}", description = "Current URL"), + @Server(url = "localhost:${server.port:8080}${server.servlet.context-path:}", description = "Localhost"), + @Server(url = "${app.docs-api-url:(no value)}${server.servlet.context-path:}", description = "Custom URL from env") }) @SecurityScheme( name = "bearerAuth", diff --git a/src/main/java/br/com/grupo63/serviceproduction/config/DynamoDBConfig.java b/src/main/java/br/com/grupo63/serviceproduction/config/DynamoDBConfig.java index 6bd1329..03ce486 100644 --- a/src/main/java/br/com/grupo63/serviceproduction/config/DynamoDBConfig.java +++ b/src/main/java/br/com/grupo63/serviceproduction/config/DynamoDBConfig.java @@ -2,6 +2,7 @@ import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.BasicSessionCredentials; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; @@ -18,30 +19,36 @@ @EnableDynamoDBRepositories (basePackages = "br.com.grupo63.serviceproduction.gateway") public class DynamoDBConfig { - @Value("${amazon.dynamodb.endpoint}") - private String amazonDynamoDBEndpoint; + @Value("${app.aws.dynamodb.endpoint}") + private String awsDynamoDBEndpoint; - @Value("${amazon.aws.accesskey}") - private String amazonAWSAccessKey; + @Value("${app.aws.access-key}") + private String awsAccessKey; - @Value("${amazon.aws.secretkey}") - private String amazonAWSSecretKey; + @Value("${app.aws.secret-key}") + private String awsSecretKey; + + @Value("${app.aws.session-token}") + private String awsSessionToken; @Bean public AmazonDynamoDB amazonDynamoDB() { AmazonDynamoDB amazonDynamoDB - = new AmazonDynamoDBClient(amazonAWSCredentials()); + = new AmazonDynamoDBClient(awsCredentials()); - if (!StringUtils.isEmpty(amazonDynamoDBEndpoint)) { - amazonDynamoDB.setEndpoint(amazonDynamoDBEndpoint); + if (!StringUtils.isEmpty(awsDynamoDBEndpoint)) { + amazonDynamoDB.setEndpoint(awsDynamoDBEndpoint); } return amazonDynamoDB; } @Bean - public AWSCredentials amazonAWSCredentials() { - return new BasicAWSCredentials( - amazonAWSAccessKey, amazonAWSSecretKey); + public AWSCredentials awsCredentials() { + if (awsSessionToken == null || awsSessionToken.isBlank()) { + return new BasicAWSCredentials( + awsAccessKey, awsSecretKey); + } + return new BasicSessionCredentials(awsAccessKey, awsSecretKey, awsSessionToken); } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index be50124..b7e3123 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -17,12 +17,3 @@ jwt: token: key: public: "${JWT_PUBLIC_KEY:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqStd8n4SGNM0eZhV/hzU+urHA5/IMZPoP9YQ9ZcLKWiX33nI6bSuZMCrLZcJExf63xS+uxDpGxM8Mnk2zOdl+lPwANXLzP1us5P1PyA3YPycW9J7C5YTQW0GiEL3M93ZX7vMJiVoBYblP3JPlYnoYlBORuc0JPk33KtfEZP+78qXpPHM8imYrJLe8ceiDLLFDU/nh5KC2dWAy3ci1ahoJ1Q9ELhp3IZLvOTX57H/T2VKOYOya5+ST41h+JjzI+qGTVnLcKaW+k25YLlVnkSspvdx98+yQDi7kbOTS6yRZHUPD6wPk/nUozpD0nZKccoH4W+zMwmQVtsAA6JCA9gfGwIDAQAB}" -amazon: - dynamodb: - endpoint: "${AMAZON_DYNAMODB_ENDPOINT:http://127.0.0.1:8080}" - aws: - accesskey: "${AMAZON_AWS_ACCESSKEY:accesskey}" - secretkey: "${AMAZON_AWS_SECRETKEY:secretkey}" -server: - servlet: - context-path: "/production" diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8c78f65..f58b137 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,10 +14,6 @@ spring: flyway: locations: classpath:db/migrations/{vendor}/ enabled: true -jwt: - token: - key: - public: "${JWT_PUBLIC_KEY}" springdoc: swagger-ui: @@ -31,15 +27,37 @@ management: endpoint: health: show-components: always + shutdown: + enabled: true # For debugging endpoints: web: exposure: - include: health, info + include: health, info, metrics, shutdown + +server: + servlet: + context-path: "/production" + port: 8004 + + +# --- Custom keys --- + info: name: '@project.name@' description: '@project.description@' version: '@project.version@' -docs: - api: - url: "${DOCS_API_URL:https://9ah1j49vm1.execute-api.us-east-2.amazonaws.com}" \ No newline at end of file + +app: + docs-api-url: "${DOCS_API_URL:(no value)}" + aws: + access-key: "${AWS_ACCESS_KEY:no_access_key}" + secret-key: "${AWS_SECRET_KEY:no_secret_key}" + session-token: "${AWS_SESSION_TOKEN:}" + dynamodb: + endpoint: "${AWS_DYNAMODB_ENDPOINT:dynamodb.us-east-1.amazonaws.com}" + +jwt: + token: + key: + public: "${JWT_PUBLIC_KEY}" \ No newline at end of file