Example for Oracle Cloud Vault

    To enable distributed configuration a src/main/resources/bootstrap.yml configuration file must be created and configured to use one or more Oracle Cloud Vaults:

    bootstrap.yml

    1. micronaut:
    2. application:
    3. name: vault-test
    4. config-client:
    5. enabled: true
    6. oraclecloud:
    7. vault:
    8. config:
    9. enabled: true
    10. vaults:
    11. - ocid: ocid1.vault.oc1.phx...
    12. compartment-ocid: ocid1.compartment.oc1...
    13. use-instance-principal: false
    14. path-to-config: ~/.oci/config
    15. profile: DEFAULT
    16. region: US-PHOENIX-1

    See the for all configuration options.

    Each configured vault will be read and all of the secrets within the vault will be retrieved and set into configuration variables with the exact same name as the secret in the Oracle Cloud Vault.

    For example, if you create a secret with the name of SECRET_ONE in your Oracle Cloud Vault, then it will be available to use in your application like any standard configuration variable:

    1. @Value("${SECRET_ONE}") String secretOne

    You can also use @PropertyName:

    Another option is to inject your variables in to your configuration files which gives you the ability to store things like database passwords and API keys in your vault:

    1. default:
    2. password: ${DB_PASSWORD}

    Vault retrieved values are always String, but you can use @ConfigurationProperties on a bean in conjunction with your application.yml file to provide properly typed configuration variables.

    So if you where to create secrets in your Oracle Cloud Vault like so:

    And then added the following to your application.yml file:

    application.yml

    1. secrets:
    2. one: ${SECRET_ONE}
    3. two: ${SECRET_TWO}
    4. three: ${SECRET_THREE}
    5. four: ${SECRET_FOUR}
    6. five: ${SECRET_FIVE}

    You could add a config bean like so:

    Config.java

    You could then inject and use this bean in your application with properly typed values.

    1. @Controller("/hello")
    2. public class HelloController {
    3. private Config config;
    4. public HelloController(
    5. Config config
    6. ) {
    7. @Get("/")
    8. public HttpStatus index() {
    9. return HttpStatus.OK;
    10. }
    11. @Get("/secret")
    12. public HttpResponse getSecret() {
    13. return HttpResponse.ok(config);
    14. }
    15. }

    Calling the /hello/secret endpoint would return:

    1. {
    2. "one": "Value One",
    3. "two": "value two",
    4. "three": true,
    5. "four": 42,
    6. "five": 3.16