From eec2262db166bccfd85861db5ca60c81294b6a08 Mon Sep 17 00:00:00 2001 From: tomcruise81 Date: Fri, 27 Oct 2017 12:34:18 -0400 Subject: [PATCH 1/4] Documented (_) support for the {application} parameter --- .../main/asciidoc/spring-cloud-config.adoc | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 3b3c5412..daa963f5 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -153,9 +153,10 @@ git branch or tag name contains a slash ("/") then the label in the HTTP URL should be specified with the special string "(\_)" instead (to avoid ambiguity with other URL paths). For example, if the label is `foo/bar`, replacing the slash would result in a label that looks like -`foo(_)bar`. Be careful with the brackets in -the URL if you are using a command line client like curl (e.g. escape -them from the shell with quotes ''). +`foo(_)bar`. The inclusion of the special string "(\_)" can also be +applied to the `{application}` parameter. Be careful with the brackets +in the URL if you are using a command line client like curl (e.g. +escape them from the shell with quotes ''). ===== Placeholders in Git URI @@ -178,6 +179,23 @@ spring: or a "one repo per profile" policy using a similar pattern but with `{profile}`. +Additionally, using the special string "(\_)" within your +`{application}` parameters can enable support for multiple +organizations (for example): + +[source,yaml] +---- +spring: + cloud: + config: + server: + git: + uri: https://github.com/{application} +---- + +where `{application}` is provided at request time in the format +"organization(\_)application". + ===== Pattern Matching and Multiple Repositories There is also support for more complex requirements with pattern From 349f365dbd250cb671ae79d9c49365d33213a606 Mon Sep 17 00:00:00 2001 From: Stefan Erichsen Date: Thu, 2 Nov 2017 12:52:39 +0100 Subject: [PATCH 2/4] encrypt.* config needs to be in bootstrap.yml For some reason starting with Dalston.SR2, the encrypt.* properties can no longer be defined in application.properties but need to be set in bootstrap.properties. The documentation now reflects this. --- docs/src/main/asciidoc/spring-cloud-config.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 3b3c5412..7cad0920 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -969,7 +969,7 @@ The key argument is mandatory (despite having a `--` prefix). The Config Server can use a symmetric (shared) key or an asymmetric one (RSA key pair). The asymmetric choice is superior in terms of security, but it is often more convenient to use a symmetric key since -it is just a single property value to configure. +it is just a single property value to configure in the `bootstrap.properties`. To configure a symmetric key you just need to set `encrypt.key` to a secret String (or use an enviroment variable `ENCRYPT_KEY` to keep it @@ -1006,7 +1006,7 @@ $ keytool -genkeypair -alias mytestkey -keyalg RSA \ ---- Put the `server.jks` file in the classpath (for instance) and then in -your `application.yml` for the Config Server: +your `bootstrap.yml` for the Config Server: [source,yaml] ---- From 3157bd4e2c527f0a7c9046af4c2b13ef2d1b9317 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig Date: Mon, 6 Nov 2017 19:03:58 +0900 Subject: [PATCH 3/4] Make CompositeConfiguration conditional on missing bean Previously, `CompositeConfiguration` (which is imported by `ConfigServerAutoConfiguration`) would unconditionally create a `CompositeEnvironmentRepository` bean marked as `@Primary`. This makes it difficult for users, in their code, to provide their own `CompositeEnvironmentRepository` bean to be used in various places. This adds a `ConditionalOnMissingBean` condition to the `Configuration` to make it easy to provide a primary `CompositeEnvironmentRepository` in user code. --- .../server/config/CompositeConfiguration.java | 1 + .../CompositeEnvironmentRepositoryTests.java | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/CompositeConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/CompositeConfiguration.java index c4792adb..8b06bb87 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/CompositeConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/CompositeConfiguration.java @@ -32,6 +32,7 @@ import org.springframework.context.annotation.Primary; * @author Ryan Baxter */ @Configuration +@ConditionalOnMissingBean(CompositeEnvironmentRepository.class) public class CompositeConfiguration { private List environmentRepos = new ArrayList<>(); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java index 138f9f56..c455b62f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java @@ -16,10 +16,17 @@ package org.springframework.cloud.config.server.environment; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.Test; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.config.CompositeConfiguration; +import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.core.Ordered; import static org.junit.Assert.assertEquals; @@ -31,7 +38,7 @@ import static org.mockito.Mockito.mock; */ public class CompositeEnvironmentRepositoryTests { - private class TestOrderedEnvironmentRepository implements EnvironmentRepository, SearchPathLocator, Ordered { + private static class TestOrderedEnvironmentRepository implements EnvironmentRepository, SearchPathLocator, Ordered { private Environment env; private Locations locations; @@ -144,4 +151,21 @@ public class CompositeEnvironmentRepositoryTests { assertEquals(null, multiEnv.getState()); } + + @Test + public void overridingCompositeEnvRepo_contextLoads() { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { + context.register(OverrideCompositeConfig.class, CompositeConfiguration.class, ConfigServerHealthIndicator.class); + context.refresh(); + } + } + + @Configuration + static class OverrideCompositeConfig { + @Bean + @Primary + CompositeEnvironmentRepository customCompositeEnvironmentRepository() { + return new CompositeEnvironmentRepository(Arrays.asList(new TestOrderedEnvironmentRepository(1, new Environment("app", "dev"), null))); + } + } } From b278e531c9c03c976c52f87bd166dbc314c5d61f Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 9 Nov 2017 15:14:56 +0000 Subject: [PATCH 4/4] Make SQL statement for JDBC repo configurable --- .../server/environment/JdbcEnvironmentRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java index f12c8687..ffdc54c9 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java @@ -61,6 +61,14 @@ public class JdbcEnvironmentRepository implements EnvironmentRepository, Ordered public JdbcEnvironmentRepository(JdbcTemplate jdbc) { this.jdbc = jdbc; } + + public void setSql(String sql) { + this.sql = sql; + } + + public String getSql() { + return this.sql; + } @Override public Environment findOne(String application, String profile, String label) {