Skip to content

Commit

Permalink
un-nested properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Solis Ramirez committed Dec 16, 2019
1 parent b07655a commit 6a44bfa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
55 changes: 17 additions & 38 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,21 +759,6 @@ export enum RedirectProtocol {
HTTPS = 'https',
}

/**
* Specifies the S3 Bucket how the access logs will be persited in.
*/
export interface ServerAccessLogs {
/**
* Destination bucket for the server access logs.
*/
readonly destinationBucket: IBucket;
/**
* Optional log file prefix to use for the bucket's access logs.
* @default - No log file prefix
*/
readonly logFilePrefix?: string | undefined;
}

/**
* Specifies a redirect behavior of all requests to a website endpoint of a bucket.
*/
Expand Down Expand Up @@ -842,13 +827,6 @@ export interface BucketProps {
*/
readonly lifecycleRules?: LifecycleRule[];

/**
* Whether this bucket should have server access logs configured or not.
*
* @default - Disabled server access logs
*/
readonly serverAccessLogs?: ServerAccessLogs;

/**
* The name of the index document (e.g. "index.html") for the website. Enables static website
* hosting for this bucket.
Expand Down Expand Up @@ -923,6 +901,18 @@ export interface BucketProps {
* @default - No CORS configuration.
*/
readonly cors?: CorsRule[];

/**
* Destination bucket for the server access logs.
* @default - Access logs are not enable
*/
readonly serverAccessLogsBucket?: IBucket;

/**
* Optional log file prefix to use for the bucket's access logs.
* @default - No log file prefix
*/
readonly serverAccessLogsPrefix?: string;
}

/**
Expand Down Expand Up @@ -1004,7 +994,6 @@ export class Bucket extends BucketBase {
public policy?: BucketPolicy;
protected autoCreatePolicy = true;
protected disallowPublicAccess?: boolean;
protected serverAccessLogs?: ServerAccessLogs;
private readonly lifecycleRules: LifecycleRule[] = [];
private readonly versioned?: boolean;
private readonly notifications: BucketNotifications;
Expand All @@ -1030,12 +1019,11 @@ export class Bucket extends BucketBase {
metricsConfigurations: Lazy.anyValue({ produce: () => this.parseMetricConfiguration() }),
corsConfiguration: Lazy.anyValue({ produce: () => this.parseCorsConfiguration() }),
accessControl: props.accessControl,
loggingConfiguration: Lazy.anyValue({ produce: () => this.parseServerAccessLogs() }),
loggingConfiguration: this.parseServerAccessLogs(props),
});

resource.applyRemovalPolicy(props.removalPolicy);

this.serverAccessLogs = props.serverAccessLogs;
this.versioned = props.versioned;
this.encryptionKey = encryptionKey;

Expand Down Expand Up @@ -1087,15 +1075,6 @@ export class Bucket extends BucketBase {
this.lifecycleRules.push(rule);
}

/**
* Adds server access logs to the bucket.
*
* @param serverAccessLogs configuration for the S3 bucket.
*/
public addServerAccessLogs(serverAccessLogs: ServerAccessLogs): void {
this.serverAccessLogs = serverAccessLogs;
}

/**
* Adds a metrics configuration for the CloudWatch request metrics from the bucket.
*
Expand Down Expand Up @@ -1307,14 +1286,14 @@ export class Bucket extends BucketBase {
}
}

private parseServerAccessLogs(): CfnBucket.LoggingConfigurationProperty | undefined {
if (!this.serverAccessLogs) {
private parseServerAccessLogs(props: BucketProps): CfnBucket.LoggingConfigurationProperty | undefined {
if (!props.serverAccessLogsBucket) {
return undefined;
}

return {
destinationBucketName: this.serverAccessLogs.destinationBucket.bucketName,
logFilePrefix: this.serverAccessLogs.logFilePrefix,
destinationBucketName: props.serverAccessLogsBucket.bucketName,
logFilePrefix: props.serverAccessLogsPrefix,
};
}

Expand Down
48 changes: 47 additions & 1 deletion packages/@aws-cdk/aws-s3/test/test.bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1725,5 +1725,51 @@ export = {
// THEN
new Bucket(stack, 'b', { encryptionKey: key });
test.done();
}
},

'Bucket with Server Access Logs'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
const accessLogBucket = new Bucket(stack, 'AccessLogs');
new Bucket(stack, 'MyBucket', {
serverAccessLogsBucket: accessLogBucket,
});

// THEN
expect(stack).to(haveResource('AWS::S3::Bucket', {
LoggingConfiguration: {
DestinationBucketName: {
Ref: 'AccessLogs8B620ECA',
},
}
}));

test.done();
},

'Bucket with Server Access Logs with Prefix'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
const accessLogBucket = new Bucket(stack, 'AccessLogs');
new Bucket(stack, 'MyBucket', {
serverAccessLogsBucket: accessLogBucket,
serverAccessLogsPrefix: 'hello',
});

// THEN
expect(stack).to(haveResource('AWS::S3::Bucket', {
LoggingConfiguration: {
DestinationBucketName: {
Ref: 'AccessLogs8B620ECA',
},
LogFilePrefix: 'hello'
}
}));

test.done();
},
};

0 comments on commit 6a44bfa

Please sign in to comment.