"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.S3SourceAction=exports.S3Trigger=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var codepipeline=()=>{var tmp=require("../../../aws-codepipeline");return codepipeline=()=>tmp,tmp},targets=()=>{var tmp=require("../../../aws-events-targets");return targets=()=>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},action_1=()=>{var tmp=require("../action");return action_1=()=>tmp,tmp},common_1=()=>{var tmp=require("../common");return common_1=()=>tmp,tmp},S3Trigger;(function(S3Trigger2){S3Trigger2.NONE="None",S3Trigger2.POLL="Poll",S3Trigger2.EVENTS="Events"})(S3Trigger||(exports.S3Trigger=S3Trigger={}));class S3SourceAction extends action_1().Action{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_codepipeline_actions.S3SourceAction",version:"2.256.1"};props;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(core_1()).UnscopedValidationError((0,literal_string_1().lit)`PropertyBucketkeyCannotEmpty`,"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(core_1()).UnscopedValidationError((0,literal_string_1().lit)`SourceActionPathAlready`,`S3 source action with path '${this.props.bucketKey}' is already present in the pipeline for this source bucket`);return ret}}exports.S3SourceAction=S3SourceAction;
