Sophia Price
Sophia Price

Reputation: 958

Spring Cloud Vault use local env variable when not in production for API Key

I am using Spring Cloud Vault to store an API Key in production.

From reading the spring.io blog it appears I can use

 @Value("${apiKey}")
 String apiKey;

to access that key in vault.

This is fine when in production, but is there a way that I can set a default value/ some other way of setting up an apiKey that can be used locally for development? (preferably outside of vault if possible)

Upvotes: 0

Views: 1435

Answers (2)

M. Deinum
M. Deinum

Reputation: 124441

As explained in the Spring Boot Reference Guide several sources of configuration properties are consulted. It doesn't really matter where the value for apiKey comes from.

You have at least 3 options:

  1. Set it in the environment,
  2. Pass it as an argument with --apiKey=<your-api-key> when starting the application locally
  3. simply place it in an application.[properties|yaml] used for local development.

Either way the apiKey property will be resolved locally without having to use the vault.

Upvotes: 2

Abdelghani Roussi
Abdelghani Roussi

Reputation: 2817

You can set a default value (if the apiKey is not found ) like this :

@Value("${apiKey:MY_KEY_HERE}")

where MY_KEY_HERE is the default value.

Upvotes: 2

Related Questions