Skip to content

Commit

Permalink
Merge pull request #13394 from pukkaone/spring-cloud-config-client-label
Browse files Browse the repository at this point in the history
Configure label in Spring Cloud Config Client extension
  • Loading branch information
geoand authored Nov 20, 2020
2 parents 6c3d615 + 00a72e6 commit a93648a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ private URI finalURI(String applicationName, String profile) throws URISyntaxExc
List<String> finalPathSegments = new ArrayList<>(result.getPathSegments());
finalPathSegments.add(applicationName);
finalPathSegments.add(profile);
if (springCloudConfigClientConfig.label.isPresent()) {
finalPathSegments.add(springCloudConfigClientConfig.label.get());
}
result.setPathSegments(finalPathSegments);
return result.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public class SpringCloudConfigClientConfig {
@ConfigItem(defaultValue = "http://localhost:8888")
public String url;

/**
* The label to be used to pull remote configuration properties.
* The default is set on the Spring Cloud Config Server
* (generally "master" when the server uses a Git backend).
*/
@ConfigItem
public Optional<String> label;

/**
* The amount of time to wait when initially establishing a connection before giving up and timing out.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class SpringCloudConfigClientGatewayTest {
private static final int MOCK_SERVER_PORT = 9300;
private static final WireMockServer wireMockServer = new WireMockServer(MOCK_SERVER_PORT);

private static final SpringCloudConfigClientConfig springCloudConfigClientConfig = configForTesting();
private final SpringCloudConfigClientGateway sut = new DefaultSpringCloudConfigClientGateway(
configForTesting());
springCloudConfigClientConfig);

@BeforeAll
static void start() {
Expand All @@ -39,7 +40,9 @@ static void stop() {
void testBasicExchange() throws Exception {
final String applicationName = "foo";
final String profile = "dev";
wireMockServer.stubFor(WireMock.get(String.format("/%s/%s", applicationName, profile)).willReturn(WireMock
final String springCloudConfigUrl = String.format(
"/%s/%s/%s", applicationName, profile, springCloudConfigClientConfig.label.get());
wireMockServer.stubFor(WireMock.get(springCloudConfigUrl).willReturn(WireMock
.okJson(getJsonStringForApplicationAndProfile(applicationName, profile))));

final Response response = sut.exchange(applicationName, profile);
Expand Down Expand Up @@ -73,6 +76,7 @@ private String getJsonStringForApplicationAndProfile(String applicationName, Str
private static SpringCloudConfigClientConfig configForTesting() {
SpringCloudConfigClientConfig springCloudConfigClientConfig = new SpringCloudConfigClientConfig();
springCloudConfigClientConfig.url = "http://localhost:" + MOCK_SERVER_PORT;
springCloudConfigClientConfig.label = Optional.of("master");
springCloudConfigClientConfig.connectionTimeout = Duration.ZERO;
springCloudConfigClientConfig.readTimeout = Duration.ZERO;
springCloudConfigClientConfig.username = Optional.empty();
Expand Down

0 comments on commit a93648a

Please sign in to comment.