Support priority ordering for VaultPropertySourceLocator.

We now support setting a priority for VaultPropertySourceLocator by configuring `spring.cloud.vault.config.order`. Lower values increase priority, higher values decrease priority. Applying a priority can be used to control VaultPropertySourceLocator precedence over other property sources.

Original pull request: gh-36.
This commit is contained in:
Jean-Philippe Bélanger
2016-08-09 11:07:51 -04:00
committed by Mark Paluch
parent caaaaaa056
commit bc02b8d3ff
3 changed files with 20 additions and 1 deletions

View File

@@ -180,6 +180,8 @@ spring.cloud.vault:
scheme: https
connection-timeout: 5000
read-timeout: 15000
config:
order: -10
----
* `host` sets the hostname of the Vault host. The host name will be used

View File

@@ -29,6 +29,7 @@ import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.PriorityOrdered;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -40,7 +41,7 @@ import static org.springframework.cloud.vault.config.SecureBackendAccessors.*;
* @author Spencer Gibb
* @author Mark Paluch
*/
class VaultPropertySourceLocator implements PropertySourceLocator {
class VaultPropertySourceLocator implements PropertySourceLocator, PriorityOrdered {
private final VaultConfigOperations operations;
private final VaultProperties properties;
@@ -85,6 +86,11 @@ class VaultPropertySourceLocator implements PropertySourceLocator {
return null;
}
@Override
public int getOrder() {
return properties.getConfig().getOrder();
}
private List<String> buildContexts(ConfigurableEnvironment env) {
String appName = env.getProperty("spring.application.name");

View File

@@ -78,6 +78,8 @@ public class VaultProperties {
private Ssl ssl = new Ssl();
private Config config = new Config();
/**
* Application name for AppId authentication.
*/
@@ -177,6 +179,15 @@ public class VaultProperties {
private String certAuthPath = "cert";
}
@Data
public static class Config {
/**
* Used to force a PropertySourceLocator ordering.
* This is useful to use Vault as an override on consul properties;
*/
private int order = 0;
}
public enum AuthenticationMethod {
TOKEN, APPID, AWS_EC2, CERT
}