Add support for endpoints.env.post.enabled=false
Separately disable the POST /env from the GET. Fixes gh-106.
This commit is contained in:
@@ -43,7 +43,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(EnvironmentEndpoint.class)
|
||||
@ConditionalOnProperty(value = "endpoints.env.enabled", matchIfMissing = true)
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean(RestartEndpoint.class)
|
||||
@AutoConfigureAfter({ WebMvcAutoConfiguration.class,
|
||||
@@ -55,6 +54,7 @@ public class LifecycleMvcEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(EnvironmentEndpoint.class)
|
||||
@ConditionalOnProperty(value = "endpoints.env.post.enabled", matchIfMissing = true)
|
||||
public EnvironmentManagerMvcEndpoint environmentManagerEndpoint(
|
||||
EnvironmentEndpoint delegate, EnvironmentManager environment) {
|
||||
return new EnvironmentManagerMvcEndpoint(delegate, environment);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
{"properties": [
|
||||
{
|
||||
"name": "endpoints.env.post.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable changing the Environment through a POST to /env.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "endpoints.refresh.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the /refresh endpoint to refresh configuration and re-initialize refresh scoped beans.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "endpoints.restart.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the /restart endpoint to restart the application context.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "endpoints.pause.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the /pause endpoint (to send Lifecycle.stop()).",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "endpoints.resume.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the /resume endpoint (to send Lifecycle.start()).",
|
||||
"defaultValue": true
|
||||
}
|
||||
]}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -19,6 +20,16 @@ import static org.junit.Assert.assertThat;
|
||||
*/
|
||||
public class LifecycleMvcAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void postEnvMvcEndpointDisabled() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
"server.port=0", "endpoints.env.post.enabled=false")) {
|
||||
assertThat(context
|
||||
.getBeanNamesForType(EnvironmentManagerMvcEndpoint.class).length,
|
||||
is(equalTo(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pauseMvcEndpointDisabled() {
|
||||
endpointDisabled("endpoints.pause.enabled", "pauseMvcEndpoint");
|
||||
@@ -35,16 +46,21 @@ public class LifecycleMvcAutoConfigurationTests {
|
||||
}
|
||||
|
||||
private void endpointDisabled(String enabledProp, String beanName) {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class, "server.port=0", enabledProp +"=false")) {
|
||||
EndpointMvcAdapter endpoint = context.getBean(beanName, EndpointMvcAdapter.class);
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
"server.port=0", enabledProp + "=false")) {
|
||||
EndpointMvcAdapter endpoint = context.getBean(beanName,
|
||||
EndpointMvcAdapter.class);
|
||||
Object result = endpoint.invoke();
|
||||
assertThat("result is wrong type", result, is(instanceOf(ResponseEntity.class)));
|
||||
ResponseEntity response = (ResponseEntity) result;
|
||||
assertThat("response code was wrong", response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
|
||||
assertThat("result is wrong type", result,
|
||||
is(instanceOf(ResponseEntity.class)));
|
||||
ResponseEntity<?> response = (ResponseEntity<?>) result;
|
||||
assertThat("response code was wrong", response.getStatusCode(),
|
||||
equalTo(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext getApplicationContext(Class<?> configuration, String... properties) {
|
||||
private static ConfigurableApplicationContext getApplicationContext(
|
||||
Class<?> configuration, String... properties) {
|
||||
return new SpringApplicationBuilder(configuration).properties(properties).run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user