Skip to content

Commit

Permalink
Merge branch '4.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Dec 19, 2024
2 parents 0eaefa0 + b3c179f commit 91bc257
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;

/**
Expand Down Expand Up @@ -80,7 +81,11 @@ private <P extends EnvironmentRepositoryProperties> P bindProperties(int index,
Binder binder = Binder.get(environment);
String environmentConfigurationPropertyName = String.format("spring.cloud.config.server.composite[%d]", index);
P properties = binder.bindOrCreate(environmentConfigurationPropertyName, propertiesClass);
properties.setOrder(index + 1);
if (properties instanceof Ordered
&& ((Ordered) properties).getOrder() == EnvironmentRepositoryProperties.DEFAULT_ORDER) {
// The order is not set, it is the default so set it to the order in the list
properties.setOrder(index + 1);
}
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
import org.springframework.validation.annotation.Validated;

/**
Expand All @@ -45,7 +44,7 @@ public class AwsParameterStoreEnvironmentProperties implements EnvironmentReposi
/**
* The order of the environment repository.
*/
private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

/**
* The region to be used by the AWS Parameter Store client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AwsS3EnvironmentProperties implements EnvironmentRepositoryProperti
*/
private String bucket;

private int order;
private int order = DEFAULT_ORDER;

public String getRegion() {
return region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Tejas Pandilwar
Expand Down Expand Up @@ -62,7 +61,7 @@ public class AwsSecretsManagerEnvironmentProperties implements EnvironmentReposi
/**
* The order of the environment repository.
*/
private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

/**
* Prefix indicating first level for every property loaded from AWS Secrets Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Alberto C. Ríos
Expand All @@ -32,7 +31,7 @@ public class CredhubEnvironmentProperties implements EnvironmentRepositoryProper
/** The default label to be used when is not provided by client applications. */
private String defaultLabel = "master";

private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

public String getPath() {
return this.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Jose Maria Alvarez
*/
@ConfigurationProperties("spring.cloud.config.server.gcp-secret-manager")
public class GoogleSecretManagerEnvironmentProperties implements EnvironmentRepositoryProperties {

private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

private String applicationLabel = "application";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Dylan Roberts
Expand All @@ -38,7 +37,7 @@ public class JdbcEnvironmentProperties implements EnvironmentRepositoryPropertie
*/
private boolean enabled = true;

private int order = Ordered.LOWEST_PRECEDENCE - 10;
private int order = DEFAULT_ORDER - 10;

/** SQL used to query database for keys and values. */
private String sql = DEFAULT_SQL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Dylan Roberts
Expand Down Expand Up @@ -49,7 +48,7 @@ public class NativeEnvironmentProperties implements EnvironmentRepositoryPropert
*/
private String version;

private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

public Boolean getFailOnError() {
return this.failOnError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;

/**
* @author Piotr Mińkowski
*/
@ConfigurationProperties("spring.cloud.config.server.redis")
public class RedisEnvironmentProperties implements EnvironmentRepositoryProperties {

private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

public int getOrder() {
return this.order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.proxy.ProxyHostProperties;
import org.springframework.cloud.config.server.support.HttpEnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
import org.springframework.core.io.Resource;
import org.springframework.validation.annotation.Validated;

Expand Down Expand Up @@ -83,7 +82,7 @@ public class VaultEnvironmentProperties implements HttpEnvironmentRepositoryProp
*/
private Map<ProxyHostProperties.ProxyForScheme, ProxyHostProperties> proxy = new HashMap<>();

private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

/**
* Value to indicate which version of Vault kv backend is used. Defaults to 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.io.File;

import org.springframework.core.Ordered;

/**
* @author Dylan Roberts
*/
Expand Down Expand Up @@ -63,7 +61,7 @@ public class AbstractScmAccessorProperties implements EnvironmentRepositoryPrope
private boolean strictHostKeyChecking = true;

/** The order of the environment repository. */
private int order = Ordered.LOWEST_PRECEDENCE;
private int order = DEFAULT_ORDER;

/** The default label to be used with the remote repository. */
private String defaultLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

package org.springframework.cloud.config.server.support;

import org.springframework.core.Ordered;

/**
* @author Dylan Roberts
*/
public interface EnvironmentRepositoryProperties {

/**
* Default order value.
*/
int DEFAULT_ORDER = Ordered.LOWEST_PRECEDENCE;

void setOrder(int order);

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,57 @@ public void resourceEndpointsWork() {

}

@Nested
@SpringBootTest(classes = TestConfigServerApplication.class, properties = {
"spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].type: svn",
"spring.cloud.config.server.composite[0].uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.composite[0].order:2", "spring.cloud.config.server.composite[1].type: git",
"spring.cloud.config.server.composite[1].uri:file:./target/repos/config-repo",
"spring.cloud.config.server.composite[1].order:1" }, webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "composite" })
class StaticCompositeTests {

@LocalServerPort
private int port;

@BeforeAll
public static void init() throws Exception {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

ConfigServerTestUtils.prepareLocalRepo();
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
"target/repos/svn-config-repo");
}

@Test
public void contextLoads() {
ResponseEntity<Environment> response = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/foo/development", HttpMethod.GET, getV2AcceptEntity(),
Environment.class);
Environment environment = response.getBody();
assertThat(3).isEqualTo(environment.getPropertySources().size());
assertThat("overrides").isEqualTo(environment.getPropertySources().get(0).getName());
assertThat(environment.getPropertySources().get(1).getName().contains("config-repo")
&& !environment.getPropertySources().get(1).getName().contains("svn-config-repo"))
.isTrue();
assertThat(environment.getPropertySources().get(2).getName()).contains("svn-config-repo");
ConfigServerTestUtils.assertConfigEnabled(environment);
}

@Test
public void resourceEndpointsWork() {
// This request will get the file from the Git Repo because its order is first
// The SVN repo should have the content foo: bar
String text = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/foo/development/composite/bar.properties", String.class);

String expected = "foo: barconfig\n";
assertThat(expected).isEqualTo(text).as("invalid content");
}

}

@Nested
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
Expand Down

0 comments on commit 91bc257

Please sign in to comment.