Skip to content

Commit 34bdeca

Browse files
authored
feat(kms): allow fromLookup method to return dummy key if target key 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*
1 parent 3d650c3 commit 34bdeca

16 files changed

+552
-3
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/integ.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/key-from-lookup-dummy.assets.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"Outputs": {
3+
"KeyId": {
4+
"Value": "1234abcd-12ab-34cd-56ef-1234567890ab"
5+
}
6+
},
7+
"Parameters": {
8+
"BootstrapVersion": {
9+
"Type": "AWS::SSM::Parameter::Value<String>",
10+
"Default": "/cdk-bootstrap/hnb659fds/version",
11+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
12+
}
13+
},
14+
"Rules": {
15+
"CheckBootstrapVersion": {
16+
"Assertions": [
17+
{
18+
"Assert": {
19+
"Fn::Not": [
20+
{
21+
"Fn::Contains": [
22+
[
23+
"1",
24+
"2",
25+
"3",
26+
"4",
27+
"5"
28+
],
29+
{
30+
"Ref": "BootstrapVersion"
31+
}
32+
]
33+
}
34+
]
35+
},
36+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
37+
}
38+
]
39+
}
40+
}
41+
}

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/keyfromlookupdummyintegDefaultTestDeployAssert59B83056.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/keyfromlookupdummyintegDefaultTestDeployAssert59B83056.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/manifest.json

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-kms/test/integ.key-from-lookup-dummy.js.snapshot/tree.json

+117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)