All files / mgmt-lambda/utils cloudfrontUtils.ts

100% Statements 11/11
88.88% Branches 8/9
100% Functions 6/6
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 263x 3x     3x 8x     3x       14x     3x       8x   4x        
import { CacheBehavior, DefaultCacheBehavior, DistributionConfig, EventType, Origin } from '@aws-sdk/client-cloudfront'
import { defaults } from '../DefaultSettings'
import { LambdaFunctionAssociation } from '@aws-sdk/client-cloudfront'
 
export function getFPCDNOrigins(distributionConfig: DistributionConfig | undefined): Origin[] {
  return distributionConfig?.Origins?.Items?.filter((it) => it.DomainName === defaults.FP_CDN_URL) || []
}
 
export function doesCacheBehaviorUseOrigins(
  cacheBehavior: DefaultCacheBehavior | CacheBehavior | undefined,
  origins: Origin[]
): boolean {
  return origins?.some((origin) => origin.Id === cacheBehavior?.TargetOriginId) || false
}
 
export function getCacheBehaviorLambdaFunctionAssociations(
  cacheBehavior: DefaultCacheBehavior | CacheBehavior | undefined,
  functionName: string
): LambdaFunctionAssociation[] {
  return (
    cacheBehavior?.LambdaFunctionAssociations?.Items?.filter(
      (it) => it && it.EventType === EventType.origin_request && it.LambdaFunctionARN?.includes(`${functionName}:`)
    ) || []
  )
}