Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -79,7 +82,7 @@ void env() throws Exception {
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")
Expand All @@ -101,7 +104,7 @@ void singlePropertyFromEnv() throws Exception {
.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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private EnvironmentDescriptor getEnvironmentDescriptor(Predicate<String> propert
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
Expand All @@ -114,7 +115,7 @@ EnvironmentEntryDescriptor getEnvironmentEntryDescriptor(String propertyName, bo
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(
Expand Down Expand Up @@ -209,17 +210,25 @@ public static final class EnvironmentDescriptor implements OperationResponseBody

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;
}

public List<String> getActiveProfiles() {
return this.activeProfiles;
}

public List<String> getDefaultProfiles() {
return this.defaultProfiles;
}

public List<PropertySourceDescriptor> getPropertySources() {
return this.propertySources;
}
Expand All @@ -236,12 +245,15 @@ public static final class EnvironmentEntryDescriptor {

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;
}

Expand All @@ -253,6 +265,10 @@ public List<String> getActiveProfiles() {
return this.activeProfiles;
}

public List<String> getDefaultProfiles() {
return this.defaultProfiles;
}

public List<PropertySourceEntryDescriptor> getPropertySources() {
return this.propertySources;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void whenShowValuesIsWhenAuthorizedAndSecurityContextIsNotAuthorized() {

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);
}
Expand Down