UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 4.96 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.OriginBase=exports.OriginSelectionCriteria=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},OriginSelectionCriteria;(function(OriginSelectionCriteria2){OriginSelectionCriteria2.DEFAULT="default",OriginSelectionCriteria2.MEDIA_QUALITY_BASED="media-quality-based"})(OriginSelectionCriteria||(exports.OriginSelectionCriteria=OriginSelectionCriteria={}));class OriginBase{constructor(domainName,props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudfront_OriginProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,OriginBase),error}validateIntInRangeOrUndefined("connectionTimeout",1,10,props.connectionTimeout?.toSeconds()),validateIntInRangeOrUndefined("connectionAttempts",1,3,props.connectionAttempts,!1),validateCustomHeaders(props.customHeaders),this.domainName=domainName,this.originPath=this.validateOriginPath(props.originPath),this.connectionTimeout=props.connectionTimeout,this.connectionAttempts=props.connectionAttempts,this.customHeaders=props.customHeaders,this.originShieldRegion=props.originShieldRegion,this.originId=props.originId,this.originShieldEnabled=props.originShieldEnabled??!0,this.originAccessControlId=props.originAccessControlId}bind(scope,options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudfront_OriginBindOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const s3OriginConfig=this.renderS3OriginConfig(),customOriginConfig=this.renderCustomOriginConfig(),vpcOriginConfig=this.renderVpcOriginConfig();if(!s3OriginConfig&&!customOriginConfig&&!vpcOriginConfig)throw new(core_1()).ValidationError("Subclass must override and provide either s3OriginConfig, customOriginConfig or vpcOriginConfig",scope);return{originProperty:{domainName:this.domainName,id:this.originId??options.originId,originPath:this.originPath,connectionAttempts:this.connectionAttempts,connectionTimeout:this.connectionTimeout?.toSeconds(),originCustomHeaders:this.renderCustomHeaders(),s3OriginConfig,customOriginConfig,vpcOriginConfig,originShield:this.renderOriginShield(this.originShieldEnabled,this.originShieldRegion),originAccessControlId:this.originAccessControlId}}}renderS3OriginConfig(){}renderCustomOriginConfig(){}renderVpcOriginConfig(){}renderCustomHeaders(){if(!(!this.customHeaders||Object.entries(this.customHeaders).length===0))return Object.entries(this.customHeaders).map(([headerName,headerValue])=>({headerName,headerValue}))}validateOriginPath(originPath){if(core_1().Token.isUnresolved(originPath))return originPath;if(originPath===void 0)return;let path=originPath;return path.startsWith("/")||(path="/"+path),path.endsWith("/")&&(path=path.slice(0,-1)),path}renderOriginShield(originShieldEnabled,originShieldRegion){return originShieldEnabled?originShieldRegion?{enabled:!0,originShieldRegion}:void 0:{enabled:!1}}}exports.OriginBase=OriginBase,_a=JSII_RTTI_SYMBOL_1,OriginBase[_a]={fqn:"aws-cdk-lib.aws_cloudfront.OriginBase",version:"2.185.0"};function validateIntInRangeOrUndefined(name,min,max,value,isDuration=!0){if(value!==void 0&&(!Number.isInteger(value)||value<min||value>max)){const seconds=isDuration?" seconds":"";throw new(core_1()).UnscopedValidationError(`${name}: Must be an int between ${min} and ${max}${seconds} (inclusive); received ${value}.`)}}function validateCustomHeaders(customHeaders){if(!customHeaders||Object.entries(customHeaders).length===0)return;const customHeaderKeys=Object.keys(customHeaders),prohibitedHeaderKeys=["Cache-Control","Connection","Content-Length","Cookie","Host","If-Match","If-Modified-Since","If-None-Match","If-Range","If-Unmodified-Since","Max-Forwards","Pragma","Proxy-Authorization","Proxy-Connection","Range","Request-Range","TE","Trailer","Transfer-Encoding","Upgrade","Via","X-Real-Ip"],prohibitedHeaderKeyPrefixes=["X-Amz-","X-Edge-"],prohibitedHeadersKeysMatches=customHeaderKeys.filter(customKey=>prohibitedHeaderKeys.map(prohibitedKey=>prohibitedKey.toLowerCase()).includes(customKey.toLowerCase())),prohibitedHeaderPrefixMatches=customHeaderKeys.filter(customKey=>prohibitedHeaderKeyPrefixes.some(prohibitedKeyPrefix=>customKey.toLowerCase().startsWith(prohibitedKeyPrefix.toLowerCase())));if(prohibitedHeadersKeysMatches.length!==0)throw new(core_1()).UnscopedValidationError(`The following headers cannot be configured as custom origin headers: ${prohibitedHeadersKeysMatches.join(", ")}`);if(prohibitedHeaderPrefixMatches.length!==0)throw new(core_1()).UnscopedValidationError(`The following headers cannot be used as prefixes for custom origin headers: ${prohibitedHeaderPrefixMatches.join(", ")}`)}