private String resolveCertCommonName(String region) { if (Regions.CN_NORTH_1.getName().equals(region)) { return "sns-cn-north-1.amazonaws.com.cn"; } if (Regions.CN_NORTHWEST_1.getName().equals(region)) { return "sns-cn-northwest-1.amazonaws.com.cn"; } if (Regions.GovCloud.getName().equals(region)) { return "sns-us-gov-west-1.amazonaws.com"; } return "sns." + RegionUtils.getRegion(region).getDomain(); } }
/** * Sets the region to be used for the default AWS SDK metric collector; * or null if the default is to be used. */ public static void setRegion(Regions region) { AwsSdkMetrics.region = RegionUtils.getRegion(region.getName()); }
/** * Returns the region with the id given, or null if it cannot be found in * the current regions.xml file. */ public static Region getRegion(Regions region) { return RegionUtils.getRegion(region.getName()); }
/** * Returns a region enum corresponding to the given region name. * * @param regionName * The name of the region. Ex.: eu-west-1 * @return Region enum representing the given region name. */ public static Regions fromName(String regionName) { for (Regions region : Regions.values()) { if (region.getName().equals(regionName)) { return region; } } throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!"); }
/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * <p> For regions not explicitly in the {@link Regions} enum use the {@link * #withRegion(String)} overload.</p> * * @param region Region to use * @return This object for method chaining. */ public final Subclass withRegion(Regions region) { return withRegion(region.getName()); }
/** * Sets the signing region to be used by the client. This region will <b>NOT</b> be used to compute the endpoint, the endpoint * must be explicitly provided via the {@link #setEndpoint(URI)} or {@link #withEndpoint(URI)} methods. * * <p> * For regions that are not in the {@link Regions} enum, {@link #setRegion(String)} or {@link #withRegion(String)} should * be used instead. * </p> * * @param region Region to sign with. * @return This object for method chaining. * @see <a href="http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html">AWS Region Selection</a> */ public AmazonKinesisVideoPutMediaClientBuilder withRegion(Regions region) { setRegion(region.getName()); return this; }
/** * If the response doesn't have the x-amz-region header we have to resort to sending a request * to s3-external-1 * * @return */ private AuthRetryParameters redirectToS3External() { AWSS3V4Signer v4Signer = buildSigV4Signer(Regions.US_EAST_1.getName()); try { URI bucketEndpoint = new URI( String.format("https://%s.s3-external-1.amazonaws.com", endpointResolver.getBucketName())); return buildRetryParams(v4Signer, bucketEndpoint); } catch (URISyntaxException e) { throw new SdkClientException( "Failed to re-send the request to \"s3-external-1.amazonaws.com\". " + V4_REGION_WARNING, e); } }
/** * Determines the logins key for the token. * This currently varies for cn-north-1 region only. * * @return logins key used in the logins map */ protected String getLoginsKey() { if (Regions.CN_NORTH_1.getName().equals(this.region)) { return "cognito-identity.cn-north-1.amazonaws.com.cn"; } else { return "cognito-identity.amazonaws.com"; } }
/** * Sets the region to be used for the default AWS SDK metric collector; * or null if the default is to be used. */ public static void setRegion(Regions region) { AwsSdkMetrics.region = RegionUtils.getRegion(region.getName()); }
/** * Returns the region with the id given, or null if it cannot be found in * the current regions.xml file. */ public static Region getRegion(Regions region) { return RegionUtils.getRegion(region.getName()); }
/** * @param region the region. * @return the region with the id given, or null if it cannot be found in * the current regions.xml file. */ public static Region getRegion(Regions region) { return RegionUtils.getRegion(region.getName()); }
/** * Returns a region enum corresponding to the given region name. * * @param regionName The name of the region. Ex.: eu-west-1 * @return Region enum representing the given region name. */ public static Regions fromName(String regionName) { for (final Regions region : Regions.values()) { if (regionName.equals(region.getName())) { return region; } } throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!"); }
/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * <p> For regions not explicitly in the {@link Regions} enum use the {@link * #withRegion(String)} overload.</p> * * @param region Region to use * @return This object for method chaining. */ public final Subclass withRegion(Regions region) { return withRegion(region.getName()); }
/** * Returns a region enum corresponding to the given region name. * * @param regionName * The name of the region. Ex.: eu-west-1 * @return Region enum representing the given region name. */ public static Regions fromName(String regionName) { for (Regions region : Regions.values()) { if (region.getName().equals(regionName)) { return region; } } throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!"); }
public static StreamConnection openS3InputStream(URL url) throws IOException { S3Params s3Params = S3ParamsExtractor.extract(url); String region = Objects.nonNull(s3Params.getRegion()) ? s3Params.getRegion() : Regions.US_EAST_1.getName(); return new S3Aws(s3Params, region).getS3AwsInputStream(s3Params); }
@Test public void testSetRegion() { final Regions region = Regions.US_WEST_2; s3.setRegion(Region.getRegion(region)); assertEquals(region.getName(), s3.clientRegion); }
@Test public void testCreateSigner() { s3.setS3ClientOptions(accelerateOption); final Regions region = Regions.US_WEST_2; s3.setRegion(Region.getRegion(region)); final String bucketName = "bucket"; final String key = "key"; final HttpMethodName method = HttpMethodName.GET; final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key); final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method); final Signer signer = s3.createSigner(request, bucketName, key); assertTrue(signer instanceof AWSS3V4Signer); signer.sign(request, creds); final String authorization = request.getHeaders().get("Authorization"); assertNotNull(authorization); final String regionName = authorization.split("/")[2]; assertEquals(region.getName(), regionName); }
@Test public void testCreateSignerWithSpecialCharacterKeys() { s3.setS3ClientOptions(accelerateOption); final Regions region = Regions.US_WEST_2; s3.setRegion(Region.getRegion(region)); final String bucketName = "bucket"; final String key = "key%^!@#*()"; final HttpMethodName method = HttpMethodName.GET; final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key); final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method); final Signer signer = s3.createSigner(request, bucketName, key); assertTrue(signer instanceof AWSS3V4Signer); signer.sign(request, creds); final String authorization = request.getHeaders().get("Authorization"); assertNotNull(authorization); final String regionName = authorization.split("/")[2]; assertEquals(region.getName(), regionName); assertTrue(request.getResourcePath().contains(key)); }
@Test public void testFromName() { final Regions usEast1 = Regions.fromName("us-east-1"); assertEquals(usEast1, Regions.US_EAST_1); final Regions cn1 = Regions.fromName("cn-north-1"); assertEquals(cn1, Regions.CN_NORTH_1); final Regions govCloud = Regions.fromName("us-gov-west-1"); assertEquals(govCloud, Regions.GovCloud); assertEquals(usEast1.getName(), "us-east-1"); } }