Skip to content

Commit

Permalink
feat: aws session credentials, misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
g-otn committed Jan 29, 2024
1 parent 3323d09 commit a91b78c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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
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.serviceidentification.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);
}
}
25 changes: 10 additions & 15 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
spring:
# docker:
# compose:
# enabled: true
# file: compose-dev.yml
# start:
# command: up
# stop:
# command: down
# docker:
# compose:
# enabled: true
# file: compose-dev.yml
# start:
# command: up
# stop:
# command: down
jpa:
hibernate:
ddl-auto: validate
Expand All @@ -17,12 +17,7 @@ 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: "/identification"
context-path: "/identification"
18 changes: 16 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ management:
endpoint:
health:
show-components: always
shutdown:
enabled: true # For debugging
endpoints:
web:
exposure:
include: health, info
include: health, info, metrics, shutdown

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}"
url: "${DOCS_API_URL:https://9ah1j49vm1.execute-api.us-east-2.amazonaws.com}"

# --- Custom keys ---

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

1 change: 1 addition & 0 deletions src/main/resources/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.exclusions=src/java/br/com/grupo63/techchallenge/serviceidentification/config/**

0 comments on commit a91b78c

Please sign in to comment.