Merge branch '1.3.x'
This commit is contained in:
@@ -95,7 +95,9 @@ public class ConsulPropertySourceLocatorFilesTests {
|
||||
@After
|
||||
public void teardown() {
|
||||
this.client.deleteKVValues(PREFIX);
|
||||
this.context.close();
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import com.ecwid.consul.transport.TLSConfig;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
@@ -57,6 +59,17 @@ public class ConsulAutoConfiguration {
|
||||
? consulProperties.getScheme() + "://" + consulProperties.getHost()
|
||||
: consulProperties.getHost();
|
||||
|
||||
if (consulProperties.getTls() != null) {
|
||||
ConsulProperties.TLSConfig tls = consulProperties.getTls();
|
||||
TLSConfig tlsConfig = new TLSConfig(
|
||||
tls.getKeyStoreInstanceType(),
|
||||
tls.getCertificatePath(),
|
||||
tls.getCertificatePassword(),
|
||||
tls.getKeyStorePath(),
|
||||
tls.getKeyStorePassword()
|
||||
);
|
||||
return new ConsulClient(agentHost, agentPort, tlsConfig);
|
||||
}
|
||||
return new ConsulClient(agentHost, agentPort);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ package org.springframework.cloud.consul;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import com.ecwid.consul.transport.TLSConfig.KeyStoreInstanceType;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,10 @@ public class ConsulProperties {
|
||||
/** Is spring cloud consul enabled */
|
||||
private boolean enabled = true;
|
||||
|
||||
/** configuration for TLS */
|
||||
private TLSConfig tls;
|
||||
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
@@ -73,13 +80,101 @@ public class ConsulProperties {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public TLSConfig getTls() {
|
||||
return tls;
|
||||
}
|
||||
|
||||
public void setTls(TLSConfig tls) {
|
||||
this.tls = tls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConsulProperties{" +
|
||||
"host='" + host + '\'' +
|
||||
", port=" + port +
|
||||
", scheme=" + scheme +
|
||||
", tls=" + tls +
|
||||
", enabled=" + enabled +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class TLSConfig {
|
||||
/** Type of key framework to use. */
|
||||
private KeyStoreInstanceType keyStoreInstanceType;
|
||||
|
||||
/** Path to an external keystore */
|
||||
private String keyStorePath;
|
||||
|
||||
/** Password to an external keystore */
|
||||
private String keyStorePassword;
|
||||
|
||||
/**File path to the certificate. */
|
||||
private String certificatePath;
|
||||
|
||||
/** Password to open the certificate. */
|
||||
private String certificatePassword;
|
||||
|
||||
public TLSConfig() {
|
||||
}
|
||||
|
||||
public TLSConfig(KeyStoreInstanceType keyStoreInstanceType, String keyStorePath, String keyStorePassword, String certificatePath, String certificatePassword) {
|
||||
this.keyStoreInstanceType = keyStoreInstanceType;
|
||||
this.keyStorePath = keyStorePath;
|
||||
this.keyStorePassword = keyStorePassword;
|
||||
this.certificatePath = certificatePath;
|
||||
this.certificatePassword = certificatePassword;
|
||||
}
|
||||
|
||||
public KeyStoreInstanceType getKeyStoreInstanceType() {
|
||||
return keyStoreInstanceType;
|
||||
}
|
||||
|
||||
public void setKeyStoreInstanceType(KeyStoreInstanceType keyStoreInstanceType) {
|
||||
this.keyStoreInstanceType = keyStoreInstanceType;
|
||||
}
|
||||
|
||||
public String getKeyStorePath() {
|
||||
return keyStorePath;
|
||||
}
|
||||
|
||||
public void setKeyStorePath(String keyStorePath) {
|
||||
this.keyStorePath = keyStorePath;
|
||||
}
|
||||
|
||||
public String getKeyStorePassword() {
|
||||
return keyStorePassword;
|
||||
}
|
||||
|
||||
public void setKeyStorePassword(String keyStorePassword) {
|
||||
this.keyStorePassword = keyStorePassword;
|
||||
}
|
||||
|
||||
public String getCertificatePath() {
|
||||
return certificatePath;
|
||||
}
|
||||
|
||||
public void setCertificatePath(String certificatePath) {
|
||||
this.certificatePath = certificatePath;
|
||||
}
|
||||
|
||||
public String getCertificatePassword() {
|
||||
return certificatePassword;
|
||||
}
|
||||
|
||||
public void setCertificatePassword(String certificatePassword) {
|
||||
this.certificatePassword = certificatePassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("keyStoreInstanceType", keyStoreInstanceType)
|
||||
.append("keyStorePath", keyStorePath)
|
||||
.append("keyStorePassword", keyStorePassword)
|
||||
.append("certificatePath", certificatePath)
|
||||
.append("certificatePassword", certificatePassword)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.springframework.cloud.consul;
|
||||
|
||||
import com.ecwid.consul.transport.DefaultHttpsTransport;
|
||||
import com.ecwid.consul.transport.HttpTransport;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.ConsulRawClient;
|
||||
import com.ecwid.consul.v1.catalog.CatalogConsulClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = {"spring.cloud.consul.tls.key-store-instance-type=JKS",
|
||||
"spring.cloud.consul.tls.key-store-path=src/test/resources/server.jks",
|
||||
"spring.cloud.consul.tls.key-store-password=letmein",
|
||||
"spring.cloud.consul.tls.certificate-path=src/test/resources/trustStore.jks",
|
||||
"spring.cloud.consul.tls.certificate-password=change_me", })
|
||||
public class ConsulAutoConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private ConsulClient consulClient;
|
||||
|
||||
@Test
|
||||
public void tlsConfigured() {
|
||||
CatalogConsulClient client = (CatalogConsulClient) ReflectionTestUtils.getField(consulClient, "catalogClient");
|
||||
ConsulRawClient rawClient = (ConsulRawClient) ReflectionTestUtils.getField(client, "rawClient");
|
||||
HttpTransport httpTransport = (HttpTransport) ReflectionTestUtils.getField(rawClient, "httpTransport");
|
||||
assertThat(httpTransport).isInstanceOf(DefaultHttpsTransport.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfig {}
|
||||
}
|
||||
BIN
spring-cloud-consul-core/src/test/resources/server.jks
Normal file
BIN
spring-cloud-consul-core/src/test/resources/server.jks
Normal file
Binary file not shown.
BIN
spring-cloud-consul-core/src/test/resources/trustStore.jks
Normal file
BIN
spring-cloud-consul-core/src/test/resources/trustStore.jks
Normal file
Binary file not shown.
Reference in New Issue
Block a user