Skip to content

Commit

Permalink
chore(s3): use ICfnBucket
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Nov 28, 2023
1 parent 86ab734 commit 5351f76
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions packages/aws-cdk-lib/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IBucketNotificationDestination } from './destination';
import { BucketNotifications } from './notifications-resource';
import * as perms from './perms';
import { LifecycleRule } from './rule';
import { CfnBucket } from './s3.generated';
import { CfnBucket, ICfnBucket } from './s3.generated';
import { parseBucketArn, parseBucketName } from './util';
import * as events from '../../aws-events';
import * as iam from '../../aws-iam';
Expand Down Expand Up @@ -36,7 +36,7 @@ import * as regionInformation from '../../region-info';
const AUTO_DELETE_OBJECTS_RESOURCE_TYPE = 'Custom::S3AutoDeleteObjects';
const AUTO_DELETE_OBJECTS_TAG = 'aws-cdk:auto-delete-objects';

export interface IBucket extends IResource {
export interface IBucket extends IResource, ICfnBucket {
/**
* The ARN of the bucket.
* @attribute
Expand Down Expand Up @@ -498,7 +498,15 @@ export interface BucketAttributes {
*
*/
export abstract class BucketBase extends Resource implements IBucket {
public abstract readonly attrArn: string;
public abstract readonly attrBucketName?: string;
/**
* @deprecated use attrArn
*/
public abstract readonly bucketArn: string;
/**
* @deprecated use attrBucketName
*/
public abstract readonly bucketName: string;
public abstract readonly bucketDomainName: string;
public abstract readonly bucketWebsiteUrl: string;
Expand Down Expand Up @@ -1674,8 +1682,10 @@ export class Bucket extends BucketBase {
const websiteDomain = `${bucketName}.${staticDomainEndpoint}`;

class Import extends BucketBase {
public readonly bucketName = bucketName!;
public readonly bucketArn = parseBucketArn(scope, attrs);
public readonly attrArn = parseBucketArn(scope, attrs);
public readonly attrBucketName = bucketName!;
public readonly bucketName = this.attrBucketName;
public readonly bucketArn = this.attrArn;
public readonly bucketDomainName = attrs.bucketDomainName || `${bucketName}.s3.${urlSuffix}`;
public readonly bucketWebsiteUrl = attrs.bucketWebsiteUrl || `http://${websiteDomain}`;
public readonly bucketWebsiteDomainName = attrs.bucketWebsiteUrl ? Fn.select(2, Fn.split('/', attrs.bucketWebsiteUrl)) : websiteDomain;
Expand Down Expand Up @@ -1738,8 +1748,10 @@ export class Bucket extends BucketBase {
}

return new class extends BucketBase {
public readonly bucketArn = cfnBucket.attrArn;
public readonly bucketName = cfnBucket.ref;
public readonly attrArn = cfnBucket.attrArn;
public readonly bucketArn = this.attrArn;
public readonly attrBucketName = cfnBucket.ref;
public readonly bucketName = this.attrBucketName;
public readonly bucketDomainName = cfnBucket.attrDomainName;
public readonly bucketDualStackDomainName = cfnBucket.attrDualStackDomainName;
public readonly bucketRegionalDomainName = cfnBucket.attrRegionalDomainName;
Expand Down Expand Up @@ -1807,6 +1819,8 @@ export class Bucket extends BucketBase {
}
}

public readonly attrArn: string;
public readonly attrBucketName?: string;
public readonly bucketArn: string;
public readonly bucketName: string;
public readonly bucketDomainName: string;
Expand Down Expand Up @@ -1870,13 +1884,15 @@ export class Bucket extends BucketBase {
this.encryptionKey = encryptionKey;
this.eventBridgeEnabled = props.eventBridgeEnabled;

this.bucketName = this.getResourceNameAttribute(resource.ref);
this.bucketArn = this.getResourceArnAttribute(resource.attrArn, {
this.attrBucketName = this.getResourceNameAttribute(resource.ref);
this.bucketName = this.attrBucketName;
this.attrArn = this.getResourceArnAttribute(resource.attrArn, {
region: '',
account: '',
service: 's3',
resource: this.physicalName,
});
this.bucketArn = this.attrArn;

this.bucketDomainName = resource.attrDomainName;
this.bucketWebsiteUrl = resource.attrWebsiteUrl;
Expand Down

0 comments on commit 5351f76

Please sign in to comment.