Skip to content

Commit 6fc741d

Browse files
nvobilisseebees
authored andcommitted
fix(keystore): Fix kms config (#627)
* change kms config remove flag methods remove assertValidNotAliasArn function * less arn parsing util exports needed
1 parent c314752 commit 6fc741d

File tree

5 files changed

+12
-129
lines changed

5 files changed

+12
-129
lines changed

modules/branch-keystore-node/src/kms_config.ts

+11-33
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

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'
69

710
// a general interface that outlines common operations any of the 4 AWS KMS
811
// configurations should perform
912
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-
2813
/**
2914
* this method tells the user if the config is compatible with an arn
3015
* @param otherArn
@@ -56,26 +41,19 @@ export abstract class KmsKeyArnConfig implements RegionalKmsConfig {
5641
//# This ARN MUST NOT be an Alias.
5742
//# This ARN MUST be a valid
5843
//# [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+
6050
this._arn = arn
6151
}
6252

6353
getRegion(): string {
6454
return getRegionFromIdentifier(this._arn)
6555
}
6656

67-
isKmsKeyArn(): boolean {
68-
return true
69-
}
70-
71-
isMrDiscovery(): boolean {
72-
return false
73-
}
74-
75-
isDiscovery(): boolean {
76-
return false
77-
}
78-
7957
getArn(): string {
8058
return this._arn
8159
}

modules/branch-keystore-node/src/kms_config_helpers.ts

-20
This file was deleted.

modules/branch-keystore-node/test/kms_config.test.ts

-24
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ describe('Test kms config', () => {
4040
expect((config as RegionalKmsConfig).getRegion()).equals('us-west-2')
4141
})
4242

43-
it('Test isKmsKeyArn', () => {
44-
expect(config.isKmsKeyArn()).equals(true)
45-
})
46-
47-
it('Test isMrDiscovery', () => {
48-
expect(config.isMrDiscovery()).equals(false)
49-
})
50-
51-
it('Test isDiscovery', () => {
52-
expect(config.isDiscovery()).equals(false)
53-
})
54-
5543
it('Test getArn', () => {
5644
expect((config as KmsKeyArnConfig).getArn()).equals(WELL_FORMED_SRK_ARN)
5745
})
@@ -82,18 +70,6 @@ describe('Test kms config', () => {
8270
expect((config as RegionalKmsConfig).getRegion()).equals('us-west-2')
8371
})
8472

85-
it('Test isKmsKeyArn', () => {
86-
expect(config.isKmsKeyArn()).equals(true)
87-
})
88-
89-
it('Test isMrDiscovery', () => {
90-
expect(config.isMrDiscovery()).equals(false)
91-
})
92-
93-
it('Test isDiscovery', () => {
94-
expect(config.isDiscovery()).equals(false)
95-
})
96-
9773
it('Test getArn', () => {
9874
expect((config as KmsKeyArnConfig).getArn()).equals(WELL_FORMED_MRK_ARN)
9975
})

modules/branch-keystore-node/test/kms_config_helpers.test.ts

-46
This file was deleted.

modules/kms-keyring/src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
export * from './kms_client_supplier'
5-
export {
6-
getRegionFromIdentifier,
7-
parseAwsKmsKeyArn,
8-
ParsedAwsKmsKeyArn,
9-
isMultiRegionAwsKmsArn,
10-
} from './arn_parsing'
5+
export { getRegionFromIdentifier, parseAwsKmsKeyArn } from './arn_parsing'
116
export * from './kms_keyring'
127
export * from './kms_mrk_keyring'
138
export * from './kms_mrk_discovery_keyring'

0 commit comments

Comments
 (0)