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

chore(kms): prefer new aliasArn to keyArn for getting arn of an alias #28197

Merged

Conversation

rafaelrcamargo
Copy link
Contributor

Motivation:

The current implementation of keyArn within the AWS CDK AWS KMS module returns the Key ARN for a key and an alias, which causes confusion for users expecting the Alias ARN. This PR aims to alleviate this confusion by providing clearer access to the Alias ARN.

Changes:

Introducing a new attribute aliasArn that mirrors the value from keyArn specifically for aliases to explicitly retrieve the Alias ARN.

/**
 * The ARN of the alias.
 *
 * @attribute
 * @deprecated use `aliasArn` instead
 */
public get keyArn(): string {
  return Stack.of(this).formatArn({
    service: 'kms',
    // aliasName already contains the '/'
    resource: this.aliasName,
  });
}

/**
 * The ARN of the alias.
 *
 * @attribute
 */
public get aliasArn(): string {
  return this.keyArn;
}

Query:

Should we deprecate the existing keyArn and mirror it in aliasArn or change the logic within keyArn to aliasArn and use the keyArn as the mirror?

Your feedback on the preferred approach would be greatly appreciated!

Closes #28105.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Nov 30, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 30, 2023 02:22
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Nov 30, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@daschaa
Copy link
Contributor

daschaa commented Nov 30, 2023

@rafaelrcamargo Thanks for opening up a pull request! I think it's good to add the deprecation warning.
One small remark: Could you also add tests for the aliasArn getter? The current test just checks if it is the same value as keyArn, but if in the future the keyArn logic is changed, we should still test that the aliasArn returns a valid ARN.

@rafaelrcamargo
Copy link
Contributor Author

@daschaa for sure, makes sense. Are there any utils/helpers or recommended ways to test that in this project?

@daschaa
Copy link
Contributor

daschaa commented Dec 1, 2023

@rafaelrcamargo You can use Arn.format(...) to build an ARN for the assertion.

@rafaelrcamargo
Copy link
Contributor Author

rafaelrcamargo commented Dec 1, 2023

Awesome, followed the current implementation in the L2 construct.

Should I worry about this linter failing? Seems like some change convention.

If there's anything else I can help with, let me know

@daschaa
Copy link
Contributor

daschaa commented Dec 1, 2023

Thanks for the contribution. Looks good to me, so a maintainer can have a look :)

Can you add an exemption request for the integration test? Just add a comment with "Exemption request" and the reason why an integration test (and change to the README file) is not needed here.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-maintainer-review This PR needs a review from a Core Team Member labels Dec 1, 2023
@rafaelrcamargo
Copy link
Contributor Author

Exemption request: Integration test and README update not necessary for this PR. No new features have been introduced; the modification solely involves an existing property, which is already well-documented and thoroughly tested with relevant tests.

Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one nit and should be good to go.

I do not think this needs either integ tests or a readme update.

packages/aws-cdk-lib/aws-kms/lib/alias.ts Outdated Show resolved Hide resolved
@scanlonp scanlonp self-assigned this Dec 4, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 4, 2023
@scanlonp scanlonp changed the title feat: Deprecate keyArn and add aliasArn as the new attribute to get the ARN into the alias L2 construct chore(kms): prefer new aliasArn to keyArn for getting arn of an alias Dec 4, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 4, 2023 22:43

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@scanlonp scanlonp added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Dec 4, 2023
@mergify mergify bot dismissed scanlonp’s stale review December 5, 2023 14:59

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 5, 2023
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

mergify bot commented Dec 5, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 5, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 73b3902
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 6126413 into aws:main Dec 5, 2023
12 checks passed
Copy link
Contributor

mergify bot commented Dec 5, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

chenjane-dev pushed a commit to chenjane-dev/aws-cdk that referenced this pull request Dec 5, 2023
…lias (aws#28197)

**Motivation:**

The current implementation of `keyArn` within the AWS CDK AWS KMS module returns the Key ARN for a key and an alias, which causes confusion for users expecting the Alias ARN. This PR aims to alleviate this confusion by providing clearer access to the Alias ARN.

**Changes:**

Introducing a new attribute `aliasArn` that mirrors the value from `keyArn` specifically for aliases to explicitly retrieve the Alias ARN. 

```typescript
/**
 * The ARN of the alias.
 *
 * @Attribute
 * @deprecated use `aliasArn` instead
 */
public get keyArn(): string {
  return Stack.of(this).formatArn({
    service: 'kms',
    // aliasName already contains the '/'
    resource: this.aliasName,
  });
}

/**
 * The ARN of the alias.
 *
 * @Attribute
 */
public get aliasArn(): string {
  return this.keyArn;
}
```

**Query:**

Should we deprecate the existing `keyArn` and mirror it in `aliasArn` or change the logic within `keyArn` to `aliasArn` and use the `keyArn` as the mirror?

> Your feedback on the preferred approach would be greatly appreciated!

Closes aws#28105.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cdk-lib/aws-kms: No available option to get the a Alias ARN
4 participants