Restore `endpoints.env.keys-to-sanitize` binding
Closes gh-10174
This commit is contained in:
parent
1cf7c32a1e
commit
e244d75bd2
|
|
@ -27,6 +27,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor;
|
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor;
|
||||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor.PropertyValueDescriptor;
|
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor.PropertyValueDescriptor;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.endpoint.Endpoint;
|
import org.springframework.boot.endpoint.Endpoint;
|
||||||
import org.springframework.boot.endpoint.ReadOperation;
|
import org.springframework.boot.endpoint.ReadOperation;
|
||||||
import org.springframework.boot.endpoint.Selector;
|
import org.springframework.boot.endpoint.Selector;
|
||||||
|
|
@ -54,6 +55,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
*/
|
*/
|
||||||
@Endpoint(id = "env")
|
@Endpoint(id = "env")
|
||||||
|
@ConfigurationProperties("endpoints.env")
|
||||||
public class EnvironmentEndpoint {
|
public class EnvironmentEndpoint {
|
||||||
|
|
||||||
private final Sanitizer sanitizer = new Sanitizer();
|
private final Sanitizer sanitizer = new Sanitizer();
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,13 @@ import org.junit.Test;
|
||||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor;
|
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor;
|
||||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor;
|
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor;
|
||||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor.PropertyValueDescriptor;
|
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint.EnvironmentDescriptor.PropertySourceDescriptor.PropertyValueDescriptor;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.CompositePropertySource;
|
import org.springframework.core.env.CompositePropertySource;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.core.env.MutablePropertySources;
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
|
@ -147,6 +152,23 @@ public class EnvironmentEndpointTests {
|
||||||
clearSystemProperties("dbPassword", "apiKey");
|
clearSystemProperties("dbPassword", "apiKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void keysToSanitizeCanBeConfiguredViaTheEnvironment() throws Exception {
|
||||||
|
ApplicationContextRunner tester = new ApplicationContextRunner()
|
||||||
|
.withSystemProperties("dbPassword=123456", "apiKey=123456")
|
||||||
|
.withPropertyValues("endpoints.env.keys-to-sanitize=.*pass.*")
|
||||||
|
.withUserConfiguration(Config.class);
|
||||||
|
tester.run((context) -> {
|
||||||
|
EnvironmentEndpoint endpoint = context
|
||||||
|
.getBean(EnvironmentEndpoint.class);
|
||||||
|
EnvironmentDescriptor env = endpoint.environment(null);
|
||||||
|
Map<String, PropertyValueDescriptor> systemProperties = getSource(
|
||||||
|
"systemProperties", env).getProperties();
|
||||||
|
assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("******");
|
||||||
|
assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("123456");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertyWithPlaceholderResolved() {
|
public void propertyWithPlaceholderResolved() {
|
||||||
StandardEnvironment environment = new StandardEnvironment();
|
StandardEnvironment environment = new StandardEnvironment();
|
||||||
|
|
@ -220,4 +242,17 @@ public class EnvironmentEndpointTests {
|
||||||
.filter((source) -> name.equals(source.getName())).findFirst().get();
|
.filter((source) -> name.equals(source.getName())).findFirst().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public EnvironmentEndpoint environmentEndpoint(Environment environment) {
|
||||||
|
return new EnvironmentEndpoint(environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue