UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 5.65 kB
"use strict";var _a,_b;Object.defineProperty(exports,"__esModule",{value:!0}),exports.MissingRemovalPolicies=exports.RemovalPolicies=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var annotations_1=()=>{var tmp=require("./annotations");return annotations_1=()=>tmp,tmp},aspect_1=()=>{var tmp=require("./aspect");return aspect_1=()=>tmp,tmp},cfn_resource_1=()=>{var tmp=require("./cfn-resource");return cfn_resource_1=()=>tmp,tmp},removal_policy_1=()=>{var tmp=require("./removal-policy");return removal_policy_1=()=>tmp,tmp};class BaseRemovalPolicyAspect{constructor(policy,props={}){this.policy=policy,this.props=props}resourceTypeMatchesPatterns(resourceType,patterns){return!patterns||patterns.length===0?!1:patterns.includes(resourceType)}visit(node){if(!cfn_resource_1().CfnResource.isCfnResource(node))return;const cfnResource=node,resourceType=cfnResource.cfnResourceType;this.resourceTypeMatchesPatterns(resourceType,this.props.excludeResourceTypes)||this.props.applyToResourceTypes?.length&&!this.resourceTypeMatchesPatterns(resourceType,this.props.applyToResourceTypes)||this.shouldApplyPolicy(cfnResource)&&cfnResource.applyRemovalPolicy(this.policy)}}class RemovalPolicyAspect extends BaseRemovalPolicyAspect{shouldApplyPolicy(_cfnResource){return!0}}class MissingRemovalPolicyAspect extends BaseRemovalPolicyAspect{shouldApplyPolicy(cfnResource){return!(cfnResource.cfnOptions.deletionPolicy!==void 0||cfnResource.cfnOptions.updateReplacePolicy!==void 0)}}class RemovalPolicies{static of(scope){return new RemovalPolicies(scope)}constructor(scope){this.scope=scope}apply(policy,props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicy(policy),jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.apply),error}aspect_1().Aspects.of(this.scope).add(new RemovalPolicyAspect(policy,props),{priority:props.priority??aspect_1().AspectPriority.MUTATING})}destroy(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.destroy),error}this.apply(removal_policy_1().RemovalPolicy.DESTROY,props)}retain(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.retain),error}this.apply(removal_policy_1().RemovalPolicy.RETAIN,props)}snapshot(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.snapshot),error}this.apply(removal_policy_1().RemovalPolicy.SNAPSHOT,props)}retainOnUpdateOrDelete(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.retainOnUpdateOrDelete),error}this.apply(removal_policy_1().RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE,props)}}exports.RemovalPolicies=RemovalPolicies,_a=JSII_RTTI_SYMBOL_1,RemovalPolicies[_a]={fqn:"aws-cdk-lib.RemovalPolicies",version:"2.185.0"};class MissingRemovalPolicies{static of(scope){return new MissingRemovalPolicies(scope)}constructor(scope){this.scope=scope}apply(policy,props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicy(policy),jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.apply),error}aspect_1().Aspects.of(this.scope).add(new MissingRemovalPolicyAspect(policy,props),{priority:props.priority??aspect_1().AspectPriority.MUTATING}),props.priority!==void 0&&annotations_1().Annotations.of(this.scope).addWarningV2(`Warning MissingRemovalPolicies with priority in ${this.scope.node.path}`,"Applying a MissingRemovalPolicy with `priority` can lead to unexpected behavior since it only applies to resources without existing policies. Please refer to the documentation for more details.")}destroy(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.destroy),error}this.apply(removal_policy_1().RemovalPolicy.DESTROY,props)}retain(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.retain),error}this.apply(removal_policy_1().RemovalPolicy.RETAIN,props)}snapshot(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.snapshot),error}this.apply(removal_policy_1().RemovalPolicy.SNAPSHOT,props)}retainOnUpdateOrDelete(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.retainOnUpdateOrDelete),error}this.apply(removal_policy_1().RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE,props)}}exports.MissingRemovalPolicies=MissingRemovalPolicies,_b=JSII_RTTI_SYMBOL_1,MissingRemovalPolicies[_b]={fqn:"aws-cdk-lib.MissingRemovalPolicies",version:"2.185.0"};