Include the environment default profiles in the env endpoint's response

See gh-39257
This commit is contained in:
Wzy19930507 2024-01-21 22:28:55 +08:00 committed by Moritz Halbritter
parent f36b69f961
commit dae3952144
3 changed files with 27 additions and 7 deletions

View File

@ -64,6 +64,9 @@ class EnvironmentEndpointDocumentationTests extends MockMvcEndpointDocumentation
private static final FieldDescriptor activeProfiles = fieldWithPath("activeProfiles")
.description("Names of the active profiles, if any.");
private static final FieldDescriptor defaultProfiles = fieldWithPath("defaultProfiles")
.description("Names of the default profiles, if any.");
private static final FieldDescriptor propertySources = fieldWithPath("propertySources")
.description("Property sources in order of precedence.");
@ -79,7 +82,7 @@ class EnvironmentEndpointDocumentationTests extends MockMvcEndpointDocumentation
replacePattern(Pattern.compile(
"org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/"), ""),
filterProperties()),
responseFields(activeProfiles, propertySources, propertySourceName,
responseFields(activeProfiles, defaultProfiles, propertySources, propertySourceName,
fieldWithPath("propertySources.[].properties")
.description("Properties in the property source keyed by property name."),
fieldWithPath("propertySources.[].properties.*.value")
@ -101,7 +104,7 @@ class EnvironmentEndpointDocumentationTests extends MockMvcEndpointDocumentation
.optional(),
fieldWithPath("property.source").description("Name of the source of the property."),
fieldWithPath("property.value").description("Value of the property."), activeProfiles,
propertySources, propertySourceName,
defaultProfiles, propertySources, propertySourceName,
fieldWithPath("propertySources.[].property")
.description("Property in the property source, if any.")
.optional(),

View File

@ -101,7 +101,8 @@ public class EnvironmentEndpoint {
propertyNamePredicate, showUnsanitized));
}
});
return new EnvironmentDescriptor(Arrays.asList(this.environment.getActiveProfiles()), propertySources);
return new EnvironmentDescriptor(Arrays.asList(this.environment.getActiveProfiles()),
Arrays.asList(this.environment.getDefaultProfiles()), propertySources);
}
@ReadOperation
@ -114,7 +115,7 @@ public class EnvironmentEndpoint {
Map<String, PropertyValueDescriptor> descriptors = getPropertySourceDescriptors(propertyName, showUnsanitized);
PropertySummaryDescriptor summary = getPropertySummaryDescriptor(descriptors);
return new EnvironmentEntryDescriptor(summary, Arrays.asList(this.environment.getActiveProfiles()),
toPropertySourceDescriptors(descriptors));
Arrays.asList(this.environment.getDefaultProfiles()), toPropertySourceDescriptors(descriptors));
}
private List<PropertySourceEntryDescriptor> toPropertySourceDescriptors(
@ -209,10 +210,14 @@ public class EnvironmentEndpoint {
private final List<String> activeProfiles;
private final List<String> defaultProfiles;
private final List<PropertySourceDescriptor> propertySources;
private EnvironmentDescriptor(List<String> activeProfiles, List<PropertySourceDescriptor> propertySources) {
private EnvironmentDescriptor(List<String> activeProfiles, List<String> defaultProfiles,
List<PropertySourceDescriptor> propertySources) {
this.activeProfiles = activeProfiles;
this.defaultProfiles = defaultProfiles;
this.propertySources = propertySources;
}
@ -220,6 +225,10 @@ public class EnvironmentEndpoint {
return this.activeProfiles;
}
public List<String> getDefaultProfiles() {
return this.defaultProfiles;
}
public List<PropertySourceDescriptor> getPropertySources() {
return this.propertySources;
}
@ -236,12 +245,15 @@ public class EnvironmentEndpoint {
private final List<String> activeProfiles;
private final List<String> defaultProfiles;
private final List<PropertySourceEntryDescriptor> propertySources;
EnvironmentEntryDescriptor(PropertySummaryDescriptor property, List<String> activeProfiles,
List<PropertySourceEntryDescriptor> propertySources) {
List<String> defaultProfiles, List<PropertySourceEntryDescriptor> propertySources) {
this.property = property;
this.activeProfiles = activeProfiles;
this.defaultProfiles = defaultProfiles;
this.propertySources = propertySources;
}
@ -253,6 +265,10 @@ public class EnvironmentEndpoint {
return this.activeProfiles;
}
public List<String> getDefaultProfiles() {
return this.defaultProfiles;
}
public List<PropertySourceEntryDescriptor> getPropertySources() {
return this.propertySources;
}

View File

@ -86,7 +86,8 @@ class EnvironmentEndpointWebExtensionTests {
private void verifyPrefixed(SecurityContext securityContext, boolean showUnsanitized) {
given(this.delegate.getEnvironmentEntryDescriptor("test", showUnsanitized))
.willReturn(new EnvironmentEntryDescriptor(null, Collections.emptyList(), Collections.emptyList()));
.willReturn(new EnvironmentEntryDescriptor(null, Collections.emptyList(), Collections.emptyList(),
Collections.emptyList()));
this.webExtension.environmentEntry(securityContext, "test");
then(this.delegate).should().getEnvironmentEntryDescriptor("test", showUnsanitized);
}