aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 1.59 kB
JavaScript
;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},logs_generated_1=()=>{var tmp=require("../logs.generated");return logs_generated_1=()=>tmp,tmp};class LogGroupWithPolicyFactory{forResource(resource){return ifCfnLogGroup(resource,r=>new CfnLogGroupWithPolicy(r))}}class CfnLogGroupWithPolicy{logGroup;env;policy;policyDocument;constructor(logGroup){this.logGroup=logGroup,this.env=logGroup.env}addToResourcePolicy(statement){return this.policy||(this.policy=new(logs_generated_1()).CfnResourcePolicy(this.logGroup,"LogGroupPolicy",{policyDocument:JSON.stringify({Statement:[]}),policyName:core_1().Names.uniqueId(this.logGroup)})),this.policyDocument||(this.policyDocument=aws_iam_1().PolicyDocument.fromJson(JSON.parse(this.policy.policyDocument)??{Statement:[]})),this.policyDocument.addStatements(statement),this.policy.policyDocument=JSON.stringify(this.policyDocument.toJSON()),{statementAdded:!0,policyDependable:this.policy}}}function ifCfnLogGroup(resource,factory){if(!logs_generated_1().CfnLogGroup.isCfnLogGroup(resource))throw new(core_1()).ValidationError((0,literal_string_1().lit)`Construct`,`Construct ${resource.node.path} is not of type CfnLogGroup`,resource);return factory(resource)}aws_iam_1().DefaultPolicyFactories.set("AWS::Logs::LogGroup",new LogGroupWithPolicyFactory);