Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): add bucketDomainName to IAwsBucket and BucketRef #7207

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading