Skip to content

Commit

Permalink
docs(updated): Add secret example documentation and updater actions
Browse files Browse the repository at this point in the history
  • Loading branch information
juancgalvis committed Jan 22, 2025
1 parent 46f7d77 commit 4b0ebfd
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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'
3 changes: 3 additions & 0 deletions docs/docs/reactive-commons/1-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
71 changes: 71 additions & 0 deletions docs/docs/reactive-commons/9-configuration-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
```

</TabItem>
Expand Down

0 comments on commit 4b0ebfd

Please sign in to comment.