Skip to content

Commit dae3952

Browse files
Wzy19930507mhalbritter
authored andcommitted
Include the environment default profiles in the env endpoint's response
See gh-39257
1 parent f36b69f commit dae3952

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/EnvironmentEndpointDocumentationTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class EnvironmentEndpointDocumentationTests extends MockMvcEndpointDocumentation
6464
private static final FieldDescriptor activeProfiles = fieldWithPath("activeProfiles")
6565
.description("Names of the active profiles, if any.");
6666

67+
private static final FieldDescriptor defaultProfiles = fieldWithPath("defaultProfiles")
68+
.description("Names of the default profiles, if any.");
69+
6770
private static final FieldDescriptor propertySources = fieldWithPath("propertySources")
6871
.description("Property sources in order of precedence.");
6972

@@ -79,7 +82,7 @@ void env() throws Exception {
7982
replacePattern(Pattern.compile(
8083
"org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/"), ""),
8184
filterProperties()),
82-
responseFields(activeProfiles, propertySources, propertySourceName,
85+
responseFields(activeProfiles, defaultProfiles, propertySources, propertySourceName,
8386
fieldWithPath("propertySources.[].properties")
8487
.description("Properties in the property source keyed by property name."),
8588
fieldWithPath("propertySources.[].properties.*.value")
@@ -101,7 +104,7 @@ void singlePropertyFromEnv() throws Exception {
101104
.optional(),
102105
fieldWithPath("property.source").description("Name of the source of the property."),
103106
fieldWithPath("property.value").description("Value of the property."), activeProfiles,
104-
propertySources, propertySourceName,
107+
defaultProfiles, propertySources, propertySourceName,
105108
fieldWithPath("propertySources.[].property")
106109
.description("Property in the property source, if any.")
107110
.optional(),

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private EnvironmentDescriptor getEnvironmentDescriptor(Predicate<String> propert
101101
propertyNamePredicate, showUnsanitized));
102102
}
103103
});
104-
return new EnvironmentDescriptor(Arrays.asList(this.environment.getActiveProfiles()), propertySources);
104+
return new EnvironmentDescriptor(Arrays.asList(this.environment.getActiveProfiles()),
105+
Arrays.asList(this.environment.getDefaultProfiles()), propertySources);
105106
}
106107

107108
@ReadOperation
@@ -114,7 +115,7 @@ EnvironmentEntryDescriptor getEnvironmentEntryDescriptor(String propertyName, bo
114115
Map<String, PropertyValueDescriptor> descriptors = getPropertySourceDescriptors(propertyName, showUnsanitized);
115116
PropertySummaryDescriptor summary = getPropertySummaryDescriptor(descriptors);
116117
return new EnvironmentEntryDescriptor(summary, Arrays.asList(this.environment.getActiveProfiles()),
117-
toPropertySourceDescriptors(descriptors));
118+
Arrays.asList(this.environment.getDefaultProfiles()), toPropertySourceDescriptors(descriptors));
118119
}
119120

120121
private List<PropertySourceEntryDescriptor> toPropertySourceDescriptors(
@@ -209,17 +210,25 @@ public static final class EnvironmentDescriptor implements OperationResponseBody
209210

210211
private final List<String> activeProfiles;
211212

213+
private final List<String> defaultProfiles;
214+
212215
private final List<PropertySourceDescriptor> propertySources;
213216

214-
private EnvironmentDescriptor(List<String> activeProfiles, List<PropertySourceDescriptor> propertySources) {
217+
private EnvironmentDescriptor(List<String> activeProfiles, List<String> defaultProfiles,
218+
List<PropertySourceDescriptor> propertySources) {
215219
this.activeProfiles = activeProfiles;
220+
this.defaultProfiles = defaultProfiles;
216221
this.propertySources = propertySources;
217222
}
218223

219224
public List<String> getActiveProfiles() {
220225
return this.activeProfiles;
221226
}
222227

228+
public List<String> getDefaultProfiles() {
229+
return this.defaultProfiles;
230+
}
231+
223232
public List<PropertySourceDescriptor> getPropertySources() {
224233
return this.propertySources;
225234
}
@@ -236,12 +245,15 @@ public static final class EnvironmentEntryDescriptor {
236245

237246
private final List<String> activeProfiles;
238247

248+
private final List<String> defaultProfiles;
249+
239250
private final List<PropertySourceEntryDescriptor> propertySources;
240251

241252
EnvironmentEntryDescriptor(PropertySummaryDescriptor property, List<String> activeProfiles,
242-
List<PropertySourceEntryDescriptor> propertySources) {
253+
List<String> defaultProfiles, List<PropertySourceEntryDescriptor> propertySources) {
243254
this.property = property;
244255
this.activeProfiles = activeProfiles;
256+
this.defaultProfiles = defaultProfiles;
245257
this.propertySources = propertySources;
246258
}
247259

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

268+
public List<String> getDefaultProfiles() {
269+
return this.defaultProfiles;
270+
}
271+
256272
public List<PropertySourceEntryDescriptor> getPropertySources() {
257273
return this.propertySources;
258274
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointWebExtensionTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ void whenShowValuesIsWhenAuthorizedAndSecurityContextIsNotAuthorized() {
8686

8787
private void verifyPrefixed(SecurityContext securityContext, boolean showUnsanitized) {
8888
given(this.delegate.getEnvironmentEntryDescriptor("test", showUnsanitized))
89-
.willReturn(new EnvironmentEntryDescriptor(null, Collections.emptyList(), Collections.emptyList()));
89+
.willReturn(new EnvironmentEntryDescriptor(null, Collections.emptyList(), Collections.emptyList(),
90+
Collections.emptyList()));
9091
this.webExtension.environmentEntry(securityContext, "test");
9192
then(this.delegate).should().getEnvironmentEntryDescriptor("test", showUnsanitized);
9293
}

0 commit comments

Comments
 (0)