Skip to content

Commit

Permalink
feat(kms): allow fromLookup method to return dummy key if target ke…
Browse files Browse the repository at this point in the history
…y was not found (#31676)

### Issue # (if applicable)

Closes #31574.

### Reason for this change



The `fromLookup` method causes an error if the target key was not found. However it would be also good not to cause an error in that case. 

### Description of changes



Added `returnDummyKeyOnMissing` in `KeyLookupOptions`. If the property is set to true, the context method will not cause an error and will return a dummy key if the key was not found.

Originally, I thought to make the method to return undefined in that case, but the return type of method is `IKey`. If we change the type to `IKey | undefined`, it should be a breaking change.

```ts
  public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions): IKey {
```

So I decided to return a dummy key with a dummy key id '1234abcd-12ab-34cd-56ef-1234567890ab'. The dummy key id had been defined originally (see: https://github.com/aws/aws-cdk/blob/v2.161.0/packages/aws-cdk-lib/aws-kms/lib/key.ts#L686).

The property `returnDummyKeyOnMissing` will be passed to `ignoreErrorOnMissingContext` added in the [PR](#31415). If the `ignoreErrorOnMissingContext` is true and the key doesn't exist, an error will be suppressed in the `ContextProvider`.

### Additional information

see: #31574 (comment)

### Description of how you validated changes



Both of unit and integ tests

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
go-to-k authored Oct 17, 2024
1 parent 3d650c3 commit 34bdeca
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"Outputs": {
"KeyId": {
"Value": "1234abcd-12ab-34cd-56ef-1234567890ab"
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 34bdeca

Please sign in to comment.