Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(updater): Add dependency updater #54

Merged
merged 6 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: updater
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * 5' # every Friday at 07:00 Colombia Time
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }}
private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }}
- uses: actions/checkout@v4
with:
ref: master
token: ${{ steps.generate_token.outputs.token }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Check for updates
run: ./gradlew internalTask --action UPDATE_DEPENDENCIES
- name: Check for changes
id: git_changes
run: |
git diff --name-only
if [[ $(git diff --name-only) ]]; then
echo "Changes detected!"
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "No changes detected!"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.HAS_CHANGES == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate_token.outputs.token }}
committer: Dependencies Bot <release-bot@bancolombia.com.co>
commit-message: 'fix(deps): update dependencies'
title: 'fix(deps): update dependencies'
body: 'This PR updates dependencies to latest versions'
branch: 'feature/autoupdate-deps'
base: 'master'
labels: 'dependencies'
reviewers: 'juancgalvis'
6 changes: 3 additions & 3 deletions api/secrets-manager-api/secrets-manager-api.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies {
implementation "io.projectreactor:reactor-core:${reactorCoreVersion}"
implementation "com.google.code.gson:gson:${gsonVersion}"
implementation 'io.projectreactor:reactor-core:3.6.6'
implementation 'com.google.code.gson:gson:2.11.0'
}

