"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.VirtualNode=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),iam=require("../../aws-iam"),cdk=require("../../core"),appmesh_generated_1=require("./appmesh.generated"),mesh_1=require("./mesh"),utils_1=require("./private/utils");class VirtualNodeBase extends cdk.Resource{grantStreamAggregatedResources(identity){return iam.Grant.addToPrincipal({grantee:identity,actions:["appmesh:StreamAggregatedResources"],resourceArns:[this.virtualNodeArn]})}}class VirtualNode extends VirtualNodeBase{constructor(scope,id,props){var _b,_c,_d,_e,_f;super(scope,id,{physicalName:props.virtualNodeName||cdk.Lazy.string({produce:()=>cdk.Names.uniqueId(this)})});this.backends=new Array,this.listeners=new Array,jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_VirtualNodeProps(props),this.mesh=props.mesh,this.serviceDiscoveryConfig=(_b=props.serviceDiscovery)===null||_b===void 0?void 0:_b.bind(this),(_c=props.backends)===null||_c===void 0||_c.forEach(backend=>this.addBackend(backend)),(_d=props.listeners)===null||_d===void 0||_d.forEach(listener=>this.addListener(listener));const accessLogging=(_e=props.accessLog)===null||_e===void 0?void 0:_e.bind(this),node=new appmesh_generated_1.CfnVirtualNode(this,"Resource",{virtualNodeName:this.physicalName,meshName:this.mesh.meshName,meshOwner:utils_1.renderMeshOwner(this.env.account,this.mesh.env.account),spec:{backends:cdk.Lazy.any({produce:()=>this.backends},{omitEmptyArray:!0}),listeners:cdk.Lazy.any({produce:()=>this.listeners.map(listener=>listener.listener)},{omitEmptyArray:!0}),backendDefaults:props.backendDefaults!==void 0?{clientPolicy:{tls:utils_1.renderTlsClientPolicy(this,(_f=props.backendDefaults)===null||_f===void 0?void 0:_f.tlsClientPolicy)}}:void 0,serviceDiscovery:renderServiceDiscovery(this.serviceDiscoveryConfig),logging:accessLogging!==void 0?{accessLog:accessLogging.virtualNodeAccessLog}:void 0}});this.virtualNodeName=this.getResourceNameAttribute(node.attrVirtualNodeName),this.virtualNodeArn=this.getResourceArnAttribute(node.ref,{service:"appmesh",resource:`mesh/${props.mesh.meshName}/virtualNode`,resourceName:this.physicalName})}static fromVirtualNodeArn(scope,id,virtualNodeArn){return new class extends VirtualNodeBase{constructor(){super(...arguments);this.virtualNodeArn=virtualNodeArn,this.parsedArn=cdk.Fn.split("/",cdk.Stack.of(scope).splitArn(virtualNodeArn,cdk.ArnFormat.SLASH_RESOURCE_NAME).resourceName),this.mesh=mesh_1.Mesh.fromMeshName(this,"Mesh",cdk.Fn.select(0,this.parsedArn)),this.virtualNodeName=cdk.Fn.select(2,this.parsedArn)}}(scope,id)}static fromVirtualNodeAttributes(scope,id,attrs){return jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_VirtualNodeAttributes(attrs),new class extends VirtualNodeBase{constructor(){super(...arguments);this.mesh=attrs.mesh,this.virtualNodeName=attrs.virtualNodeName,this.virtualNodeArn=cdk.Stack.of(this).formatArn({service:"appmesh",resource:`mesh/${attrs.mesh.meshName}/virtualNode`,resourceName:this.virtualNodeName})}}(scope,id)}addListener(listener){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_VirtualNodeListener(listener),!this.serviceDiscoveryConfig)throw new Error("Service discovery information is required for a VirtualNode with a listener.");this.listeners.push(listener.bind(this))}addBackend(backend){jsiiDeprecationWarnings.aws_cdk_lib_aws_appmesh_Backend(backend),this.backends.push(backend.bind(this).virtualServiceBackend)}}exports.VirtualNode=VirtualNode,_a=JSII_RTTI_SYMBOL_1,VirtualNode[_a]={fqn:"aws-cdk-lib.aws_appmesh.VirtualNode",version:"2.13.0"};function renderServiceDiscovery(config){return config?{dns:config==null?void 0:config.dns,awsCloudMap:config==null?void 0:config.cloudmap}:void 0}
//# sourceMappingURL=virtual-node.js.map
