/** * @deprecated in favor of {@link #parseRegionName(String, String)}. */ @Deprecated public static String parseRegionName(URI endpoint) { return parseRegionName(endpoint.getHost(), null); }
private String resolveRegion(String endpointPrefix, String serviceSigningName) { return AwsHostNameUtils.parseRegionName(request.getEndpoint().getHost(), endpointPrefix != null ? endpointPrefix : serviceSigningName); }
/** * @deprecated use {@link AmazonS3ClientBuilder#setEndpointConfiguration(AwsClientBuilder.EndpointConfiguration)} */ @Override @Deprecated public synchronized void setEndpoint(String endpoint) { if (ServiceUtils.isS3AccelerateEndpoint(endpoint)) { throw new IllegalStateException("To enable accelerate mode, please use AmazonS3ClientBuilder.withAccelerateModeEnabled(true)"); } else { super.setEndpoint(endpoint); /* * Extract the region string from the endpoint if it's not known to be a * global S3 endpoint. */ if (!ServiceUtils.isS3USStandardEndpoint(endpoint)) { clientRegion = AwsHostNameUtils.parseRegionName(this.endpoint.getHost(), S3_SERVICE_NAME); } } }
@Override public Signer getSigner(SignerProviderContext signerProviderContext) { URI uri = signerProviderContext.getUri(); // Return the default signer if no URI is passed, the client is configured with region override, // or if we are hitting an accelerate endpoint. if (uri == null || ServiceUtils.isS3AccelerateEndpoint(uri.getHost()) || isSignerRegionOverrideSet()) { return signer; } if (signer instanceof RegionAwareSigner) { // Parse region name from the host component of the URL and // assign it to the signer RegionAwareSigner regionSigner = (RegionAwareSigner) signer; try { regionSigner.setRegionName(AwsHostNameUtils.parseRegionName( uri.getHost(), "s3")); } catch (RuntimeException e) { log.warn("Failed to parse the endpoint " + uri + ", and skip re-assigning the signer region", e); } } return signer; }
/** * Returns the signer for the given uri and the current client * configuration. * <p> * Note, however, the signer returned for S3 is incomplete at this stage as * the information on the S3 bucket and key is not yet known. * * @param signerRegionOverride * the overriding signer region; or null if there is none. * @param isRegionIdAsSignerParam * true if the "regionId" is used to configure the signer if * applicable; false if this method is called for the purpose of * purely setting the communication end point of this AWS client, * and therefore the "regionId" parameter will not be used * directly for configuring the signer. */ private Signer computeSignerByURI(URI uri, String signerRegionOverride, boolean isRegionIdAsSignerParam) { if (uri == null) { throw new IllegalArgumentException( "Endpoint is not set. Use setEndpoint to set an endpoint before performing any request."); } String service = getServiceNameIntern(); String region = AwsHostNameUtils.parseRegionName(uri.getHost(), getEndpointPrefix()); return computeSignerByServiceRegion( service, region, signerRegionOverride, isRegionIdAsSignerParam); }
.getDestinationRegion() != null ? originalCopySnapshotRequest .getDestinationRegion() : AwsHostNameUtils .parseRegionName(endPointDestination.getHost(), serviceName);
protected String extractRegionName(URI endpoint) { if (regionName != null) { return regionName; } return AwsHostNameUtils.parseRegionName(endpoint.getHost(), serviceName); }
/** * @deprecated in favor of {@link #parseRegionName(String, String)}. */ @Deprecated public static String parseRegionName(URI endpoint) { return parseRegionName(endpoint.getHost(), null); }
/** * @deprecated in favor of {@link #parseRegionName(String, String)}. * @param endpoint the URI endpoint. * @return the region name. */ @Deprecated public static String parseRegionName(URI endpoint) { return parseRegionName(endpoint.getHost(), null); }
private String resolveRegion(String endpointPrefix, String serviceSigningName) { return AwsHostNameUtils.parseRegionName(request.getEndpoint().getHost(), endpointPrefix != null ? endpointPrefix : serviceSigningName); }
@Override public void setEndpoint(String endpoint) { if (endpoint.endsWith(Constants.S3_ACCELERATE_HOSTNAME)) { throw new IllegalStateException( "To enable accelerate mode, please use AmazonS3Client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build());"); } super.setEndpoint(endpoint); /* * Extract the region string from the endpoint if it's not known to be a * global S3 endpoint. */ if (!endpoint.endsWith(Constants.S3_HOSTNAME)) { clientRegion = AwsHostNameUtils.parseRegionName(this.endpoint.getHost(), S3_SERVICE_NAME); } }
/** * Returns the signer for the given uri and the current client * configuration. * <p> * Note, however, the signer returned for S3 is incomplete at this stage as * the information on the S3 bucket and key is not yet known. * * @param signerRegionOverride the overriding signer region; or null if * there is none. * @param isRegionIdAsSignerParam true if the "regionId" is used to * configure the signer if applicable; false if this method is * called for the purpose of purely setting the communication end * point of this AWS client, and therefore the "regionId" * parameter will not be used directly for configuring the * signer. */ @SuppressWarnings("checkstyle:hiddenfield") private Signer computeSignerByURI(final URI uri, String signerRegionOverride, boolean isRegionIdAsSignerParam) { if (uri == null) { throw new IllegalArgumentException( "Endpoint is not set. Use setEndpoint to set an endpoint before performing any request."); } final String service = getServiceNameIntern(); final String region = AwsHostNameUtils.parseRegionName(uri.getHost(), service); return computeSignerByServiceRegion( service, region, signerRegionOverride, isRegionIdAsSignerParam); }
/** * Returns the signer for the given uri and the current client * configuration. * <p> * Note, however, the signer returned for S3 is incomplete at this stage as * the information on the S3 bucket and key is not yet known. * * @param signerRegionOverride * the overriding signer region; or null if there is none. * @param isRegionIdAsSignerParam * true if the "regionId" is used to configure the signer if * applicable; false if this method is called for the purpose of * purely setting the communication end point of this AWS client, * and therefore the "regionId" parameter will not be used * directly for configuring the signer. */ private Signer computeSignerByURI(URI uri, String signerRegionOverride, boolean isRegionIdAsSignerParam) { if (uri == null) { throw new IllegalArgumentException( "Endpoint is not set. Use setEndpoint to set an endpoint before performing any request."); } String service = getServiceNameIntern(); String region = AwsHostNameUtils.parseRegionName(uri.getHost(), getEndpointPrefix()); return computeSignerByServiceRegion( service, region, signerRegionOverride, isRegionIdAsSignerParam); }
@Test public void testS3SpecialRegions() { assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3-external-1.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3-external-1.amazonaws.com", null)); assertEquals("us-gov-west-1", AwsHostNameUtils.parseRegionName("s3-fips-us-gov-west-1.amazonaws.com", null)); assertEquals("us-gov-west-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3-fips-us-gov-west-1.amazonaws.com", null)); }
@Test public void testBJS() { // Verify that BJS endpoints parse correctly even though they're // non-standard. assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("iam.cn-north-1.amazonaws.com.cn", "iam")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("ec2.cn-north-1.amazonaws.com.cn", "ec2")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3.cn-north-1.amazonaws.com.cn", "s3")); }
@Test public void testStandard() { // Verify that standard endpoints parse correctly with a service hint assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("iam.amazonaws.com", "iam")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("iam.us-west-2.amazonaws.com", "iam")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("ec2.us-west-2.amazonaws.com", "ec2")); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3.amazonaws.com", "s3")); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("bucket.name.s3.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3.eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3")); }
@Test public void testStandardNoHint() { // Verify that standard endpoints parse correctly without a service hint assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("iam.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("iam.us-west-2.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("ec2.us-west-2.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("bucket.name.s3.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3-eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3.eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3-eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName( "bucket.name.with.periods.s3.eu-west-1.amazonaws.com", null)); }
protected String extractRegionName(URI endpoint) { if (regionName != null) { return regionName; } return AwsHostNameUtils.parseRegionName(endpoint.getHost(), serviceName); }
protected String extractRegionName(URI endpoint) { if (regionName != null) { return regionName; } return AwsHostNameUtils.parseRegionName(endpoint.getHost(), serviceName); }
/** * @deprecated in favor of {@link #parseRegionName(String, String)}. * @param endpoint the URI endpoint. * @return the region name. */ @Deprecated public static String parseRegionName(URI endpoint) { return parseRegionName(endpoint.getHost(), null); }