Introduce path to SecretBackendMetadata.
This commit is contained in:
@@ -78,6 +78,23 @@ public class VaultConfigAwsBootstrapConfiguration {
|
||||
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return String.format("%s/creds/%s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getVariables() {
|
||||
|
||||
@@ -88,17 +105,6 @@ public class VaultConfigAwsBootstrapConfiguration {
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,18 @@ public class VaultConfigConsulBootstrapConfiguration {
|
||||
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return String.format("%s/creds/%s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getVariables() {
|
||||
|
||||
@@ -85,12 +97,6 @@ public class VaultConfigConsulBootstrapConfiguration {
|
||||
return variables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
|
||||
@@ -83,17 +83,14 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getVariables() {
|
||||
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
variables.put("backend", properties.getBackend());
|
||||
variables.put("key", String.format("creds/%s", properties.getRole()));
|
||||
return variables;
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
public String getPath() {
|
||||
return String.format("%s/creds/%s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@@ -101,6 +98,15 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getVariables() {
|
||||
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
variables.put("backend", properties.getBackend());
|
||||
variables.put("key", String.format("creds/%s", properties.getRole()));
|
||||
return variables;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,23 @@ public class VaultConfigRabbitMqBootstrapConfiguration {
|
||||
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return String.format("%s/creds/%s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getVariables() {
|
||||
|
||||
@@ -94,17 +111,6 @@ public class VaultConfigRabbitMqBootstrapConfiguration {
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return transformer;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,16 +58,20 @@ class GenericSecretBackendMetadata implements SecretBackendMetadata {
|
||||
* leading/trailing slashes, must not be empty or {@literal null}.
|
||||
* @return the {@link SecretBackendMetadata}
|
||||
*/
|
||||
public static SecretBackendMetadata create(final String secretBackendPath,
|
||||
final String key) {
|
||||
public static SecretBackendMetadata create(String secretBackendPath, String key) {
|
||||
return new GenericSecretBackendMetadata(secretBackendPath, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String getPath() {
|
||||
return String.format("%s/%s", secretBackendPath, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyTransformer getPropertyTransformer() {
|
||||
return PropertyTransformers.noop();
|
||||
|
||||
@@ -21,10 +21,13 @@ import org.springframework.vault.core.util.PropertyTransformer;
|
||||
|
||||
/**
|
||||
* Interface specifying the API to obtain URL variables and optionally a
|
||||
* {@link PropertyTransformer}. Typically used by {@link VaultPropertySource}.
|
||||
* {@link PropertyTransformer}. Typically used by {@link VaultPropertySource}. Supports
|
||||
* ordering of implementations.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @see PropertyTransformer
|
||||
* @see org.springframework.core.Ordered
|
||||
* @see org.springframework.core.annotation.Order
|
||||
*/
|
||||
public interface SecretBackendMetadata {
|
||||
|
||||
@@ -35,6 +38,14 @@ public interface SecretBackendMetadata {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Return the path of this secret backend.
|
||||
*
|
||||
* @return the path of this secret backend.
|
||||
* @since 1.1
|
||||
*/
|
||||
String getPath();
|
||||
|
||||
/**
|
||||
* Return a {@link PropertyTransformer} to post-process properties retrieved from
|
||||
* Vault.
|
||||
@@ -45,7 +56,8 @@ public interface SecretBackendMetadata {
|
||||
PropertyTransformer getPropertyTransformer();
|
||||
|
||||
/**
|
||||
* @return URL template variables.
|
||||
* @return URL template variables. URI variables should declare either {@code backend}
|
||||
* and {@code key} or {@code path} properties.
|
||||
*/
|
||||
Map<String, String> getVariables();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.config;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
@@ -26,7 +25,6 @@ import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.vault.core.util.PropertyTransformer;
|
||||
import org.springframework.vault.support.JsonMapFlattener;
|
||||
import org.springframework.vault.support.VaultResponse;
|
||||
import org.springframework.web.util.DefaultUriTemplateHandler;
|
||||
|
||||
/**
|
||||
* Central class to retrieve configuration from Vault.
|
||||
@@ -37,7 +35,6 @@ import org.springframework.web.util.DefaultUriTemplateHandler;
|
||||
@CommonsLog
|
||||
public class VaultConfigTemplate implements VaultConfigOperations {
|
||||
|
||||
private final DefaultUriTemplateHandler templateHandler = new DefaultUriTemplateHandler();
|
||||
private final VaultOperations vaultOperations;
|
||||
private final VaultProperties properties;
|
||||
|
||||
@@ -58,16 +55,16 @@ public class VaultConfigTemplate implements VaultConfigOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Secrets read(final SecretBackendMetadata secretBackendMetadata) {
|
||||
public Secrets read(SecretBackendMetadata secretBackendMetadata) {
|
||||
|
||||
Assert.notNull(secretBackendMetadata, "SecureBackendAccessor must not be null!");
|
||||
|
||||
URI uri = templateHandler.expand("{backend}/{key}",
|
||||
secretBackendMetadata.getVariables());
|
||||
log.info(String.format("Fetching config from Vault at: %s", uri));
|
||||
log.info(String.format("Fetching config from Vault at: %s",
|
||||
secretBackendMetadata.getPath()));
|
||||
|
||||
try {
|
||||
VaultResponse vaultResponse = vaultOperations.read(uri.toString());
|
||||
VaultResponse vaultResponse = vaultOperations
|
||||
.read(secretBackendMetadata.getPath());
|
||||
|
||||
if (vaultResponse == null) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user