Skip to content

Commit

Permalink
bucket: versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 29, 2024
1 parent a73af4c commit 0fa4033
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions platform/src/components/aws/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ export interface BucketArgs {
* @default `true`
*/
cors?: Input<false | Prettify<BucketCorsArgs>>;
/**
* Enable versioning for the bucket.
*
* Bucket versioning enables you to store multiple versions of an object, protecting
* against accidental deletion or overwriting.
*
* @default Versioning disabled
* @example
* ```js
* {
* versioning: true
* }
* ```
*/
versioning?: Input<true>;
/**
* [Transform](/docs/components#transform) how this component creates its underlying
* resources.
Expand All @@ -176,6 +191,10 @@ export interface BucketArgs {
* Transform the S3 Bucket Policy resource.
*/
policy?: Transform<s3.BucketPolicyArgs>;
/**
* Transform the S3 Bucket versioning resource.
*/
versioning?: Transform<s3.BucketVersioningV2Args>;
/**
* Transform the public access block resource that's attached to the Bucket.
*
Expand Down Expand Up @@ -343,6 +362,7 @@ export class Bucket extends Component implements Link.Linkable {
const access = normalizeAccess();

const bucket = createBucket();
createVersioning();
const publicAccessBlock = createPublicAccess();
const policy = createBucketPolicy();
createCorsRule();
Expand Down Expand Up @@ -387,6 +407,24 @@ export class Bucket extends Component implements Link.Linkable {
return new s3.BucketV2(...transformed);
}

function createVersioning() {
if (!args.versioning) return;

return new s3.BucketVersioningV2(
...transform(
args.transform?.versioning,
`${name}Versioning`,
{
bucket: bucket.bucket,
versioningConfiguration: {
status: "Enabled",
},
},
{ parent },
),
);
}

function createPublicAccess() {
if (args.transform?.publicAccessBlock === false) return;

Expand Down
3 changes: 1 addition & 2 deletions platform/src/components/aws/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ export interface FunctionArgs {
/**
* Enable versioning for the function.
*
*
* @default false
* @default Versioning disabled
* @example
* ```js
* {
Expand Down
1 change: 1 addition & 0 deletions platform/src/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class Component extends ComponentResource {
"aws:s3/bucketObjectv2:BucketObjectv2",
"aws:s3/bucketPolicy:BucketPolicy",
"aws:s3/bucketPublicAccessBlock:BucketPublicAccessBlock",
"aws:s3/bucketVersioningV2:BucketVersioningV2",
"aws:s3/bucketWebsiteConfigurationV2:BucketWebsiteConfigurationV2",
"aws:ses/domainIdentityVerification:DomainIdentityVerification",
"aws:sesv2/emailIdentity:EmailIdentity",
Expand Down

0 comments on commit 0fa4033

Please sign in to comment.