remove dependency on Regions class from sdk v1
This commit is contained in:
parent
d8f90476f5
commit
f35c7dfd85
4 changed files with 17 additions and 11 deletions
|
|
@ -15,13 +15,14 @@
|
|||
package software.amazon.kinesis.multilang;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
/**
|
||||
* Key-Value pairs which may be nested in, and extracted from, a property value
|
||||
|
|
@ -73,8 +74,13 @@ public enum NestedPropertyKey {
|
|||
* @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions">Available Regions</a>
|
||||
*/
|
||||
ENDPOINT_REGION {
|
||||
void visit(final NestedPropertyProcessor processor, final String region) {
|
||||
processor.acceptEndpointRegion(Regions.fromName(region));
|
||||
void visit(final NestedPropertyProcessor processor, final String regionName) {
|
||||
List<Region> validRegions = Region.regions();
|
||||
Region region = Region.of(regionName);
|
||||
if (!validRegions.contains(region)) {
|
||||
throw new IllegalArgumentException("Invalid region name: " + regionName);
|
||||
}
|
||||
processor.acceptEndpointRegion(region);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
package software.amazon.kinesis.multilang;
|
||||
|
||||
import com.amazonaws.regions.Regions;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
/**
|
||||
* Defines methods to process {@link NestedPropertyKey}s.
|
||||
|
|
@ -28,7 +28,7 @@ public interface NestedPropertyProcessor {
|
|||
* (e.g., https://sns.us-west-1.amazonaws.com, sns.us-west-1.amazonaws.com)
|
||||
* @param signingRegion the region to use for SigV4 signing of requests (e.g. us-west-1)
|
||||
*
|
||||
* @see #acceptEndpointRegion(Regions)
|
||||
* @see #acceptEndpointRegion(Region)
|
||||
* @see <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/client/builder/AwsClientBuilder.EndpointConfiguration.html">
|
||||
* AwsClientBuilder.EndpointConfiguration</a>
|
||||
*/
|
||||
|
|
@ -42,7 +42,7 @@ public interface NestedPropertyProcessor {
|
|||
*
|
||||
* @see #acceptEndpoint(String, String)
|
||||
*/
|
||||
void acceptEndpointRegion(Regions region);
|
||||
void acceptEndpointRegion(Region region);
|
||||
|
||||
/**
|
||||
* Set the external id, an optional field to designate who can assume an IAM role.
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ import com.amazonaws.auth.AWSSessionCredentialsProvider;
|
|||
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
|
||||
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider.Builder;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
|
||||
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;
|
||||
import software.amazon.kinesis.multilang.NestedPropertyKey;
|
||||
import software.amazon.kinesis.multilang.NestedPropertyProcessor;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
/**
|
||||
* An {@link AWSSessionCredentialsProvider} that is backed by STSAssumeRole.
|
||||
|
|
@ -73,7 +73,7 @@ public class KclSTSAssumeRoleSessionCredentialsProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public void acceptEndpointRegion(final Regions region) {
|
||||
public void acceptEndpointRegion(final Region region) {
|
||||
final AWSSecurityTokenService stsClient =
|
||||
AWSSecurityTokenServiceClient.builder().withRegion(region).build();
|
||||
builder.withStsClient(stsClient);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@
|
|||
*/
|
||||
package software.amazon.kinesis.multilang;
|
||||
|
||||
import com.amazonaws.regions.Regions;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
|
@ -64,9 +64,9 @@ public class NestedPropertyKeyTest {
|
|||
|
||||
@Test
|
||||
public void testEndpointRegion() {
|
||||
final Regions expectedRegion = Regions.GovCloud;
|
||||
final Region expectedRegion = Region.US_GOV_WEST_1;
|
||||
|
||||
parse(mockProcessor, createKey(ENDPOINT_REGION, expectedRegion.getName()));
|
||||
parse(mockProcessor, createKey(ENDPOINT_REGION, expectedRegion.id()));
|
||||
verify(mockProcessor).acceptEndpointRegion(expectedRegion);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue