Skip to content

Commit

Permalink
Merge branch 'main' into zhiwei/fix-no-tests-1-count
Browse files Browse the repository at this point in the history
  • Loading branch information
monadabot authored Nov 4, 2024
2 parents 7ad0c77 + ee1ab4b commit 2c2048c
Show file tree
Hide file tree
Showing 28 changed files with 693 additions and 37 deletions.
14 changes: 14 additions & 0 deletions docs/api/04-standard-library/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ let BucketProps = cloud.BucketProps{ ... };
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.BucketProps.property.cors">cors</a></code> | <code>bool</code> | Whether to add default cors configuration. |
| <code><a href="#@winglang/sdk.cloud.BucketProps.property.corsOptions">corsOptions</a></code> | <code><a href="#@winglang/sdk.cloud.BucketCorsOptions">BucketCorsOptions</a></code> | Custom cors configuration for the bucket. |
| <code><a href="#@winglang/sdk.cloud.BucketProps.property.forceDestroy">forceDestroy</a></code> | <code>bool</code> | Whether to allow the bucket to be deleted even if it is not empty. |
| <code><a href="#@winglang/sdk.cloud.BucketProps.property.public">public</a></code> | <code>bool</code> | Whether the bucket's objects should be publicly accessible. |

---
Expand Down Expand Up @@ -1130,6 +1131,19 @@ with the following options:

---

##### `forceDestroy`<sup>Optional</sup> <a name="forceDestroy" id="@winglang/sdk.cloud.BucketProps.property.forceDestroy"></a>

```wing
forceDestroy: bool;
```

- *Type:* bool
- *Default:* false

Whether to allow the bucket to be deleted even if it is not empty.

---

##### `public`<sup>Optional</sup> <a name="public" id="@winglang/sdk.cloud.BucketProps.property.public"></a>

```wing
Expand Down
7 changes: 5 additions & 2 deletions packages/@winglang/platform-awscdk/src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ export class Bucket extends cloud.Bucket implements IAwsBucket {

private readonly bucket: S3Bucket;
private readonly public: boolean;
private readonly forceDestroy: boolean;
private bucketDeployment?: BucketDeployment;

constructor(scope: Construct, id: string, props: cloud.BucketProps = {}) {
super(scope, id, props);

this.public = props.public ?? false;
this.forceDestroy = props.forceDestroy ?? false;

this.bucket = createEncryptedBucket(this, this.public);
this.bucket = createEncryptedBucket(this, this.public, this.forceDestroy);

if (props.cors ?? true) {
this.addCorsRule(
Expand Down Expand Up @@ -254,6 +256,7 @@ export class Bucket extends cloud.Bucket implements IAwsBucket {
export function createEncryptedBucket(
scope: Construct,
isPublic: boolean,
forceDestroy: boolean,
name: string = "Default"
): S3Bucket {
const isTestEnvironment = App.of(scope).isTestEnvironment;
Expand All @@ -270,6 +273,6 @@ export function createEncryptedBucket(
: BlockPublicAccess.BLOCK_ALL,
publicReadAccess: isPublic ? true : false,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: isTestEnvironment ? true : false,
autoDeleteObjects: isTestEnvironment || forceDestroy ? true : false,
});
}
2 changes: 1 addition & 1 deletion packages/@winglang/platform-awscdk/src/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Website extends cloud.Website implements IAwsWebsite {
constructor(scope: Construct, id: string, props: cloud.WebsiteProps) {
super(scope, id, props);

this.bucket = createEncryptedBucket(this, false, "WebsiteBucket");
this.bucket = createEncryptedBucket(this, false, false, "WebsiteBucket");

new BucketDeployment(this, "BucketWebsiteConfiguration", {
destinationBucket: this.bucket,
Expand Down
Loading

0 comments on commit 2c2048c

Please sign in to comment.