in modules/branch-keystore-node/src/kms_config.ts [80:126]
constructor(config: KmsConfig) {
readOnlyProperty(this, '_config', config)
/* Precondition: config must be a string or object */
const configType = typeof config
needs(
!!config && (configType === 'object' || configType === 'string'),
'Config must be a `discovery` or an object.'
)
if (configType === 'string') {
/* Precondition: Only `discovery` is a valid string value */
needs(config === 'discovery', 'Unexpected config shape')
} else if (
'identifier' in (config as any) ||
'mrkIdentifier' in (config as any)
) {
const arn =
'identifier' in (config as any)
? (config as any).identifier
: (config as any).mrkIdentifier
/* Precondition: ARN must be a string */
needs(typeof arn === 'string', 'ARN must be a string')
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-kms-configuration
//# To be clear, an KMS ARN for a Multi-Region Key MAY be provided to the `KMS Key ARN` configuration,
//# and a KMS ARN for non Multi-Region Key MAY be provided to the `KMS MRKey ARN` configuration.
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-kms-configuration
//# This ARN MUST NOT be an Alias.
//# This ARN MUST be a valid
//# [AWS KMS Key ARN](./aws-kms/aws-kms-key-arn.md#a-valid-aws-kms-arn).
const parsedArn = parseAwsKmsKeyArn(arn)
needs(
parsedArn && parsedArn.ResourceType === 'key',
`${arn} must be a well-formed AWS KMS non-alias resource arn`
)
readOnlyProperty(this, '_parsedArn', parsedArn)
readOnlyProperty(this, '_arn', arn)
} else if ('region' in (config as any)) {
readOnlyProperty(this, '_mrkRegion', (config as any).region)
} else {
needs(false, 'Unexpected config shape')
}
Object.freeze(this)
}