|
1 | 1 | // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 |
| -import { getRegionFromIdentifier } from '@aws-crypto/kms-keyring' |
5 |
| -import { assertValidNotAliasArn } from './kms_config_helpers' |
| 4 | +import { |
| 5 | + getRegionFromIdentifier, |
| 6 | + parseAwsKmsKeyArn, |
| 7 | +} from '@aws-crypto/kms-keyring' |
| 8 | +import { needs } from '@aws-crypto/material-management' |
6 | 9 |
|
7 | 10 | // a general interface that outlines common operations any of the 4 AWS KMS
|
8 | 11 | // configurations should perform
|
9 | 12 | export interface KmsConfig {
|
10 |
| - /** |
11 |
| - * this method tells the user if the config is SRK/MRK compatibility |
12 |
| - * @returns a flag answering the method's purpose |
13 |
| - */ |
14 |
| - isKmsKeyArn(): boolean |
15 |
| - |
16 |
| - /** |
17 |
| - * this method tells the user if the config is MrDiscovery |
18 |
| - * @returns a flag answering the method's purpose |
19 |
| - */ |
20 |
| - isMrDiscovery(): boolean |
21 |
| - |
22 |
| - /** |
23 |
| - * this method tells the user if the config is Discovery |
24 |
| - * @returns a flag answering the method's purpose |
25 |
| - */ |
26 |
| - isDiscovery(): boolean |
27 |
| - |
28 | 13 | /**
|
29 | 14 | * this method tells the user if the config is compatible with an arn
|
30 | 15 | * @param otherArn
|
@@ -56,26 +41,19 @@ export abstract class KmsKeyArnConfig implements RegionalKmsConfig {
|
56 | 41 | //# This ARN MUST NOT be an Alias.
|
57 | 42 | //# This ARN MUST be a valid
|
58 | 43 | //# [AWS KMS Key ARN](./aws-kms/aws-kms-key-arn.md#a-valid-aws-kms-arn).
|
59 |
| - assertValidNotAliasArn(arn) |
| 44 | + const parsedArn = parseAwsKmsKeyArn(arn) |
| 45 | + needs( |
| 46 | + parsedArn && parsedArn.ResourceType === 'key', |
| 47 | + `${arn} must be a well-formed AWS KMS non-alias resource arn` |
| 48 | + ) |
| 49 | + |
60 | 50 | this._arn = arn
|
61 | 51 | }
|
62 | 52 |
|
63 | 53 | getRegion(): string {
|
64 | 54 | return getRegionFromIdentifier(this._arn)
|
65 | 55 | }
|
66 | 56 |
|
67 |
| - isKmsKeyArn(): boolean { |
68 |
| - return true |
69 |
| - } |
70 |
| - |
71 |
| - isMrDiscovery(): boolean { |
72 |
| - return false |
73 |
| - } |
74 |
| - |
75 |
| - isDiscovery(): boolean { |
76 |
| - return false |
77 |
| - } |
78 |
| - |
79 | 57 | getArn(): string {
|
80 | 58 | return this._arn
|
81 | 59 | }
|
|
0 commit comments