Skip to content

Commit 339d136

Browse files
author
Travis Tomsu
authored
Adds /resolvedEnv endpoint (#54)
Adds /resolvedEnv endpoint
1 parent 51d7722 commit 339d136

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

kork-web/kork-web.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
compile spinnaker.dependency('retrofit')
1010
compile spinnaker.dependency('guava')
1111

12+
compileOnly spinnaker.dependency('bootActuator')
1213

1314
spinnaker.group('spockBase')
1415
}

kork-web/src/main/groovy/com/netflix/spinnaker/config/TomcatConfiguration.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ import org.apache.catalina.connector.Connector
2222
import org.apache.coyote.http11.AbstractHttp11JsseProtocol
2323
import org.apache.coyote.http11.Http11NioProtocol
2424
import org.springframework.beans.factory.annotation.Value
25+
import org.springframework.boot.actuate.endpoint.ResolvedEnvironmentEndpoint
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
2627
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer
2728
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer
2829
import org.springframework.boot.context.embedded.Ssl
2930
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer
3031
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
32+
import org.springframework.boot.context.properties.EnableConfigurationProperties
3133
import org.springframework.context.annotation.Bean
3234
import org.springframework.context.annotation.Configuration
3335

3436
@Slf4j
3537
@Configuration
38+
@EnableConfigurationProperties(ResolvedEnvironmentEndpoint)
3639
class TomcatConfiguration {
3740
@Value('${default.legacyServerPort:-1}')
3841
int legacyServerPort
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2016 Google, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License")
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.endpoint
18+
19+
import org.springframework.boot.context.properties.ConfigurationProperties
20+
import org.springframework.core.env.ConfigurableEnvironment
21+
import org.springframework.core.env.EnumerablePropertySource
22+
import org.springframework.core.env.Environment
23+
import org.springframework.core.env.MutablePropertySources
24+
import org.springframework.core.env.StandardEnvironment
25+
26+
@ConfigurationProperties(prefix = "endpoints.resolvedEnv")
27+
class ResolvedEnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
28+
29+
private final Sanitizer sanitizer = new Sanitizer();
30+
31+
public ResolvedEnvironmentEndpoint() {
32+
super("resolvedEnv")
33+
}
34+
35+
@Override
36+
Map<String, Object> invoke() {
37+
Environment environment = getEnvironment()
38+
return getPropertyKeys().collectEntries {
39+
[(it): sanitizer.sanitize(it, environment.getProperty(it))]
40+
}
41+
}
42+
43+
/**
44+
* Impl partially copied from
45+
* {@link org.springframework.boot.actuate.endpoint.EnvironmentEndpoint}
46+
*
47+
* This gathers all defined properties in the system (no matter the source)
48+
*/
49+
private SortedSet<String> getPropertyKeys() {
50+
SortedSet<String> result = new TreeSet<String>()
51+
Environment environment = getEnvironment()
52+
53+
MutablePropertySources sources
54+
if (environment && environment instanceof ConfigurableEnvironment) {
55+
sources = ((ConfigurableEnvironment) environment).getPropertySources()
56+
} else {
57+
sources = new StandardEnvironment().getPropertySources()
58+
}
59+
60+
sources.each {
61+
if (it instanceof EnumerablePropertySource) {
62+
((EnumerablePropertySource) it).propertyNames.each {
63+
result.add(it)
64+
}
65+
}
66+
}
67+
68+
return result
69+
}
70+
71+
public void setKeysToSanitize(String... keysToSanitize) {
72+
this.sanitizer.setKeysToSanitize(keysToSanitize);
73+
}
74+
}

0 commit comments

Comments
 (0)