From 85053fc06a35011601db185f6e5b6542df2d2ecf Mon Sep 17 00:00:00 2001 From: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:36:54 -0400 Subject: [PATCH 1/3] Upgrade jgit to 5.13.2.202306221912-r --- spring-cloud-config-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 2d2a4221..280178c1 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -15,7 +15,7 @@ spring-cloud-config-dependencies Spring Cloud Config Dependencies - 5.13.1.202206130422-r + 5.13.2.202306221912-r 2.3.2 2.1.1.RELEASE 2.4.4 From 558545dbfbe20b03dc5394aeda4b2b9cb8e8e1ce Mon Sep 17 00:00:00 2001 From: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:15:59 -0400 Subject: [PATCH 2/3] Fixing doc includes --- README.adoc | 2 +- docs/src/main/asciidoc/README.adoc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 2991a3d1..83062c93 100644 --- a/README.adoc +++ b/README.adoc @@ -264,7 +264,7 @@ The refresh endpoint reports that the "sample" property changed. == Building -:jdkversion: 17 +:jdkversion: 1.8 === Basic Compile and Test diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc index 0ee4204e..bcd2f7bc 100644 --- a/docs/src/main/asciidoc/README.adoc +++ b/docs/src/main/asciidoc/README.adoc @@ -60,7 +60,7 @@ The refresh endpoint reports that the "sample" property changed. == Building -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/building.adoc[] +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/3.1.x/docs/src/main/asciidoc/building.adoc[] === JCE @@ -77,4 +77,4 @@ Extract the JCE files into the `JDK/jre/lib/security` folder for whichever versi == Contributing -include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/contributing.adoc[] +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/3.1.x/docs/src/main/asciidoc/contributing.adoc[] From 861ed6785e4a7eceacb123076062721e56ab0b40 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 21 Nov 2023 15:27:17 -0500 Subject: [PATCH 3/3] Do not combine profiles when spring.cloud.config.pofiles is set. (#2354) Fixes #2349 --- .../ConfigServicePropertySourceLocator.java | 12 ++++-------- ...ConfigServicePropertySourceLocatorTests.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java index 5509a259..73ab8066 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java @@ -50,7 +50,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.retry.annotation.Retryable; import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; @@ -80,8 +79,7 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator } /** - * Combine properties from the config client properties and the active profiles from - * the environment. + * Combine the active and default profiles from the environment. * @param properties config client properties, * @param environment application environment. * @return A list of combined profiles. @@ -89,10 +87,6 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator private List combineProfiles(ConfigClientProperties properties, org.springframework.core.env.Environment environment) { List combinedProfiles = new ArrayList<>(); - if (!ObjectUtils.isEmpty(properties.getProfile())) { - combinedProfiles = Stream.of(properties.getProfile().split(",")).map(String::trim).filter(s -> !s.isEmpty()) - .collect(Collectors.toList()); - } if (environment.getActiveProfiles().length > 0) { List finalCombinedProfiles = combinedProfiles; List filteredActiveProfiles = Stream.of(environment.getActiveProfiles()) @@ -109,7 +103,9 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator @Retryable(interceptor = "configServerRetryInterceptor") public org.springframework.core.env.PropertySource locate(org.springframework.core.env.Environment environment) { ConfigClientProperties properties = this.defaultProperties.override(environment); - properties.setProfile(String.join(",", combineProfiles(properties, environment))); + if (!StringUtils.hasText(properties.getProfile())) { + properties.setProfile(String.join(",", combineProfiles(properties, environment))); + } if (StringUtils.startsWithIgnoreCase(properties.getName(), "application-")) { InvalidApplicationNameException exception = new InvalidApplicationNameException(properties.getName()); diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java index 39d61edb..83bd5ff3 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java @@ -118,6 +118,17 @@ public class ConfigServicePropertySourceLocatorTests { assertThat(this.locator.locateCollection(this.environment)).isNotNull(); } + @Test + public void overrideProfile() { + Environment body = new Environment("app", "override-profile"); + body.add(new PropertySource("p1", new HashMap<>())); + mockRequestResponseWithProfile(new ResponseEntity<>(body, HttpStatus.OK), "override-profile"); + this.locator.setRestTemplate(this.restTemplate); + TestPropertyValues.of("spring.cloud.config.profile:override-profile", "spring.profiles.active: foo") + .applyTo(this.environment); + assertThat(this.locator.locateCollection(this.environment).size()).isEqualTo(2); + } + @Test public void sunnyDayWithLabelThatContainsASlash() { Environment body = new Environment("app", "master"); @@ -358,6 +369,12 @@ public class ConfigServicePropertySourceLocatorTests { ArgumentMatchers.eq(label))).thenReturn(response); } + private void mockRequestResponseWithProfile(ResponseEntity response, String profiles) { + Mockito.when(this.restTemplate.exchange(Mockito.any(String.class), Mockito.any(HttpMethod.class), + Mockito.any(HttpEntity.class), Mockito.any(Class.class), anyString(), ArgumentMatchers.eq(profiles))) + .thenReturn(response); + } + @SuppressWarnings("unchecked") private void mockRequestResponseWithoutLabel(ResponseEntity response) { Mockito.when(this.restTemplate.exchange(Mockito.any(String.class), Mockito.any(HttpMethod.class),