From 8021faf33d75ed08901c4918399a2f05830f155e Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 27 Aug 2018 10:00:13 +0200 Subject: [PATCH] fix(aws-s3): remove bucket name validation Now that Tokens can be stringified, they can be inserted into parameters like `bucketName`, which can lead to an input string like `"bucket-name-${Token[TOKEN.0]}"`. We can't properly validate these strings anymore. Fixes #624. --- packages/@aws-cdk/aws-s3/lib/bucket.ts | 4 +--- packages/@aws-cdk/aws-s3/lib/util.ts | 10 ---------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 4f7a62e481c16..f03a44b33b3d1 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -7,7 +7,7 @@ import { BucketNotifications } from './notifications-resource'; import perms = require('./perms'); import { LifecycleRule } from './rule'; import { BucketArn, BucketDomainName, BucketDualStackDomainName, cloudformation } from './s3.generated'; -import { parseBucketArn, parseBucketName, validateBucketName } from './util'; +import { parseBucketArn, parseBucketName } from './util'; /** * A reference to a bucket. The easiest way to instantiate is to call @@ -348,8 +348,6 @@ export class Bucket extends BucketRef { constructor(parent: cdk.Construct, name: string, props: BucketProps = {}) { super(parent, name); - validateBucketName(props && props.bucketName); - const { bucketEncryption, encryptionKey } = this.parseEncryption(props); const resource = new cloudformation.BucketResource(this, 'Resource', { diff --git a/packages/@aws-cdk/aws-s3/lib/util.ts b/packages/@aws-cdk/aws-s3/lib/util.ts index 13783c94bee11..830f51a349fc7 100644 --- a/packages/@aws-cdk/aws-s3/lib/util.ts +++ b/packages/@aws-cdk/aws-s3/lib/util.ts @@ -1,16 +1,6 @@ import { Arn } from '@aws-cdk/cdk'; import { BucketRefProps } from './bucket'; -export function validateBucketName(bucketName?: string) { - if (!bucketName) { - return; - } - - if (bucketName.search(/[^a-z0-9.-]/g) !== -1) { - throw new Error('Bucket name contains invalid characters: ' + bucketName); - } -} - export function parseBucketArn(props: BucketRefProps) { // if we have an explicit bucket ARN, use it.