aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.91 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.renderAttributes=renderAttributes,exports.defaultPortForProtocol=defaultPortForProtocol,exports.defaultProtocolForPort=defaultProtocolForPort,exports.determineProtocolAndPort=determineProtocolAndPort,exports.ifUndefined=ifUndefined,exports.validateNetworkProtocol=validateNetworkProtocol,exports.mapTagMapToCxschema=mapTagMapToCxschema,exports.parseLoadBalancerFullName=parseLoadBalancerFullName,exports.parseTargetGroupFullName=parseTargetGroupFullName;var enums_1=()=>{var tmp=require("./enums");return enums_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../../core/lib/errors");return errors_1=()=>tmp,tmp};function renderAttributes(attributes){const ret=[];for(const[key,value]of Object.entries(attributes))value!==void 0&&ret.push({key,value});return ret}function defaultPortForProtocol(proto){switch(proto){case enums_1().ApplicationProtocol.HTTP:return 80;case enums_1().ApplicationProtocol.HTTPS:return 443;default:throw new(errors_1()).UnscopedValidationError(`Unrecognized protocol: ${proto}`)}}function defaultProtocolForPort(port){switch(port){case 80:case 8e3:case 8008:case 8080:return enums_1().ApplicationProtocol.HTTP;case 443:case 8443:return enums_1().ApplicationProtocol.HTTPS;default:throw new(errors_1()).UnscopedValidationError(`Don't know default protocol for port: ${port}; please supply a protocol`)}}function determineProtocolAndPort(protocol,port){return protocol===void 0&&port===void 0?[void 0,void 0]:(protocol===void 0&&(protocol=defaultProtocolForPort(port)),port===void 0&&(port=defaultPortForProtocol(protocol)),[protocol,port])}function ifUndefined(x,def){return x??def}function validateNetworkProtocol(protocol){const NLB_PROTOCOLS=[enums_1().Protocol.TCP,enums_1().Protocol.TLS,enums_1().Protocol.UDP,enums_1().Protocol.TCP_UDP];if(NLB_PROTOCOLS.indexOf(protocol)===-1)throw new(errors_1()).UnscopedValidationError(`The protocol must be one of ${NLB_PROTOCOLS.join(", ")}. Found ${protocol}`)}function mapTagMapToCxschema(tagMap){return Object.entries(tagMap).map(([key,value])=>({key,value}))}function parseLoadBalancerFullName(arn){if(core_1().Token.isUnresolved(arn)){const arnParts=core_1().Fn.split("/",arn);return`${core_1().Fn.select(1,arnParts)}/${core_1().Fn.select(2,arnParts)}/${core_1().Fn.select(3,arnParts)}`}else{const resourceName=core_1().Arn.split(arn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName;if(!resourceName)throw new(errors_1()).UnscopedValidationError(`Provided ARN does not belong to a load balancer: ${arn}`);return resourceName}}function parseTargetGroupFullName(arn){const resource=core_1().Arn.split(arn,core_1().ArnFormat.NO_RESOURCE_NAME).resource;if(!resource)throw new(errors_1()).UnscopedValidationError(`Provided ARN does not belong to a target group: ${arn}`);return resource}
;