Skip to content

Commit

Permalink
feat(sdk): add bucketDomainName to IAwsBucket and BucketRef (#7207)
Browse files Browse the repository at this point in the history
## Checklist

- [X] Title matches [Winglang's style
guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [X] Description explains motivation and solution
- [X] Tests added (always)
- [X] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end
testing

*By submitting this pull request, I confirm that my contribution is made
under the terms of the [Wing Cloud Contribution
License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.

---------

Signed-off-by: monada-bot[bot] <[email protected]>
Co-authored-by: monada-bot[bot] <[email protected]>
  • Loading branch information
ShaiBer and monadabot authored Oct 29, 2024
1 parent 1c4ba06 commit e37b943
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
26 changes: 26 additions & 0 deletions docs/api/04-standard-library/aws/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ NOTE: This statement must be executed within an async context.
| --- | --- | --- |
| <code><a href="#@winglang/sdk.aws.BucketRef.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
| <code><a href="#@winglang/sdk.aws.BucketRef.property.bucketArn">bucketArn</a></code> | <code>str</code> | The ARN of this bucket. |
| <code><a href="#@winglang/sdk.aws.BucketRef.property.bucketDomainName">bucketDomainName</a></code> | <code>str</code> | The domain name of this bucket. |
| <code><a href="#@winglang/sdk.aws.BucketRef.property.bucketName">bucketName</a></code> | <code>str</code> | The Name of this bucket. |

---
Expand Down Expand Up @@ -143,6 +144,18 @@ The ARN of this bucket.

---

##### `bucketDomainName`<sup>Required</sup> <a name="bucketDomainName" id="@winglang/sdk.aws.BucketRef.property.bucketDomainName"></a>

```wing
bucketDomainName: str;
```

- *Type:* str

The domain name of this bucket.

---

##### `bucketName`<sup>Required</sup> <a name="bucketName" id="@winglang/sdk.aws.BucketRef.property.bucketName"></a>

```wing
Expand Down Expand Up @@ -1605,6 +1618,7 @@ A shared interface for AWS buckets.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.aws.IAwsBucket.property.bucketArn">bucketArn</a></code> | <code>str</code> | AWS Bucket arn. |
| <code><a href="#@winglang/sdk.aws.IAwsBucket.property.bucketDomainName">bucketDomainName</a></code> | <code>str</code> | Bucket domain name. |
| <code><a href="#@winglang/sdk.aws.IAwsBucket.property.bucketName">bucketName</a></code> | <code>str</code> | AWS Bucket name. |

---
Expand All @@ -1621,6 +1635,18 @@ AWS Bucket arn.

---

##### `bucketDomainName`<sup>Required</sup> <a name="bucketDomainName" id="@winglang/sdk.aws.IAwsBucket.property.bucketDomainName"></a>

```wing
bucketDomainName: str;
```

- *Type:* str

Bucket domain name.

---

##### `bucketName`<sup>Required</sup> <a name="bucketName" id="@winglang/sdk.aws.IAwsBucket.property.bucketName"></a>

```wing
Expand Down
4 changes: 4 additions & 0 deletions packages/@winglang/platform-awscdk/src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ export class Bucket extends cloud.Bucket implements IAwsBucket {
public get bucketName(): string {
return this.bucket.bucketName;
}

public get bucketDomainName(): string {
return this.bucket.bucketDomainName;
}
}

export function createEncryptedBucket(
Expand Down
12 changes: 11 additions & 1 deletion packages/@winglang/sdk/src/shared-aws/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface IAwsBucket {
*/
readonly bucketArn: string;

/**
* Bucket domain name
*/
readonly bucketDomainName: string;

/**
* AWS Bucket name
*/
Expand Down Expand Up @@ -81,12 +86,17 @@ export class BucketRef extends Resource {
*/
public readonly bucketArn: string;

/**
* The domain name of this bucket.
*/
public readonly bucketDomainName: string;

constructor(scope: Construct, id: string, bucketName: string) {
super(scope, id);

this.bucketName = bucketName;
this.bucketArn = `arn:aws:s3:::${bucketName}`;

this.bucketDomainName = `${bucketName}.s3.amazonaws.com`;
const target = App.of(this)._target;
if (target === "sim") {
this.addUserInterface();
Expand Down
4 changes: 4 additions & 0 deletions packages/@winglang/sdk/src/target-tf-aws/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export class Bucket extends cloud.Bucket implements IAwsBucket {
public get bucketName(): string {
return this.bucket.bucket;
}

public get bucketDomainName(): string {
return this.bucket.bucketDomainName;
}
}

export function createEncryptedBucket(
Expand Down
3 changes: 3 additions & 0 deletions tests/sdk_tests/bucket/aws-bucket.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let getBucketInfo = (b: cloud.Bucket): Map<str>? => {
return {
bucketName: bucket.bucketName,
bucketArn: bucket.bucketArn,
bucketDomainName: bucket.bucketDomainName
};
}
return nil;
Expand All @@ -20,10 +21,12 @@ test "validates the AWS Bucket" {
if @target == "tf-aws" {
assert(bucket.get("bucketArn").contains("arn:aws:s3:::aws-wing-bucket"));
assert(bucket.get("bucketName").contains("aws-wing-bucket"));
assert(bucket.get("bucketDomainName").contains("aws-wing-bucket.s3.amazonaws.com"));
} else { // If it's not a 'tf-aws' target, it's an 'awscdk'
assert(bucket.get("bucketArn").contains("arn:aws:s3:::"));
assert(bucket.get("bucketArn").contains("awswingbucket"));
assert(bucket.get("bucketName").contains("awswingbucket"));
assert(bucket.get("bucketDomainName").contains("awswingbucket.s3.amazonaws.com"));
}
} else {
// If the test is not on AWS, it should not fail, so I am returning true.
Expand Down
1 change: 1 addition & 0 deletions tests/sdk_tests/bucket/bucket-ref.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if @target == "sim" {
test "bucketArn returns the arn" {
expect.equal(dummyArn, br.bucketArn);
expect.equal(dummyName, br.bucketName);
expect.equal(dummyName + ".s3.amazonaws.com", br.bucketDomainName);
}

test "get() sends a request to aws, fails because we are using a dummy bucket" {
Expand Down

0 comments on commit e37b943

Please sign in to comment.