aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.22 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringSpecializer=void 0,exports.resolvedOr=resolvedOr,exports.translateCfnTokenToAssetToken=translateCfnTokenToAssetToken,exports.translateAssetTokenToCfnToken=translateAssetTokenToCfnToken;var cxapi=()=>{var tmp=require("../../../cx-api");return cxapi=()=>tmp,tmp},cfn_pseudo_1=()=>{var tmp=require("../cfn-pseudo");return cfn_pseudo_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../errors");return errors_1=()=>tmp,tmp},token_1=()=>{var tmp=require("../token");return token_1=()=>tmp,tmp};function replaceAll(s,search,replace){return s.split(search).join(replace)}class StringSpecializer{static validateNoTokens(s,what){if(token_1().Token.isUnresolved(s))throw new(errors_1()).UnscopedValidationError(`${what} may not contain tokens; only the following literal placeholder strings are allowed: `+["${Qualifier}",cxapi().EnvironmentPlaceholders.CURRENT_REGION,cxapi().EnvironmentPlaceholders.CURRENT_ACCOUNT,cxapi().EnvironmentPlaceholders.CURRENT_PARTITION].join(", ")+`. Got: ${s}`)}constructor(stack,qualifier){this.stack=stack,this.qualifier=qualifier}specialize(s){return s=replaceAll(s,"${Qualifier}",this.qualifier),cxapi().EnvironmentPlaceholders.replace(s,{region:resolvedOr(this.stack.region,cxapi().EnvironmentPlaceholders.CURRENT_REGION),accountId:resolvedOr(this.stack.account,cxapi().EnvironmentPlaceholders.CURRENT_ACCOUNT),partition:cxapi().EnvironmentPlaceholders.CURRENT_PARTITION})}specializeNoTokens(s,what){return StringSpecializer.validateNoTokens(s,what),this.specialize(s)}qualifierOnly(s){return replaceAll(s,"${Qualifier}",this.qualifier)}}exports.StringSpecializer=StringSpecializer;function resolvedOr(x,def){return token_1().Token.isUnresolved(x)?def:x}const ASSET_TOKENS=["${AWS::Partition}","${AWS::Region}","${AWS::AccountId}"],CFN_TOKENS=[cfn_pseudo_1().Aws.PARTITION,cfn_pseudo_1().Aws.REGION,cfn_pseudo_1().Aws.ACCOUNT_ID];function translateCfnTokenToAssetToken(arn){for(let i=0;i<CFN_TOKENS.length;i++)arn=replaceAll(arn,CFN_TOKENS[i],ASSET_TOKENS[i]);return arn}function translateAssetTokenToCfnToken(arn){for(let i=0;i<ASSET_TOKENS.length;i++)arn=replaceAll(arn,ASSET_TOKENS[i],CFN_TOKENS[i]);return arn}
;