Skip to content

Commit

Permalink
Reduce noise in /end actuator docs
Browse files Browse the repository at this point in the history
Update the `/env` sample used in the actuator docs to use only a limited
set of keys.

Fixes spring-projectsgh-5849
  • Loading branch information
philwebb committed Jul 19, 2016
1 parent 1080b99 commit 05cde78
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.actuate.hypermedia;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
* {@link EnvironmentEndpoint} with reduced output to look better in the documentation.
*
* @author Phillip Webb
*/
public class LimitedEnvironmentEndpoint extends EnvironmentEndpoint {

private static final MultiValueMap<String, String> INCLUDES;

static {
Map<String, List<String>> includes = new LinkedHashMap<String, List<String>>();
List<String> systemProperties = new ArrayList<String>();
systemProperties.add("java.runtime.name");
systemProperties.add("sun.boot.library.path");
systemProperties.add("java.vendor.url");
systemProperties.add("path.separator");
systemProperties.add("sun.java.launcher");
systemProperties.add("java.runtime.version");
systemProperties.add("os.arch");
systemProperties.add("line.separator");
systemProperties.add("os.name");
systemProperties.add("user.timezone");
systemProperties.add("file.encoding");
systemProperties.add("java.vm.specification.version");
systemProperties.add("sun.java.command");
systemProperties.add("sun.arch.data.model");
systemProperties.add("user.language");
systemProperties.add("awt.toolkit");
systemProperties.add("java.awt.headless");
systemProperties.add("java.vendor");
systemProperties.add("file.separator");
includes.put("systemProperties", systemProperties);
List<String> systemEnvironment = new ArrayList<String>();
systemEnvironment.add("SHELL");
systemEnvironment.add("TMPDIR");
systemEnvironment.add("DISPLAY");
systemEnvironment.add("LOGNAME");
includes.put("systemEnvironment", systemEnvironment);
INCLUDES = new LinkedMultiValueMap<>(Collections.unmodifiableMap(includes));
}

@Override
public Object sanitize(String name, Object object) {
System.out.println(name);
if (name.equals("gopherProxySet")) {
return object;
}
return null;
}

@Override
protected Map<String, Object> postProcessSourceProperties(String sourceName,
Map<String, Object> properties) {
List<String> sourceIncludes = INCLUDES.get(sourceName);
if (sourceIncludes != null) {
Set<Entry<String, Object>> entries = properties.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
while (iterator.hasNext()) {
if (!sourceIncludes.contains(iterator.next().getKey())) {
iterator.remove();
}
}

}
return properties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import groovy.text.TemplateEngine;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
Expand All @@ -36,6 +37,11 @@ public TemplateEngine groovyTemplateEngine() {
return new GStringTemplateEngine();
}

@Bean
public EnvironmentEndpoint environmentEndpoint() {
return new LimitedEnvironmentEndpoint();
}

public static void main(String[] args) {
SpringApplication.run(SpringBootHypermediaApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public Map<String, Object> invoke() {
String sourceName = entry.getKey();
if (source instanceof EnumerablePropertySource) {
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
Map<String, Object> map = new LinkedHashMap<String, Object>();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
for (String name : enumerable.getPropertyNames()) {
map.put(name, sanitize(name, enumerable.getProperty(name)));
properties.put(name, sanitize(name, enumerable.getProperty(name)));
}
properties = postProcessSourceProperties(sourceName, properties);
if (properties != null) {
result.put(sourceName, properties);
}
result.put(sourceName, map);
}
}
return result;
Expand Down Expand Up @@ -104,4 +107,17 @@ public Object sanitize(String name, Object object) {
return this.sanitizer.sanitize(name, object);
}

/**
* Apply any post processing to source data before it is added.
* @param sourceName the source name
* @param properties the properties
* @return the post-processed properties or {@code null} if the source should not be
* added
* @since 1.4.0
*/
protected Map<String, Object> postProcessSourceProperties(String sourceName,
Map<String, Object> properties) {
return properties;
}

}

0 comments on commit 05cde78

Please sign in to comment.