Disable the env info contributor by default
Closes gh-28311
This commit is contained in:
@@ -55,7 +55,7 @@ public class InfoContributorAutoConfiguration {
|
|||||||
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
|
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnEnabledInfoContributor("env")
|
@ConditionalOnEnabledInfoContributor(value = "env", fallback = InfoContributorFallback.DISABLE)
|
||||||
@Order(DEFAULT_ORDER)
|
@Order(DEFAULT_ORDER)
|
||||||
public EnvironmentInfoContributor envInfoContributor(ConfigurableEnvironment environment) {
|
public EnvironmentInfoContributor envInfoContributor(ConfigurableEnvironment environment) {
|
||||||
return new EnvironmentInfoContributor(environment);
|
return new EnvironmentInfoContributor(environment);
|
||||||
|
|||||||
@@ -49,22 +49,28 @@ class InfoContributorAutoConfigurationTests {
|
|||||||
.withConfiguration(AutoConfigurations.of(InfoContributorAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(InfoContributorAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void disableEnvContributor() {
|
void envContributor() {
|
||||||
this.contextRunner.withPropertyValues("management.info.env.enabled=false")
|
this.contextRunner.withPropertyValues("management.info.env.enabled=true")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(EnvironmentInfoContributor.class));
|
.run((context) -> assertThat(context).hasSingleBean(EnvironmentInfoContributor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void defaultInfoContributorsEnabled() {
|
void defaultInfoContributorsEnabled() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class));
|
||||||
assertThat(context).hasSingleBean(EnvironmentInfoContributor.class);
|
|
||||||
assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void defaultInfoContributorsDisabled() {
|
void defaultInfoContributorsEnabledWithPrerequisitesInPlace() {
|
||||||
this.contextRunner.withPropertyValues("management.info.defaults.enabled=false")
|
this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class)
|
||||||
|
.run((context) -> assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(2)
|
||||||
|
.satisfies((contributors) -> assertThat(contributors.values())
|
||||||
|
.hasOnlyElementsOfTypes(BuildInfoContributor.class, GitInfoContributor.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void defaultInfoContributorsDisabledWithPrerequisitesInPlace() {
|
||||||
|
this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class)
|
||||||
|
.withPropertyValues("management.info.defaults.enabled=false")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class));
|
.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1174,10 +1174,10 @@ When appropriate, Spring auto-configures the following `InfoContributor` beans:
|
|||||||
Whether or not an individual contributor is enabled is controlled by its `management.info.<id>.enabled` property.
|
Whether or not an individual contributor is enabled is controlled by its `management.info.<id>.enabled` property.
|
||||||
Different contributors have different defaults for this property, depending on their prerequisites and the nature of the information that they expose.
|
Different contributors have different defaults for this property, depending on their prerequisites and the nature of the information that they expose.
|
||||||
|
|
||||||
With no prequisites to indicate that it should be enabled, the `java` contributor is disabled by default.
|
With no prequisites to indicate that they should be enabled, the `env` and `java` contributors are disabled by default.
|
||||||
You can enable it by setting the configprop:management.info.java.enabled[] property to `true`.
|
You can enable them by setting the configprop:management.info.env.enabled[] or configprop:management.info.java.enabled[] properties to `true`.
|
||||||
|
|
||||||
The `env`, `git`, and `build` info contributors are enabled by default.
|
The `build` and `git` info contributors are enabled by default.
|
||||||
Each can be disabled by setting its `management.info.<id>.enabled` property to `false`.
|
Each can be disabled by setting its `management.info.<id>.enabled` property to `false`.
|
||||||
Alternatively, to disable every contributor that is usually enabled by default, set the configprop:management.info.defaults.enabled[] property to `false`.
|
Alternatively, to disable every contributor that is usually enabled by default, set the configprop:management.info.defaults.enabled[] property to `false`.
|
||||||
|
|
||||||
@@ -1185,7 +1185,7 @@ Alternatively, to disable every contributor that is usually enabled by default,
|
|||||||
|
|
||||||
[[actuator.endpoints.info.custom-application-information]]
|
[[actuator.endpoints.info.custom-application-information]]
|
||||||
==== Custom Application Information
|
==== Custom Application Information
|
||||||
You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
|
When the `env` contributor is enabled, you can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
|
||||||
All `Environment` properties under the `info` key are automatically exposed.
|
All `Environment` properties under the `info` key are automatically exposed.
|
||||||
For example, you could add the following settings to your `application.properties` file:
|
For example, you could add the following settings to your `application.properties` file:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user