"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.S3SourceAction=exports.S3Trigger=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),codepipeline=require("../../../aws-codepipeline"),targets=require("../../../aws-events-targets"),core_1=require("../../../core"),action_1=require("../action"),common_1=require("../common");var S3Trigger;(function(S3Trigger2){S3Trigger2.NONE="None",S3Trigger2.POLL="Poll",S3Trigger2.EVENTS="Events"})(S3Trigger||(exports.S3Trigger=S3Trigger={}));class S3SourceAction extends action_1.Action{constructor(props){super({...props,resource:props.bucket,category:codepipeline.ActionCategory.SOURCE,provider:"S3",artifactBounds:(0,common_1.sourceArtifactBounds)(),outputs:[props.output]});try{jsiiDeprecationWarnings.aws_cdk_lib_aws_codepipeline_actions_S3SourceActionProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,S3SourceAction),error}if(props.bucketKey.length===0)throw new Error("Property bucketKey cannot be an empty string");this.props=props}get variables(){return{versionId:this.variableExpression("VersionId"),eTag:this.variableExpression("ETag")}}bound(_scope,stage,options){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_codepipeline_IStage(stage),jsiiDeprecationWarnings.aws_cdk_lib_aws_codepipeline_ActionBindOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bound),error}if(this.props.trigger===S3Trigger.EVENTS){const id=this.generateEventId(stage);this.props.bucket.onCloudTrailWriteObject(id,{target:new targets.CodePipeline(stage.pipeline),paths:[this.props.bucketKey],crossStackScope:stage.pipeline})}return this.props.bucket.grantRead(options.role,this.props.bucketKey),options.bucket.grantWrite(options.role),{configuration:{S3Bucket:this.props.bucket.bucketName,S3ObjectKey:this.props.bucketKey,PollForSourceChanges:this.props.trigger&&this.props.trigger===S3Trigger.POLL}}}generateEventId(stage){let ret;const baseId=core_1.Names.nodeUniqueId(stage.pipeline.node)+"SourceEventRule";if(core_1.Token.isUnresolved(this.props.bucketKey)){let candidate=baseId,counter=0;for(;this.props.bucket.node.tryFindChild(candidate)!==void 0;)counter+=1,candidate=baseId+counter;ret=candidate}else if(ret=baseId+this.props.bucketKey,this.props.bucket.node.tryFindChild(ret))throw new Error(`S3 source action with path '${this.props.bucketKey}' is already present in the pipeline for this source bucket`);return ret}}exports.S3SourceAction=S3SourceAction,_a=JSII_RTTI_SYMBOL_1,S3SourceAction[_a]={fqn:"aws-cdk-lib.aws_codepipeline_actions.S3SourceAction",version:"2.96.1"};
