UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 14.3 kB
"use strict";var __runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventBusPolicy=exports.EventBus=exports.Level=exports.IncludeDetail=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var archive_1=()=>{var tmp=require("./archive");return archive_1=()=>tmp,tmp},events_grants_generated_1=()=>{var tmp=require("./events-grants.generated");return events_grants_generated_1=()=>tmp,tmp},events_generated_1=()=>{var tmp=require("./events.generated");return events_generated_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},cxapi=()=>{var tmp=require("../../cx-api");return cxapi=()=>tmp,tmp},IncludeDetail;(function(IncludeDetail2){IncludeDetail2.FULL="FULL",IncludeDetail2.NONE="NONE"})(IncludeDetail||(exports.IncludeDetail=IncludeDetail={}));var Level;(function(Level2){Level2.INFO="INFO",Level2.ERROR="ERROR",Level2.TRACE="TRACE",Level2.OFF="OFF"})(Level||(exports.Level=Level={}));class EventBusBase extends core_1().Resource{grants=events_grants_generated_1().EventBusGrants.fromEventBus(this);get eventBusRef(){return{eventBusArn:this.eventBusArn,eventBusName:this.eventBusName}}archive(id,props){return new(archive_1()).Archive(this,id,{sourceEventBus:this,description:props.description||`Event Archive for ${this.eventBusName} Event Bus`,eventPattern:props.eventPattern,retention:props.retention,archiveName:props.archiveName})}grantPutEventsTo(grantee,sid){const actions=["events:PutEvents"],resourceArns=[this.eventBusArn],options={grantee,actions,resourceArns:[this.eventBusArn]},grantResult=iam().Grant.addToPrincipal(options);if(grantResult.success)return grantResult;if(core_1().FeatureFlags.of(this).isEnabled(cxapi().EVENTBUS_POLICY_SID_REQUIRED)){const statement=new(iam()).PolicyStatement({actions,resources:resourceArns,principals:[grantee.grantPrincipal],sid});return iam().Grant.addStatementToResourcePolicy({...options,statement,resource:this})}else return core_1().Annotations.of(this).addWarningV2("@aws-cdk/aws-events:eventBusServicePrincipalGrant","Unable to grant PutEvents to service principal: Statement ID is required for EventBus resource policies. Either provide a 'sid' parameter or enable the '@aws-cdk/aws-events:requireEventBusPolicySid' feature flag."),iam().Grant.drop(grantee,"")}}let EventBus=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=EventBusBase,_instanceExtraInitializers=[],_addToResourcePolicy_decorators;var EventBus2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_addToResourcePolicy_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_addToResourcePolicy_decorators,{kind:"method",name:"addToResourcePolicy",static:!1,private:!1,access:{has:obj=>"addToResourcePolicy"in obj,get:obj=>obj.addToResourcePolicy},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),EventBus2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_events.EventBus",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-events.EventBus";static fromEventBusArn(scope,id,eventBusArn){const parts=core_1().Stack.of(scope).splitArn(eventBusArn,core_1().ArnFormat.SLASH_RESOURCE_NAME);return new ImportedEventBus(scope,id,{eventBusArn,eventBusName:parts.resourceName||"",eventBusPolicy:""})}static fromEventBusName(scope,id,eventBusName){const eventBusArn=core_1().Stack.of(scope).formatArn({resource:"event-bus",service:"events",resourceName:eventBusName});return EventBus2.fromEventBusAttributes(scope,id,{eventBusName,eventBusArn,eventBusPolicy:""})}static fromEventBusAttributes(scope,id,attrs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_events_EventBusAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromEventBusAttributes),error}return new ImportedEventBus(scope,id,attrs)}static grantPutEvents(grantee){return iam().Grant.addToPrincipal({grantee,actions:["events:PutEvents"],resourceArns:["*"]})}static grantAllPutEvents(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantAllPutEvents),error}const eventBus=EventBus2.fromEventBusName(new(core_1()).Stack,"dummy","dummy");return events_grants_generated_1().EventBusGrants.fromEventBus(eventBus).allPutEvents(grantee)}static eventBusProps(defaultEventBusName,props={}){const{eventBusName,eventSourceName}=props,eventBusNameRegex=/^[\/\.\-_A-Za-z0-9]{1,256}$/;if(eventBusName!==void 0&&eventSourceName!==void 0)throw new(core_1()).UnscopedValidationError("'eventBusName' and 'eventSourceName' cannot both be provided");if(eventBusName!==void 0){if(!core_1().Token.isUnresolved(eventBusName)){if(eventBusName==="default")throw new(core_1()).UnscopedValidationError("'eventBusName' must not be 'default'");if(eventBusName.indexOf("/")>-1)throw new(core_1()).UnscopedValidationError("'eventBusName' must not contain '/'");if(!eventBusNameRegex.test(eventBusName))throw new(core_1()).UnscopedValidationError(`'eventBusName' must satisfy: ${eventBusNameRegex}`)}return{eventBusName}}if(eventSourceName!==void 0){if(!core_1().Token.isUnresolved(eventSourceName)){const eventSourceNameRegex=/^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/;if(eventSourceNameRegex.test(eventSourceName)){if(!eventBusNameRegex.test(eventSourceName))throw new(core_1()).UnscopedValidationError(`'eventSourceName' must satisfy: ${eventBusNameRegex}`)}else throw new(core_1()).UnscopedValidationError(`'eventSourceName' must satisfy: ${eventSourceNameRegex}`)}return{eventBusName:eventSourceName,eventSourceName}}return{eventBusName:defaultEventBusName}}eventBusName=__runInitializers(this,_instanceExtraInitializers);eventBusArn;eventBusPolicy;eventSourceName;constructor(scope,id,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_events_EventBusProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,EventBus2),error}const{eventBusName,eventSourceName}=EventBus2.eventBusProps(core_1().Lazy.string({produce:()=>core_1().Names.uniqueId(this)}),props);if(super(scope,id,{physicalName:eventBusName}),(0,metadata_resource_1().addConstructMetadata)(this,props),props?.description&&!core_1().Token.isUnresolved(props.description)&&props.description.length>512)throw new(core_1()).ValidationError(`description must be less than or equal to 512 characters, got ${props.description.length}`,this);const eventBus=new(events_generated_1()).CfnEventBus(this,"Resource",{name:this.physicalName,eventSourceName,deadLetterConfig:props?.deadLetterQueue?{arn:props.deadLetterQueue.queueArn}:void 0,description:props?.description,kmsKeyIdentifier:props?.kmsKey?.keyArn,logConfig:props?.logConfig});this.eventBusArn=this.getResourceArnAttribute(eventBus.attrArn,{service:"events",resource:"event-bus",resourceName:eventBus.name}),props?.kmsKey&&props?.kmsKey.addToResourcePolicy(new(iam()).PolicyStatement({resources:["*"],actions:["kms:Decrypt","kms:GenerateDataKey","kms:DescribeKey"],principals:[new(iam()).ServicePrincipal("events.amazonaws.com")],conditions:{StringEquals:{"aws:SourceAccount":this.stack.account,"aws:SourceArn":core_1().Stack.of(this).formatArn({service:"events",resource:"event-bus",resourceName:eventBusName}),"kms:EncryptionContext:aws:events:event-bus:arn":core_1().Stack.of(this).formatArn({service:"events",resource:"event-bus",resourceName:eventBusName})}}})),this.eventBusName=this.getResourceNameAttribute(eventBus.ref),this.eventBusPolicy=eventBus.attrPolicy,this.eventSourceName=eventBus.eventSourceName}addToResourcePolicy(statement){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_PolicyStatement(statement)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addToResourcePolicy),error}if(statement.sid==null)throw new(core_1()).ValidationError("Event Bus policy statements must have a sid",this);const statementId=`cdk-${statement.sid}`.slice(0,64);return statement.sid=statementId,{statementAdded:!0,policyDependable:new EventBusPolicy(this,statementId,{eventBus:this,statement:statement.toJSON(),statementId})}}static{__runInitializers(_classThis,_classExtraInitializers)}};return EventBus2=_classThis})();exports.EventBus=EventBus;let ImportedEventBus=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=EventBusBase,_instanceExtraInitializers=[],_addToResourcePolicy_decorators;var ImportedEventBus2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_addToResourcePolicy_decorators=[(0,metadata_resource_1().MethodMetadata)()],__esDecorate(this,null,_addToResourcePolicy_decorators,{kind:"method",name:"addToResourcePolicy",static:!1,private:!1,access:{has:obj=>"addToResourcePolicy"in obj,get:obj=>obj.addToResourcePolicy},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),ImportedEventBus2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-events.ImportedEventBus";eventBusArn=__runInitializers(this,_instanceExtraInitializers);eventBusName;eventBusPolicy;eventSourceName;constructor(scope,id,attrs){const arnParts=core_1().Stack.of(scope).splitArn(attrs.eventBusArn,core_1().ArnFormat.SLASH_RESOURCE_NAME);super(scope,id,{account:arnParts.account,region:arnParts.region}),(0,metadata_resource_1().addConstructMetadata)(this,attrs),this.eventBusArn=attrs.eventBusArn,this.eventBusName=attrs.eventBusName,this.eventBusPolicy=attrs.eventBusPolicy,this.eventSourceName=attrs.eventSourceName}addToResourcePolicy(_statement){return core_1().Annotations.of(this).addWarningV2("@aws-cdk/aws-events:eventBusAddToResourcePolicy",`Unable to add necessary permissions to imported target event bus: ${this.eventBusArn}`),{statementAdded:!1}}static{__runInitializers(_classThis,_classExtraInitializers)}};return ImportedEventBus2=_classThis})(),EventBusPolicy=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=core_1().Resource;var EventBusPolicy2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),EventBusPolicy2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_events.EventBusPolicy",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-events.EventBusPolicy";constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_events_EventBusPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,EventBusPolicy2),error}(0,metadata_resource_1().addConstructMetadata)(this,props),new(events_generated_1()).CfnEventBusPolicy(this,"Resource",{statementId:props.statementId,statement:props.statement,eventBusName:props.eventBus.eventBusName})}static{__runInitializers(_classThis,_classExtraInitializers)}};return EventBusPolicy2=_classThis})();exports.EventBusPolicy=EventBusPolicy;