Cannot configure endpoint for AWS Secrets Manager or Parameter Store (#2023)
Fixes gh-2025
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2018-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.client.builder.AwsSyncClientBuilder;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
abstract class AwsClientBuilderConfigurer {
|
||||
private AwsClientBuilderConfigurer() {
|
||||
}
|
||||
|
||||
static void configureClientBuilder(AwsSyncClientBuilder<?, ?> clientBuilder, String region, String endpoint) {
|
||||
if (StringUtils.hasText(region)) {
|
||||
if (StringUtils.hasText(endpoint)) {
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
|
||||
endpoint, region);
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
}
|
||||
else {
|
||||
clientBuilder.withRegion(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
|
||||
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
|
||||
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.cloud.config.server.environment.AwsClientBuilderConfigurer.configureClientBuilder;
|
||||
|
||||
/**
|
||||
* @author Iulian Antohe
|
||||
@@ -40,22 +39,7 @@ public class AwsParameterStoreEnvironmentRepositoryFactory implements
|
||||
public AwsParameterStoreEnvironmentRepository build(AwsParameterStoreEnvironmentProperties environmentProperties) {
|
||||
AWSSimpleSystemsManagementClientBuilder clientBuilder = AWSSimpleSystemsManagementClientBuilder.standard();
|
||||
|
||||
String region = environmentProperties.getRegion();
|
||||
|
||||
if (StringUtils.hasLength(region)) {
|
||||
Regions awsRegion = Regions.fromName(region);
|
||||
|
||||
clientBuilder.withRegion(awsRegion);
|
||||
|
||||
String endpoint = environmentProperties.getEndpoint();
|
||||
|
||||
if (StringUtils.hasLength(endpoint)) {
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
|
||||
endpoint, awsRegion.getName());
|
||||
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
}
|
||||
}
|
||||
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
|
||||
|
||||
AWSSimpleSystemsManagement client = clientBuilder.build();
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
|
||||
import static org.springframework.cloud.config.server.environment.AwsClientBuilderConfigurer.configureClientBuilder;
|
||||
|
||||
public class AwsS3EnvironmentRepositoryFactory
|
||||
implements EnvironmentRepositoryFactory<AwsS3EnvironmentRepository, AwsS3EnvironmentProperties> {
|
||||
|
||||
@@ -33,16 +35,7 @@ public class AwsS3EnvironmentRepositoryFactory
|
||||
@Override
|
||||
public AwsS3EnvironmentRepository build(AwsS3EnvironmentProperties environmentProperties) {
|
||||
final AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
|
||||
if (environmentProperties.getRegion() != null) {
|
||||
if (environmentProperties.getEndpoint() != null) {
|
||||
AmazonS3ClientBuilder.EndpointConfiguration endpointConfiguration = new AmazonS3ClientBuilder.EndpointConfiguration(
|
||||
environmentProperties.getEndpoint(), environmentProperties.getRegion());
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
}
|
||||
else {
|
||||
clientBuilder.withRegion(environmentProperties.getRegion());
|
||||
}
|
||||
}
|
||||
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
|
||||
final AmazonS3 client = clientBuilder.build();
|
||||
|
||||
AwsS3EnvironmentRepository repository = new AwsS3EnvironmentRepository(client,
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
|
||||
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
|
||||
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.cloud.config.server.environment.AwsClientBuilderConfigurer.configureClientBuilder;
|
||||
|
||||
/**
|
||||
* @author Tejas Pandilwar
|
||||
@@ -39,19 +38,8 @@ public class AwsSecretsManagerEnvironmentRepositoryFactory implements
|
||||
@Override
|
||||
public AwsSecretsManagerEnvironmentRepository build(AwsSecretsManagerEnvironmentProperties environmentProperties) {
|
||||
AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard();
|
||||
String region = environmentProperties.getRegion();
|
||||
|
||||
if (!StringUtils.isEmpty(region)) {
|
||||
Regions awsRegion = Regions.fromName(region);
|
||||
clientBuilder.withRegion(awsRegion);
|
||||
|
||||
String endpoint = environmentProperties.getEndpoint();
|
||||
if (!StringUtils.isEmpty(endpoint)) {
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
|
||||
endpoint, awsRegion.getName());
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
}
|
||||
}
|
||||
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
|
||||
|
||||
AWSSecretsManager client = clientBuilder.build();
|
||||
return new AwsSecretsManagerEnvironmentRepository(client, configServerProperties, environmentProperties);
|
||||
|
||||
@@ -695,6 +695,25 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
|
||||
assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryCustomizableWithRegion() {
|
||||
AwsParameterStoreEnvironmentRepositoryFactory factory = new AwsParameterStoreEnvironmentRepositoryFactory(new ConfigServerProperties());
|
||||
AwsParameterStoreEnvironmentProperties properties = new AwsParameterStoreEnvironmentProperties();
|
||||
properties.setRegion("us-east-1");
|
||||
AwsParameterStoreEnvironmentRepository repository = factory.build(properties);
|
||||
assertThat(repository).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryCustomizableWithRegionAndEndpoint() {
|
||||
AwsParameterStoreEnvironmentRepositoryFactory factory = new AwsParameterStoreEnvironmentRepositoryFactory(new ConfigServerProperties());
|
||||
AwsParameterStoreEnvironmentProperties properties = new AwsParameterStoreEnvironmentProperties();
|
||||
properties.setRegion("us-east-1");
|
||||
properties.setEndpoint("https://myawsendpoint/");
|
||||
AwsParameterStoreEnvironmentRepository repository = factory.build(properties);
|
||||
assertThat(repository).isNotNull();
|
||||
}
|
||||
|
||||
private void setupAwsSsmClientMocks(Environment environment) {
|
||||
setupAwsSsmClientMocks(environment, false, false);
|
||||
}
|
||||
|
||||
@@ -715,6 +715,25 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
|
||||
assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryCustomizableWithRegion() {
|
||||
AwsSecretsManagerEnvironmentRepositoryFactory factory = new AwsSecretsManagerEnvironmentRepositoryFactory(new ConfigServerProperties());
|
||||
AwsSecretsManagerEnvironmentProperties properties = new AwsSecretsManagerEnvironmentProperties();
|
||||
properties.setRegion("us-east-1");
|
||||
AwsSecretsManagerEnvironmentRepository repository = factory.build(properties);
|
||||
assertThat(repository).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryCustomizableWithRegionAndEndpoint() {
|
||||
AwsSecretsManagerEnvironmentRepositoryFactory factory = new AwsSecretsManagerEnvironmentRepositoryFactory(new ConfigServerProperties());
|
||||
AwsSecretsManagerEnvironmentProperties properties = new AwsSecretsManagerEnvironmentProperties();
|
||||
properties.setRegion("us-east-1");
|
||||
properties.setEndpoint("https://myawsendpoint/");
|
||||
AwsSecretsManagerEnvironmentRepository repository = factory.build(properties);
|
||||
assertThat(repository).isNotNull();
|
||||
}
|
||||
|
||||
private void setupAwsSmClientMocks(Environment environment) {
|
||||
for (PropertySource ps : environment.getPropertySources()) {
|
||||
String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
|
||||
|
||||
Reference in New Issue
Block a user