Skip to content

Commit

Permalink
fix: prepare cloud (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-otn authored Jan 29, 2024
2 parents 7eb302b + 6b844ad commit 8d0c7e2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 38 deletions.
27 changes: 21 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.grupo63</groupId>
<artifactId>serviceproduction</artifactId>
Expand All @@ -16,6 +16,10 @@
<description>FIAP SOAT1 2023 - Group 63 - Phase 4</description>
<properties>
<java.version>17</java.version>
<sonar.coverage.exclusions>
**/config/*,
**/dto/*DTO.*,
</sonar.coverage.exclusions>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -105,7 +109,6 @@
</dependencies>

<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -118,6 +121,17 @@
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
Expand Down Expand Up @@ -166,7 +180,8 @@
</goals>
<configuration>
<excludes>
<exclude>**/br/com/grupo63/serviceproduction/config/DynamoDBConfig.class</exclude>
<exclude>**/dto/*DTO.*</exclude>
<exclude>**/config/**</exclude>
</excludes>
<formats>
<format>XML</format>
Expand All @@ -179,4 +194,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
9 changes: 0 additions & 9 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 26 additions & 8 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ spring:
flyway:
locations: classpath:db/migrations/{vendor}/
enabled: true
jwt:
token:
key:
public: "${JWT_PUBLIC_KEY}"

springdoc:
swagger-ui:
Expand All @@ -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}"

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}"

0 comments on commit 8d0c7e2

Please sign in to comment.