Change method name from getUri() to getRawUri()

Users would have seen DOWN status in a health indicator whenever
the config server was secure.

Fixes gh-69
This commit is contained in:
Dave Syer
2015-01-23 17:39:14 +00:00
parent 8c6740ab71
commit e5e4cb0348
5 changed files with 21 additions and 18 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.autoconfigure;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -27,7 +26,6 @@ import org.springframework.cloud.config.client.ConfigServicePropertySourceLocato
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
/**
@@ -59,12 +57,9 @@ public class ConfigClientAutoConfiguration {
@ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true)
protected static class ConfigServerHealthIndicatorConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@Bean
public ConfigServerHealthIndicator configServerHealthIndicator(ConfigServicePropertySourceLocator locator) {
return new ConfigServerHealthIndicator(environment, locator);
return new ConfigServerHealthIndicator(locator);
}
}

View File

@@ -45,7 +45,7 @@ public class ConfigClientProperties {
*/
private String profile = "default";
@Value("${spring.application.name:'application'}")
@Value("${spring.application.name:application}")
private String name;
private String label = "master";
@@ -79,9 +79,13 @@ public class ConfigClientProperties {
this.enabled = enabled;
}
public String getUri() {
public String getRawUri() {
return extractCredentials()[2];
}
public String getUri() {
return uri;
}
public void setUri(String url) {
this.uri = url;
@@ -219,7 +223,7 @@ public class ConfigClientProperties {
BeanUtils.copyProperties(this, override);
override.setName(environment.resolvePlaceholders("${"
+ ConfigClientProperties.PREFIX
+ ".name:${spring.application.name:'application'}}"));
+ ".name:${spring.application.name:application}}"));
if (environment.containsProperty(ConfigClientProperties.PREFIX + ".profile")) {
override.setProfile(environment.getProperty(ConfigClientProperties.PREFIX + ".profile"));
}

View File

@@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
@@ -14,18 +15,19 @@ import org.springframework.core.env.PropertySource;
*/
public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
private Environment env;
private ConfigServicePropertySourceLocator locator;
private Environment env;
public ConfigServerHealthIndicator(Environment env, ConfigServicePropertySourceLocator locator) {
this.env = env;
public ConfigServerHealthIndicator(ConfigServicePropertySourceLocator locator) {
this.env = new AbstractEnvironment() {
};
this.locator = locator;
}
@Override
protected void doHealthCheck(Builder builder) throws Exception {
try {
PropertySource<?> propertySource = locator.locate(env);
PropertySource<?> propertySource = locator.locate(this.env);
builder.up();
if (propertySource instanceof CompositePropertySource) {
List<String> sources = new ArrayList<>();
@@ -33,8 +35,10 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
sources.add(ps.getName());
}
builder.withDetail("propertySources", sources);
} else {
} else if (propertySource!=null) {
builder.withDetail("propertySources", propertySource.toString());
} else {
builder.down().withDetail("error", "no property sources located");
}
} catch (Exception e) {
builder.down(e);

View File

@@ -66,7 +66,7 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
String errorBody = null;
try {
Environment result = restTemplate.exchange(
client.getUri() + "/{name}/{profile}/{label}", HttpMethod.GET,
client.getRawUri() + "/{name}/{profile}/{label}", HttpMethod.GET,
new HttpEntity<Void>((Void) null), Environment.class,
client.getName(), client.getProfile(), client.getLabel()).getBody();
for (PropertySource source : result.getPropertySources()) {

View File

@@ -35,7 +35,7 @@ public class ConfigClientPropertiesTests {
public void vanilla() {
locator.setUri("http://localhost:9999");
locator.setPassword("secret");
assertEquals("http://localhost:9999", locator.getUri());
assertEquals("http://localhost:9999", locator.getRawUri());
assertEquals("user", locator.getUsername());
assertEquals("secret", locator.getPassword());
}
@@ -43,7 +43,7 @@ public class ConfigClientPropertiesTests {
@Test
public void uriCreds() {
locator.setUri("http://foo:bar@localhost:9999");
assertEquals("http://localhost:9999", locator.getUri());
assertEquals("http://localhost:9999", locator.getRawUri());
assertEquals("foo", locator.getUsername());
assertEquals("bar", locator.getPassword());
}
@@ -52,7 +52,7 @@ public class ConfigClientPropertiesTests {
public void explicitPassword() {
locator.setUri("http://foo:bar@localhost:9999");
locator.setPassword("secret");
assertEquals("http://localhost:9999", locator.getUri());
assertEquals("http://localhost:9999", locator.getRawUri());
assertEquals("foo", locator.getUsername());
assertEquals("secret", locator.getPassword());
}