ext {
artifactId = 'secrets-manager-api'
artifactDescription = 'Secrets Manager API'
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package co.com.bancolombia.secretsmanager.api;

import co.com.bancolombia.secretsmanager.api.exceptions.SecretException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;

public class exceptionsTest {
import static org.junit.jupiter.api.Assertions.assertEquals;

class ExceptionsTest {

@Test
public void generateExpetion() {
void generateException() {
SecretException ex = new SecretException("My error");
assertEquals("My error", ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ dependencies {
api project(":secrets-manager-api")
implementation 'software.amazon.awssdk:ssm'
implementation 'software.amazon.awssdk:sts'
implementation "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
implementation "io.projectreactor:reactor-core:${reactorCoreVersion}"
testImplementation "io.projectreactor:reactor-test:${reactorCoreVersion}"
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
implementation 'io.projectreactor:reactor-core:3.6.6'
testImplementation 'io.projectreactor:reactor-test:3.6.6'
}

dependencyManagement {
imports {
mavenBom "software.amazon.awssdk:bom:${awsBomVersion}"
mavenBom 'software.amazon.awssdk:bom:2.25.55'
}
}

ext {
artifactId = 'aws-parameter-store-manager-async'
artifactDescription = 'Secrets Manager'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import com.github.benmanes.caffeine.cache.AsyncCache;
import com.github.benmanes.caffeine.cache.Caffeine;
import reactor.core.publisher.Mono;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider;
import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.*;
import software.amazon.awssdk.services.ssm.SsmAsyncClient;
import software.amazon.awssdk.services.ssm.SsmAsyncClientBuilder;
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;
Expand Down Expand Up @@ -63,9 +57,7 @@ private Mono<String> getSecretValue(String secretName) {
}
return Mono.error(new SecretException("Secret value is not a String"));
})
.doOnError((err) -> {
logger.warning("Error retrieving the secret: " + err.getMessage());
});
.doOnError(err -> logger.warning("Error retrieving the secret: " + err.getMessage()));
}

private SsmAsyncClient buildClient(SsmAsyncClientBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package co.com.bancolombia.secretsmanager.config;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AWSParameterStoreConfigTest {
class AWSParameterStoreConfigTest {

private static AWSParameterStoreConfig awsParameterStoreConfig;

@BeforeClass
@BeforeAll
public static void setUp() {
awsParameterStoreConfig = AWSParameterStoreConfig.builder().build();
}

@Test
public void validateAWSParameterStoreConfig() {
void validateAWSParameterStoreConfig() {
assertEquals(Region.US_EAST_1, awsParameterStoreConfig.getRegion());
assertEquals("", awsParameterStoreConfig.getEndpoint());
assertEquals(0, awsParameterStoreConfig.getCacheSeconds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import co.com.bancolombia.secretsmanager.api.exceptions.SecretException;
import co.com.bancolombia.secretsmanager.config.AWSParameterStoreConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import reactor.test.StepVerifier;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ssm.SsmAsyncClient;
Expand All @@ -20,17 +20,17 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class AWSParameterStoreConnectorAsyncTest {
@ExtendWith(MockitoExtension.class)
class AWSParameterStoreConnectorAsyncTest {
@Mock
private SsmAsyncClient client;
@Mock
private SsmAsyncClientBuilder builder;
private AWSParameterStoreConnectorAsync connector;
private AWSParameterStoreConfig config;

@Before
public void buildClient() {
@BeforeEach
void buildClient() {
config = AWSParameterStoreConfig.builder()
.cacheSeconds(1)
.cacheSize(10)
Expand All @@ -40,37 +40,40 @@ public void buildClient() {
}

@Test
public void shouldGetStringSecret() throws SecretException {
void shouldGetStringSecret() {
prepareClient("secretValue", true);
StepVerifier.create(connector.getSecret("secretName"))
.expectNext("secretValue").expectComplete().verify();
}

@Test
public void shouldThrowExceptionWhenSecretValueNull() {
void shouldThrowExceptionWhenSecretValueNull() {
prepareClient("secretValue", false);
StepVerifier.create(connector.getSecret("secretName"))
.expectSubscription()
.verifyError(SecretException.class);
}

@Test
public void shouldThrowExceptionWhenSecretIsNotAString() {
void shouldThrowExceptionWhenSecretIsNotAString() {
prepareClient(null, true);
StepVerifier.create(connector.getSecret("secretName"))
.expectSubscription()
.verifyError(SecretException.class);
}

@Test
public void shouldThrowExceptionWhenNoApplySerialization() {
prepareClient("secretValue", true);
void shouldThrowExceptionWhenNoApplySerialization() {
prepareClient("secretValue", true, false);
StepVerifier.create(connector.getSecret("secretName", Class.class))
.expectSubscription()
.verifyError(UnsupportedOperationException.class);
}

private void prepareClient(String data, boolean secretValue) {
prepareClient(data, secretValue, true);
}
private void prepareClient(String data, boolean secretValue, boolean willCallGetParameter) {
GetParameterResponse responseMock = secretValue ? GetParameterResponse.builder()
.parameter(Parameter.builder().value(data).build())
.build() : null;
Expand All @@ -81,7 +84,9 @@ private void prepareClient(String data, boolean secretValue) {
when(builder.region(any())).thenReturn(builder);
when(builder.build()).thenReturn(client);

when(client.getParameter(any(GetParameterRequest.class))).thenReturn(completableFuture);
if (willCallGetParameter) {
when(client.getParameter(any(GetParameterRequest.class))).thenReturn(completableFuture);
}
connector = new AWSParameterStoreConnectorAsync(config, builder);
}

Expand Down
12 changes: 6 additions & 6 deletions async/aws-secrets-manager-async/aws-secrets-manager-async.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ dependencies {
api project(":secrets-manager-api")
implementation 'software.amazon.awssdk:secretsmanager'
implementation 'software.amazon.awssdk:sts'
implementation "io.projectreactor.addons:reactor-extra:${reactorExtraVersion}"
implementation "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
implementation "io.projectreactor:reactor-core:${reactorCoreVersion}"
testImplementation "io.projectreactor:reactor-test:${reactorCoreVersion}"
implementation 'io.projectreactor.addons:reactor-extra:3.5.1'
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
implementation 'io.projectreactor:reactor-core:3.6.6'
testImplementation 'io.projectreactor:reactor-test:3.6.6'
}

dependencyManagement {
imports {
mavenBom "software.amazon.awssdk:bom:${awsBomVersion}"
mavenBom 'software.amazon.awssdk:bom:2.25.55'
}
}

ext {
artifactId = 'aws-secrets-manager-async'
artifactDescription = 'Secrets Manager'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import com.github.benmanes.caffeine.cache.AsyncCache;
import com.github.benmanes.caffeine.cache.Caffeine;
import reactor.core.publisher.Mono;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider;
import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.*;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClientBuilder;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
Expand Down Expand Up @@ -56,7 +50,7 @@ public Mono<String> getSecret(String secretName) {
public <T> Mono<T> getSecret(String secretName, Class<T> cls) {
return this.getSecret(secretName)
.flatMap((data -> Mono.just(GsonUtils.getInstance().stringToModel(data, cls))))
.onErrorMap((e) -> new SecretException(e.getMessage()));
.onErrorMap(e -> new SecretException(e.getMessage()));
}


Expand All @@ -73,9 +67,7 @@ private Mono<String> getSecretValue(String secretName) {
}
return Mono.error(new SecretException("Secret value is not a String"));
})
.doOnError((err) -> {
logger.warning("Error retrieving the secret: " + err.getMessage());
});
.doOnError(err -> logger.warning("Error retrieving the secret: " + err.getMessage()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package co.com.bancolombia.secretsmanager.config;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AWSSecretsManagerConfigTest {
class AWSSecretsManagerConfigTest {

private static AWSSecretsManagerConfig awsSecretsManagerConfig;

@BeforeClass
@BeforeAll
public static void setUp() {
awsSecretsManagerConfig = AWSSecretsManagerConfig.builder().build();
}

@Test
public void validateAWSSecretsManagerConfig() {
void validateAWSSecretsManagerConfig() {
assertEquals(Region.US_EAST_1, awsSecretsManagerConfig.getRegion());
assertEquals("", awsSecretsManagerConfig.getEndpoint());
assertEquals(0, awsSecretsManagerConfig.getCacheSeconds());
Expand Down
Loading
Loading