1 | ;
|
2 | var _a;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.Alias = void 0;
|
5 | const jsiiDeprecationWarnings = require("../.warnings.jsii.js");
|
6 | const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
|
7 | const iam = require("@aws-cdk/aws-iam");
|
8 | const core_1 = require("@aws-cdk/core");
|
9 | const kms_generated_1 = require("./kms.generated");
|
10 | const REQUIRED_ALIAS_PREFIX = 'alias/';
|
11 | const DISALLOWED_PREFIX = REQUIRED_ALIAS_PREFIX + 'aws/';
|
12 | class AliasBase extends core_1.Resource {
|
13 | get keyArn() {
|
14 | return core_1.Stack.of(this).formatArn({
|
15 | service: 'kms',
|
16 | // aliasName already contains the '/'
|
17 | resource: this.aliasName,
|
18 | });
|
19 | }
|
20 | get keyId() {
|
21 | return this.aliasName;
|
22 | }
|
23 | addAlias(alias) {
|
24 | return this.aliasTargetKey.addAlias(alias);
|
25 | }
|
26 | addToResourcePolicy(statement, allowNoOp) {
|
27 | return this.aliasTargetKey.addToResourcePolicy(statement, allowNoOp);
|
28 | }
|
29 | grant(grantee, ...actions) {
|
30 | return this.aliasTargetKey.grant(grantee, ...actions);
|
31 | }
|
32 | grantDecrypt(grantee) {
|
33 | return this.aliasTargetKey.grantDecrypt(grantee);
|
34 | }
|
35 | grantEncrypt(grantee) {
|
36 | return this.aliasTargetKey.grantEncrypt(grantee);
|
37 | }
|
38 | grantEncryptDecrypt(grantee) {
|
39 | return this.aliasTargetKey.grantEncryptDecrypt(grantee);
|
40 | }
|
41 | }
|
42 | /**
|
43 | * Defines a display name for a customer master key (CMK) in AWS Key Management
|
44 | * Service (AWS KMS). Using an alias to refer to a key can help you simplify key
|
45 | * management. For example, when rotating keys, you can just update the alias
|
46 | * mapping instead of tracking and changing key IDs. For more information, see
|
47 | * Working with Aliases in the AWS Key Management Service Developer Guide.
|
48 | *
|
49 | * You can also add an alias for a key by calling `key.addAlias(alias)`.
|
50 | *
|
51 | * @resource AWS::KMS::Alias
|
52 | */
|
53 | class Alias extends AliasBase {
|
54 | constructor(scope, id, props) {
|
55 | try {
|
56 | jsiiDeprecationWarnings._aws_cdk_aws_kms_AliasProps(props);
|
57 | }
|
58 | catch (error) {
|
59 | if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
|
60 | Error.captureStackTrace(error, Alias);
|
61 | }
|
62 | throw error;
|
63 | }
|
64 | let aliasName = props.aliasName;
|
65 | if (!core_1.Token.isUnresolved(aliasName)) {
|
66 | if (!aliasName.startsWith(REQUIRED_ALIAS_PREFIX)) {
|
67 | aliasName = REQUIRED_ALIAS_PREFIX + aliasName;
|
68 | }
|
69 | if (aliasName === REQUIRED_ALIAS_PREFIX) {
|
70 | throw new Error(`Alias must include a value after "${REQUIRED_ALIAS_PREFIX}": ${aliasName}`);
|
71 | }
|
72 | if (aliasName.toLocaleLowerCase().startsWith(DISALLOWED_PREFIX)) {
|
73 | throw new Error(`Alias cannot start with ${DISALLOWED_PREFIX}: ${aliasName}`);
|
74 | }
|
75 | if (!aliasName.match(/^[a-zA-Z0-9:/_-]{1,256}$/)) {
|
76 | throw new Error('Alias name must be between 1 and 256 characters in a-zA-Z0-9:/_-');
|
77 | }
|
78 | }
|
79 | super(scope, id, {
|
80 | physicalName: aliasName,
|
81 | });
|
82 | this.aliasTargetKey = props.targetKey;
|
83 | const resource = new kms_generated_1.CfnAlias(this, 'Resource', {
|
84 | aliasName: this.physicalName,
|
85 | targetKeyId: this.aliasTargetKey.keyArn,
|
86 | });
|
87 | this.aliasName = this.getResourceNameAttribute(resource.aliasName);
|
88 | if (props.removalPolicy) {
|
89 | resource.applyRemovalPolicy(props.removalPolicy);
|
90 | }
|
91 | }
|
92 | /**
|
93 | * Import an existing KMS Alias defined outside the CDK app.
|
94 | *
|
95 | * @param scope The parent creating construct (usually `this`).
|
96 | * @param id The construct's name.
|
97 | * @param attrs the properties of the referenced KMS Alias
|
98 | */
|
99 | static fromAliasAttributes(scope, id, attrs) {
|
100 | try {
|
101 | jsiiDeprecationWarnings._aws_cdk_aws_kms_AliasAttributes(attrs);
|
102 | }
|
103 | catch (error) {
|
104 | if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
|
105 | Error.captureStackTrace(error, this.fromAliasAttributes);
|
106 | }
|
107 | throw error;
|
108 | }
|
109 | class _Alias extends AliasBase {
|
110 | get aliasName() { return attrs.aliasName; }
|
111 | get aliasTargetKey() { return attrs.aliasTargetKey; }
|
112 | }
|
113 | return new _Alias(scope, id);
|
114 | }
|
115 | /**
|
116 | * Import an existing KMS Alias defined outside the CDK app, by the alias name. This method should be used
|
117 | * instead of 'fromAliasAttributes' when the underlying KMS Key ARN is not available.
|
118 | * This Alias will not have a direct reference to the KMS Key, so addAlias and grant* methods are not supported.
|
119 | *
|
120 | * @param scope The parent creating construct (usually `this`).
|
121 | * @param id The construct's name.
|
122 | * @param aliasName The full name of the KMS Alias (e.g., 'alias/aws/s3', 'alias/myKeyAlias').
|
123 | */
|
124 | static fromAliasName(scope, id, aliasName) {
|
125 | class Import extends core_1.Resource {
|
126 | constructor() {
|
127 | super(...arguments);
|
128 | this.keyArn = core_1.Stack.of(this).formatArn({ service: 'kms', resource: aliasName });
|
129 | this.keyId = aliasName;
|
130 | this.aliasName = aliasName;
|
131 | }
|
132 | get aliasTargetKey() { throw new Error('Cannot access aliasTargetKey on an Alias imported by Alias.fromAliasName().'); }
|
133 | addAlias(_alias) { throw new Error('Cannot call addAlias on an Alias imported by Alias.fromAliasName().'); }
|
134 | addToResourcePolicy(_statement, _allowNoOp) {
|
135 | return { statementAdded: false };
|
136 | }
|
137 | grant(grantee, ..._actions) { return iam.Grant.drop(grantee, ''); }
|
138 | grantDecrypt(grantee) { return iam.Grant.drop(grantee, ''); }
|
139 | grantEncrypt(grantee) { return iam.Grant.drop(grantee, ''); }
|
140 | grantEncryptDecrypt(grantee) { return iam.Grant.drop(grantee, ''); }
|
141 | }
|
142 | return new Import(scope, id);
|
143 | }
|
144 | generatePhysicalName() {
|
145 | return REQUIRED_ALIAS_PREFIX + super.generatePhysicalName();
|
146 | }
|
147 | }
|
148 | exports.Alias = Alias;
|
149 | _a = JSII_RTTI_SYMBOL_1;
|
150 | Alias[_a] = { fqn: "@aws-cdk/aws-kms.Alias", version: "1.197.0" };
|
151 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxpYXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJhbGlhcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSx3Q0FBd0M7QUFDeEMsd0NBQXNFO0FBR3RFLG1EQUEyQztBQUUzQyxNQUFNLHFCQUFxQixHQUFHLFFBQVEsQ0FBQztBQUN2QyxNQUFNLGlCQUFpQixHQUFHLHFCQUFxQixHQUFHLE1BQU0sQ0FBQztBQWdEekQsTUFBZSxTQUFVLFNBQVEsZUFBUTtJQUt2QyxJQUFXLE1BQU07UUFDZixPQUFPLFlBQUssQ0FBQyxFQUFFLENBQUMsSUFBSSxDQUFDLENBQUMsU0FBUyxDQUFDO1lBQzlCLE9BQU8sRUFBRSxLQUFLO1lBQ2QscUNBQXFDO1lBQ3JDLFFBQVEsRUFBRSxJQUFJLENBQUMsU0FBUztTQUN6QixDQUFDLENBQUM7S0FDSjtJQUVELElBQVcsS0FBSztRQUNkLE9BQU8sSUFBSSxDQUFDLFNBQVMsQ0FBQztLQUN2QjtJQUVNLFFBQVEsQ0FBQyxLQUFhO1FBQzNCLE9BQU8sSUFBSSxDQUFDLGNBQWMsQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUFDLENBQUM7S0FDNUM7SUFFTSxtQkFBbUIsQ0FBQyxTQUE4QixFQUFFLFNBQW1CO1FBQzVFLE9BQU8sSUFBSSxDQUFDLGNBQWMsQ0FBQyxtQkFBbUIsQ0FBQyxTQUFTLEVBQUUsU0FBUyxDQUFDLENBQUM7S0FDdEU7SUFFTSxLQUFLLENBQUM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