aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 10.6 kB
JavaScript
;var __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},__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};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogGroup=exports.Distribution=exports.LogGroupClass=exports.RetentionDays=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var log_stream_1=()=>{var tmp=require("./log-stream");return log_stream_1=()=>tmp,tmp},logs_grants_generated_1=()=>{var tmp=require("./logs-grants.generated");return logs_grants_generated_1=()=>tmp,tmp},logs_generated_1=()=>{var tmp=require("./logs.generated");return logs_generated_1=()=>tmp,tmp},metric_filter_1=()=>{var tmp=require("./metric-filter");return metric_filter_1=()=>tmp,tmp},pattern_1=()=>{var tmp=require("./pattern");return pattern_1=()=>tmp,tmp},policy_1=()=>{var tmp=require("./policy");return policy_1=()=>tmp,tmp},subscription_filter_1=()=>{var tmp=require("./subscription-filter");return subscription_filter_1=()=>tmp,tmp},transformer_1=()=>{var tmp=require("./transformer");return transformer_1=()=>tmp,tmp},cloudwatch=()=>{var tmp=require("../../aws-cloudwatch");return cloudwatch=()=>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};class LogGroupBase extends core_1().Resource{grants=logs_grants_generated_1().LogGroupGrants.fromLogGroup(this);policy;addStream(id,props={}){return new(log_stream_1()).LogStream(this,id,{logGroup:this,...props})}get logGroupRef(){return{logGroupArn:this.logGroupArn,logGroupName:this.logGroupName}}addSubscriptionFilter(id,props){return new(subscription_filter_1()).SubscriptionFilter(this,id,{logGroup:this,...props})}addMetricFilter(id,props){return new(metric_filter_1()).MetricFilter(this,id,{logGroup:this,...props})}addTransformer(id,props){return new(transformer_1()).Transformer(this,id,{logGroup:this,...props})}extractMetric(jsonField,metricNamespace,metricName){return new(metric_filter_1()).MetricFilter(this,`${metricNamespace}_${metricName}`,{logGroup:this,metricNamespace,metricName,filterPattern:pattern_1().FilterPattern.exists(jsonField),metricValue:jsonField}),new(cloudwatch()).Metric({metricName,namespace:metricNamespace}).attachTo(this)}grantWrite(grantee){return this.grants.write(grantee)}grantRead(grantee){return this.grants.read(grantee)}grant(grantee,...actions){return iam().Grant.addToPrincipalOrResource({grantee,actions,resourceArns:[this.logGroupArn],resource:this})}logGroupPhysicalName(){return this.physicalName}addToResourcePolicy(statement){return this.policy||(this.policy=new(policy_1()).ResourcePolicy(this,"Policy")),this.policy.document.addStatements(statement.copy({principals:statement.principals.map(p=>this.convertArnPrincipalToAccountId(p))})),{statementAdded:!0,policyDependable:this.policy}}convertArnPrincipalToAccountId(principal){if(principal.principalAccount)return new(iam()).ArnPrincipal(principal.principalAccount);if(principal instanceof iam().ArnPrincipal&&principal.arn!=="*"){const parsedArn=core_1().Arn.split(principal.arn,core_1().ArnFormat.SLASH_RESOURCE_NAME);if(parsedArn.account)return new(iam()).ArnPrincipal(parsedArn.account)}return principal}metricIncomingLogEvents(props){return this.metric("IncomingLogs",props)}metricIncomingBytes(props){return this.metric("IncomingBytes",props)}metric(metricName,props){return new(cloudwatch()).Metric({namespace:"AWS/Logs",metricName,statistic:"Sum",...props}).attachTo(this)}}var RetentionDays;(function(RetentionDays2){RetentionDays2[RetentionDays2.ONE_DAY=1]="ONE_DAY",RetentionDays2[RetentionDays2.THREE_DAYS=3]="THREE_DAYS",RetentionDays2[RetentionDays2.FIVE_DAYS=5]="FIVE_DAYS",RetentionDays2[RetentionDays2.ONE_WEEK=7]="ONE_WEEK",RetentionDays2[RetentionDays2.TWO_WEEKS=14]="TWO_WEEKS",RetentionDays2[RetentionDays2.ONE_MONTH=30]="ONE_MONTH",RetentionDays2[RetentionDays2.TWO_MONTHS=60]="TWO_MONTHS",RetentionDays2[RetentionDays2.THREE_MONTHS=90]="THREE_MONTHS",RetentionDays2[RetentionDays2.FOUR_MONTHS=120]="FOUR_MONTHS",RetentionDays2[RetentionDays2.FIVE_MONTHS=150]="FIVE_MONTHS",RetentionDays2[RetentionDays2.SIX_MONTHS=180]="SIX_MONTHS",RetentionDays2[RetentionDays2.ONE_YEAR=365]="ONE_YEAR",RetentionDays2[RetentionDays2.THIRTEEN_MONTHS=400]="THIRTEEN_MONTHS",RetentionDays2[RetentionDays2.EIGHTEEN_MONTHS=545]="EIGHTEEN_MONTHS",RetentionDays2[RetentionDays2.TWO_YEARS=731]="TWO_YEARS",RetentionDays2[RetentionDays2.THREE_YEARS=1096]="THREE_YEARS",RetentionDays2[RetentionDays2.FIVE_YEARS=1827]="FIVE_YEARS",RetentionDays2[RetentionDays2.SIX_YEARS=2192]="SIX_YEARS",RetentionDays2[RetentionDays2.SEVEN_YEARS=2557]="SEVEN_YEARS",RetentionDays2[RetentionDays2.EIGHT_YEARS=2922]="EIGHT_YEARS",RetentionDays2[RetentionDays2.NINE_YEARS=3288]="NINE_YEARS",RetentionDays2[RetentionDays2.TEN_YEARS=3653]="TEN_YEARS",RetentionDays2[RetentionDays2.INFINITE=9999]="INFINITE"})(RetentionDays||(exports.RetentionDays=RetentionDays={}));var LogGroupClass;(function(LogGroupClass2){LogGroupClass2.STANDARD="STANDARD",LogGroupClass2.INFREQUENT_ACCESS="INFREQUENT_ACCESS"})(LogGroupClass||(exports.LogGroupClass=LogGroupClass={}));var Distribution;(function(Distribution2){Distribution2.BY_LOG_STREAM="ByLogStream",Distribution2.RANDOM="Random"})(Distribution||(exports.Distribution=Distribution={}));let LogGroup=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=LogGroupBase;var LogGroup2=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),LogGroup2=_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_logs.LogGroup",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-log.LogGroup";static fromLogGroupArn(scope,id,logGroupArn){const baseLogGroupArn=logGroupArn.replace(/:\*$/,"");class Import extends LogGroupBase{logGroupArn=`${baseLogGroupArn}:*`;logGroupName=core_1().Stack.of(scope).splitArn(baseLogGroupArn,core_1().ArnFormat.COLON_RESOURCE_NAME).resourceName}return new Import(scope,id,{environmentFromArn:baseLogGroupArn})}static fromLogGroupName(scope,id,logGroupName){const baseLogGroupName=logGroupName.replace(/:\*$/,"");class Import extends LogGroupBase{logGroupName=baseLogGroupName;logGroupArn=core_1().Stack.of(scope).formatArn({service:"logs",resource:"log-group",arnFormat:core_1().ArnFormat.COLON_RESOURCE_NAME,resourceName:baseLogGroupName+":*"})}return new Import(scope,id)}logGroupArn;logGroupName;constructor(scope,id,props={}){super(scope,id,{physicalName:props.logGroupName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_logs_LogGroupProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,LogGroup2),error}(0,metadata_resource_1().addConstructMetadata)(this,props);let retentionInDays=props.retention;if(retentionInDays===void 0&&(retentionInDays=RetentionDays.TWO_YEARS),(retentionInDays===1/0||retentionInDays===RetentionDays.INFINITE)&&(retentionInDays=void 0),retentionInDays!==void 0&&!core_1().Token.isUnresolved(retentionInDays)&&retentionInDays<=0)throw new(core_1()).ValidationError(`retentionInDays must be positive, got ${retentionInDays}`,this);let logGroupClass=props.logGroupClass;const dataProtectionPolicy=props.dataProtectionPolicy?._bind(this),fieldIndexPolicies=[];props.fieldIndexPolicies&&props.fieldIndexPolicies.forEach(fieldIndexPolicy=>{fieldIndexPolicies.push(fieldIndexPolicy._bind(this))});const resource=new(logs_generated_1()).CfnLogGroup(this,"Resource",{kmsKeyId:props.encryptionKey?.keyRef.keyArn,logGroupClass,logGroupName:this.physicalName,retentionInDays,dataProtectionPolicy:dataProtectionPolicy?{Name:dataProtectionPolicy?.name,Description:dataProtectionPolicy?.description,Version:dataProtectionPolicy?.version,Statement:dataProtectionPolicy?.statement,Configuration:dataProtectionPolicy?.configuration}:void 0,...props.fieldIndexPolicies&&{fieldIndexPolicies}});resource.applyRemovalPolicy(props.removalPolicy),this.logGroupArn=this.getResourceArnAttribute(resource.attrArn,{service:"logs",resource:"log-group",resourceName:this.physicalName,arnFormat:core_1().ArnFormat.COLON_RESOURCE_NAME}),this.logGroupName=this.getResourceNameAttribute(resource.ref)}static{__runInitializers(_classThis,_classExtraInitializers)}};return LogGroup2=_classThis})();exports.LogGroup=LogGroup;