UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 1.27 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var aws_iam_1=()=>{var tmp=require("../../../aws-iam");return aws_iam_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp},kms_generated_1=()=>{var tmp=require("../kms.generated");return kms_generated_1=()=>tmp,tmp};class KeyWithPolicyFactory{forResource(resource){if(!kms_generated_1().CfnKey.isCfnKey(resource))throw new(core_1()).ValidationError((0,literal_string_1().lit)`Construct`,`Construct ${resource.node.path} is not of type CfnKey`,resource);return new CfnKeyWithPolicy(resource)}}class CfnKeyWithPolicy{key;env;policyDocument;constructor(key){this.key=key,this.env=key.env}addToResourcePolicy(statement){return core_1().Token.isResolved(this.key.keyPolicy)?(this.policyDocument==null&&(this.policyDocument=aws_iam_1().PolicyDocument.fromJson(this.key.keyPolicy??{Statement:[]})),this.policyDocument.addStatements(statement),this.key.keyPolicy=this.policyDocument.toJSON(),{statementAdded:!0,policyDependable:this.policyDocument}):{statementAdded:!1}}}aws_iam_1().DefaultPolicyFactories.set("AWS::KMS::Key",new KeyWithPolicyFactory);