"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BackupVault=exports.BackupVaultEvents=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),iam=require("../../aws-iam"),core_1=require("../../core"),backup_generated_1=require("./backup.generated");var BackupVaultEvents;(function(BackupVaultEvents2){BackupVaultEvents2.BACKUP_JOB_STARTED="BACKUP_JOB_STARTED",BackupVaultEvents2.BACKUP_JOB_COMPLETED="BACKUP_JOB_COMPLETED",BackupVaultEvents2.BACKUP_JOB_SUCCESSFUL="BACKUP_JOB_SUCCESSFUL",BackupVaultEvents2.BACKUP_JOB_FAILED="BACKUP_JOB_FAILED",BackupVaultEvents2.BACKUP_JOB_EXPIRED="BACKUP_JOB_EXPIRED",BackupVaultEvents2.RESTORE_JOB_STARTED="RESTORE_JOB_STARTED",BackupVaultEvents2.RESTORE_JOB_COMPLETED="RESTORE_JOB_COMPLETED",BackupVaultEvents2.RESTORE_JOB_SUCCESSFUL="RESTORE_JOB_SUCCESSFUL",BackupVaultEvents2.RESTORE_JOB_FAILED="RESTORE_JOB_FAILED",BackupVaultEvents2.COPY_JOB_STARTED="COPY_JOB_STARTED",BackupVaultEvents2.COPY_JOB_SUCCESSFUL="COPY_JOB_SUCCESSFUL",BackupVaultEvents2.COPY_JOB_FAILED="COPY_JOB_FAILED",BackupVaultEvents2.RECOVERY_POINT_MODIFIED="RECOVERY_POINT_MODIFIED",BackupVaultEvents2.BACKUP_PLAN_CREATED="BACKUP_PLAN_CREATED",BackupVaultEvents2.BACKUP_PLAN_MODIFIED="BACKUP_PLAN_MODIFIED"})(BackupVaultEvents=exports.BackupVaultEvents||(exports.BackupVaultEvents={}));class BackupVaultBase extends core_1.Resource{grant(grantee,...actions){for(const action of actions)if(action.indexOf("*")>=0)throw new Error("AWS Backup access policies don't support a wildcard in the Action key.");return iam.Grant.addToPrincipal({grantee,actions,resourceArns:[this.backupVaultArn]})}}class BackupVault extends BackupVaultBase{constructor(scope,id,props={}){var _b;super(scope,id);if(jsiiDeprecationWarnings.aws_cdk_lib_aws_backup_BackupVaultProps(props),props.backupVaultName&&!/^[a-zA-Z0-9\-_]{2,50}$/.test(props.backupVaultName))throw new Error("Expected vault name to match pattern `^[a-zA-Z0-9-_]{2,50}$`");let notifications;props.notificationTopic&&(notifications={backupVaultEvents:props.notificationEvents||Object.values(BackupVaultEvents),snsTopicArn:props.notificationTopic.topicArn},props.notificationTopic.grantPublish(new iam.ServicePrincipal("backup.amazonaws.com"))),this.accessPolicy=(_b=props.accessPolicy)!==null&&_b!==void 0?_b:new iam.PolicyDocument,props.blockRecoveryPointDeletion&&this.blockRecoveryPointDeletion();const vault=new backup_generated_1.CfnBackupVault(this,"Resource",{backupVaultName:props.backupVaultName||this.uniqueVaultName(),accessPolicy:core_1.Lazy.any({produce:()=>this.accessPolicy.toJSON()}),encryptionKeyArn:props.encryptionKey&&props.encryptionKey.keyArn,notifications});vault.applyRemovalPolicy(props.removalPolicy),this.backupVaultName=vault.attrBackupVaultName,this.backupVaultArn=vault.attrBackupVaultArn}static fromBackupVaultName(scope,id,backupVaultName){const backupVaultArn=core_1.Stack.of(scope).formatArn({service:"backup",resource:"backup-vault",resourceName:backupVaultName,arnFormat:core_1.ArnFormat.COLON_RESOURCE_NAME});return BackupVault.fromBackupVaultArn(scope,id,backupVaultArn)}static fromBackupVaultArn(scope,id,backupVaultArn){const parsedArn=core_1.Stack.of(scope).splitArn(backupVaultArn,core_1.ArnFormat.SLASH_RESOURCE_NAME);if(!parsedArn.resourceName)throw new Error(`Backup Vault Arn ${backupVaultArn} does not have a resource name.`);class Import extends BackupVaultBase{constructor(){super(...arguments);this.backupVaultName=parsedArn.resourceName,this.backupVaultArn=backupVaultArn}}return new Import(scope,id,{account:parsedArn.account,region:parsedArn.region})}addToAccessPolicy(statement){jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_PolicyStatement(statement),this.accessPolicy.addStatements(statement)}blockRecoveryPointDeletion(){this.addToAccessPolicy(new iam.PolicyStatement({effect:iam.Effect.DENY,actions:["backup:DeleteRecoveryPoint","backup:UpdateRecoveryPointLifecycle"],principals:[new iam.AnyPrincipal],resources:["*"]}))}uniqueVaultName(){const id=core_1.Names.uniqueId(this);return id.substring(Math.max(id.length-50,0),id.length)}}exports.BackupVault=BackupVault,_a=JSII_RTTI_SYMBOL_1,BackupVault[_a]={fqn:"aws-cdk-lib.aws_backup.BackupVault",version:"2.13.0"};
//# sourceMappingURL=vault.js.map
