From 4b0ebfd5e91cea9f689e00b5ca0dcb387766a826 Mon Sep 17 00:00:00 2001 From: Juan C Galvis <8420868+juancgalvis@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:22:05 -0500 Subject: [PATCH] docs(updated): Add secret example documentation and updater actions --- .github/workflows/updater.yml | 41 +++++++++++ .../reactive-commons/1-getting-started.md | 3 + .../9-configuration-properties.md | 71 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 .github/workflows/updater.yml diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml new file mode 100644 index 0000000..1f88ecd --- /dev/null +++ b/.github/workflows/updater.yml @@ -0,0 +1,41 @@ +name: updater +on: + workflow_dispatch: + schedule: + - cron: '0 12 * * 5' # every Friday at 07:00 Colombia Time +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - 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: ${{ secrets.PA_TOKEN }} + committer: Dependencies Bot + 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' \ No newline at end of file diff --git a/docs/docs/reactive-commons/1-getting-started.md b/docs/docs/reactive-commons/1-getting-started.md index d8985c6..4d400ca 100644 --- a/docs/docs/reactive-commons/1-getting-started.md +++ b/docs/docs/reactive-commons/1-getting-started.md @@ -112,6 +112,9 @@ public class MyRabbitMQConfig { } ``` +Please refer to [Configuration Properties](/reactive-commons-java/docs/reactive-commons/configuration-properties) +Or with secrets [Loading properties from a secret](/reactive-commons-java/docs/reactive-commons/configuration-properties#loading-properties-from-a-secret) + The 5.x.x stable version of Reactive Commons has been merged with the deprecated `-eda` variant, this means that the `async-commons-rabbit-starter` artifact is now the only one to use. diff --git a/docs/docs/reactive-commons/9-configuration-properties.md b/docs/docs/reactive-commons/9-configuration-properties.md index d863d12..a0da9bd 100644 --- a/docs/docs/reactive-commons/9-configuration-properties.md +++ b/docs/docs/reactive-commons/9-configuration-properties.md @@ -105,6 +105,8 @@ public class MyDomainConfig { } ``` +## Loading properties from a secret + Additionally, if you want to set only connection properties you can use the `AsyncPropsDomain.RabbitSecretFiller` class. ```java @@ -115,6 +117,75 @@ public AsyncPropsDomain.RabbitSecretFiller customFiller() { // customize asyncProps here by domain }; } +``` + +For example if you use the [Secrets Manager](https://github.com/bancolombia/secrets-manager) project, you may use +the next code to load the properties from a secret: + +1. Create a class with the properties that you will load from the secret: +```java +import lombok.Builder; +import lombok.Data; +import org.reactivecommons.async.rabbit.config.RabbitProperties; + +@Data +@Builder +public class RabbitConnectionProperties { + private String hostname; + private String password; + private String username; + private Integer port; + private String virtualhost; + private boolean ssl; + + public RabbitProperties toRabbitProperties() { + var rabbitProperties = new RabbitProperties(); + rabbitProperties.setHost(this.hostname); + rabbitProperties.setUsername(this.username); + rabbitProperties.setPassword(this.password); + rabbitProperties.setPort(this.port); + rabbitProperties.setVirtualHost(this.virtualhost); + rabbitProperties.getSsl().setEnabled(this.ssl); // To enable SSL + return rabbitProperties; + } +} +``` +2. Use the `SecretsManager` to load the properties from the secret: + +```java +import co.com.bancolombia.secretsmanager.api.GenericManager; +import lombok.SneakyThrows; +import lombok.extern.log4j.Log4j2; +import org.reactivecommons.async.rabbit.config.RabbitProperties; +import org.reactivecommons.async.rabbit.config.props.AsyncPropsDomain; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.lang.reflect.GenericArrayType; + +@Log4j2 +@Configuration +public class AsyncEventBusConfig { + + // TODO: You should create the GenericManager bean as indicated in Secrets Manager library + @Bean + public AsyncPropsDomain.RabbitSecretFiller rabbitSecretFiller(GenericManager genericManager) { + return (domain, props) -> { + if (props.getSecret() != null) { + log.info("Loading RabbitMQ connection properties from secret: {}", props.getSecret()); + props.setConnectionProperties(getFromSecret(genericManager, props.getSecret())); + log.info("RabbitMQ connection properties loaded successfully with host: '{}'", + props.getConnectionProperties().getHost()); + } + }; + } + + @SneakyThrows + private RabbitProperties getFromSecret(GenericManager genericManager, String secretName) { + return genericManager.getSecret(secretName, RabbitConnectionProperties.class).toRabbitProperties(); + } +} + ```