private boolean shouldUseVirtualAddressing(final URI endpoint) { return !isPathStyleAccess && BucketNameUtils.isDNSBucketName(bucketName) && !isValidIpV4Address(endpoint.getHost()); }
/** * Convience method that allows the DNS rules to be altered for different SDKs. */ public static boolean isDNSBucketName(String bucketName) { return isValidV2BucketName( bucketName ); }
return exception(throwOnError, "Bucket name cannot be null"); return exception( throwOnError, "Bucket name should be between " + MIN_BUCKET_NAME_LENGTH + " and " + MAX_BUCKET_NAME_LENGTH +" characters long" return exception( throwOnError, "Bucket name must not be formatted as an IP Address" return exception( throwOnError, "Bucket name should not contain uppercase characters" return exception( throwOnError, "Bucket name should not contain white space" return exception( throwOnError, "Bucket name should not begin with a period" return exception( throwOnError, "Bucket name should not contain two adjacent periods" return exception( throwOnError, "Bucket name should not contain dashes next to periods"
@Test(expected = IllegalArgumentException.class) public void testInvalidV2BucketNames() { assertFalse(BucketNameUtils.isValidV2BucketName(null)); assertFalse(BucketNameUtils.isValidV2BucketName("sm")); assertFalse(BucketNameUtils.isValidV2BucketName("UPPERCASE")); assertFalse(BucketNameUtils.isValidV2BucketName("contains.dot")); assertFalse(BucketNameUtils.isValidV2BucketName("white space")); assertFalse(BucketNameUtils.isValidV2BucketName("adjacent..periods")); assertFalse(BucketNameUtils.isValidV2BucketName("dash.-nexttoperiod")); char invalid[] = { '9' }; invalid[0]++; assertFalse(BucketNameUtils.isValidV2BucketName( String.valueOf(invalid))); assertFalse(BucketNameUtils.isValidV2BucketName("endingperiod.")); BucketNameUtils.validateBucketName("endingdash-"); } }
URI requestEndpoint = getCreateBucketEndpoint(requestRegion); BucketNameUtils.validateBucketName(bucketName);
bucketName = bucketName.trim(); BucketNameUtils.validateBucketName(bucketName);
private boolean canUseVirtualAddressing() { return BucketNameUtils.isDNSBucketName(endpointResolver.getBucketName()); }
/** * Returns true if the specified bucket name can be addressed using V2, * virtual host style, addressing. Otherwise, returns false indicating that * the bucket must be addressed using V1, path style, addressing. * * @param bucketName * The name of the bucket to check. * * @return True if the specified bucket name can be addressed in V2, virtual * host style, addressing otherwise false if V1, path style, * addressing is required. */ public static boolean isValidV2BucketName(String bucketName) { return isValidV2BucketName(bucketName, false); }
bucketName = bucketName.trim(); BucketNameUtils.validateBucketName(bucketName);
return exception(throwOnError, "Bucket name cannot be null"); return exception( throwOnError, "Bucket name should be between " + MIN_BUCKET_NAME_LENGTH + " and " return exception( throwOnError, "Bucket name must not be formatted as an IP Address"); return exception( throwOnError, "Bucket name should not contain uppercase characters"); return exception( throwOnError, "Bucket name should not contain white space"); return exception( throwOnError, "Bucket name should not begin with a period"); return exception( throwOnError, "Bucket name should not contain two adjacent periods"); return exception( throwOnError, "Bucket name should not contain dashes next to periods");
private static String convertRegionToString(Region region, String bucketName) { String regionAsString; if (region == null) { if (BucketNameUtils.isDNSBucketName(bucketName)) { regionAsString = Region.US_Standard.getFirstRegionId(); } else { throw new IllegalArgumentException("Region must be specified for bucket that cannot be addressed using virtual host style"); } } else { regionAsString = region.getFirstRegionId(); } return regionAsString; }
/** * Validates that the specified bucket name is valid for Amazon S3 V2 naming * (i.e. DNS addressable in virtual host style). Throws an * IllegalArgumentException if the bucket name is not valid. * <p> * S3 bucket naming guidelines are specified in <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?BucketRestrictions.html" * > http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html? * BucketRestrictions.html</a> * * @param bucketName * The bucket name to validate. * * @throws IllegalArgumentException * If the specified bucket name doesn't follow Amazon S3's * guidelines. */ public static void validateBucketName(final String bucketName) { isValidV2BucketName(bucketName, true); }
URI requestEndpoint = getCreateBucketEndpoint(requestRegion); BucketNameUtils.validateBucketName(bucketName);
return exception(throwOnError, "Bucket name cannot be null"); return exception( throwOnError, "Bucket name should be between " + MIN_BUCKET_NAME_LENGTH + " and " return exception( throwOnError, "Bucket name must not be formatted as an IP Address"); return exception( throwOnError, "Bucket name should not contain uppercase characters"); return exception( throwOnError, "Bucket name should not contain white space"); return exception( throwOnError, "Bucket name should not begin with a period"); return exception( throwOnError, "Bucket name should not contain two adjacent periods"); return exception( throwOnError, "Bucket name should not contain dashes next to periods");
private boolean shouldUseVirtualAddressing(final URI endpoint, final String bucketName) { return !clientOptions.isPathStyleAccess() && BucketNameUtils.isDNSBucketName(bucketName) && !isValidIpV4Address(endpoint.getHost()); }
/** * Convience method that allows the DNS rules to be altered for different * SDKs. * * @param bucketName the name of the bucket. * @return true if the name is valid, false if not. */ public static boolean isDNSBucketName(String bucketName) { return isValidV2BucketName(bucketName); }
return exception(throwOnError, "Bucket name cannot be null"); return exception( throwOnError, "Bucket name should be between " + MIN_BUCKET_NAME_LENGTH + " and " + MAX_BUCKET_NAME_LENGTH +" characters long" return exception( throwOnError, "Bucket name must not be formatted as an IP Address" return exception( throwOnError, "Bucket name should not contain uppercase characters" return exception( throwOnError, "Bucket name should not contain white space" return exception( throwOnError, "Bucket name should not begin with a period" return exception( throwOnError, "Bucket name should not contain two adjacent periods" return exception( throwOnError, "Bucket name should not contain dashes next to periods"
/** * Constructs a new {@link ID} with all the required parameters. * * @param bucket The name of the bucket containing the desired object. * @param key The key in the specified bucket under which the object is * stored. */ ID(Region region, String bucket, String key) { if (region == null) { if (BucketNameUtils.isDNSBucketName(bucket)) { this.regionId = Region.US_Standard.getFirstRegionId(); } else { throw new IllegalArgumentException( "Region must be specified for bucket that cannot be addressed using virtual host style"); } } else { this.regionId = region.getFirstRegionId(); } this.bucket = bucket; this.key = key; }
/** * Returns true if the specified bucket name can be addressed using V2, * virtual host style, addressing. Otherwise, returns false indicating that * the bucket must be addressed using V1, path style, addressing. * * @param bucketName The name of the bucket to check. * @return True if the specified bucket name can be addressed in V2, virtual * host style, addressing otherwise false if V1, path style, * addressing is required. */ public static boolean isValidV2BucketName(String bucketName) { return isValidV2BucketName(bucketName, false); }
private boolean shouldUseVirtualAddressing(final URI endpoint) { return !isPathStyleAccess && BucketNameUtils.isDNSBucketName(bucketName) && !isValidIpV4Address(endpoint.getHost()); }