Add sample for early decryption in bootstrap context

This commit is contained in:
Dave Syer
2015-05-19 09:27:45 +01:00
parent 27082db5d7
commit 401441594e
6 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sample-config-client-decrypt</artifactId>
<version>1.0.3.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-sample-config-client-decrypt</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.3.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -0,0 +1,30 @@
package demo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.client.ConfigClientProperties;
/**
* @author Dave Syer
*/
@SpringBootApplication
public class BootstrapDecryptionClientApplication implements CommandLineRunner {
private static Log logger = LogFactory.getLog(BootstrapDecryptionClientApplication.class);
@Autowired
private ConfigClientProperties config;
@Override
public void run(String... args) throws Exception {
logger.info("Config Server URI: " + config.getUri());
}
public static void main(String[] args) {
SpringApplication.run(BootstrapDecryptionClientApplication.class, args);
}
}

View File

@@ -0,0 +1,3 @@
spring:
application:
name: client

View File

@@ -0,0 +1,7 @@
debug: true
encrypt:
key: ${SECRET_KEY:foo} # normally this would be an environment variable
spring:
cloud:
config:
uri: '{cipher}10360db84ecacacf224df3334b02c85b4490b94ee6e6469bf86dd077aa6667f9b84ee3b60343f2c32d61dc14141fe5d0'

View File

@@ -0,0 +1,32 @@
package demo;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.config.client.ConfigClientProperties;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BootstrapDecryptionClientApplication.class)
@IntegrationTest
@DirtiesContext
public class BootstrapDecryptionClientApplicationTests {
@Autowired
private ConfigClientProperties config;
@Autowired
private ConfigServicePropertySourceLocator locator;
@Test
public void contextLoads() throws Exception {
assertEquals("http://localhost:8888", config.getUri());
}
}

View File

@@ -19,6 +19,7 @@
</organization>
<modules>
<module>config-client</module>
<module>config-client-decrypt</module>
<module>config-retry</module>
<module>configserver-eureka</module>
<module>eureka-first</module>