"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Connections=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),peer_1=require("./peer");class Connections{constructor(props={}){this._securityGroups=new ReactiveList,this._securityGroupRules=new ReactiveList,this.skip=!1,this.remoteRule=!1,jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_ConnectionsProps(props),this.connections=this,this._securityGroups.push(...props.securityGroups||[]),this._securityGroupRules.push(...this._securityGroups.asArray()),props.peer&&this._securityGroupRules.push(props.peer),this.defaultPort=props.defaultPort}get securityGroups(){return this._securityGroups.asArray()}addSecurityGroup(...securityGroups){jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_ISecurityGroup(securityGroups);for(const securityGroup of securityGroups)this._securityGroups.push(securityGroup),this._securityGroupRules.push(securityGroup)}allowTo(other,portRange,description){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IConnectable(other),jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_Port(portRange),this.skip)return;const remoteRule=this.remoteRule;this._securityGroups.forEachAndForever(securityGroup=>{other.connections._securityGroupRules.forEachAndForever(rule=>{securityGroup.addEgressRule(rule,portRange,description,remoteRule)})}),this.skip=!0,other.connections.remoteRule=!0;try{other.connections.allowFrom(this,portRange,description)}finally{this.skip=!1,other.connections.remoteRule=!1}}allowFrom(other,portRange,description){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IConnectable(other),jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_Port(portRange),this.skip)return;const remoteRule=this.remoteRule;this._securityGroups.forEachAndForever(securityGroup=>{other.connections._securityGroupRules.forEachAndForever(rule=>{securityGroup.addIngressRule(rule,portRange,description,remoteRule)})}),this.skip=!0,other.connections.remoteRule=!0;try{other.connections.allowTo(this,portRange,description)}finally{this.skip=!1,other.connections.remoteRule=!1}}allowInternally(portRange,description){jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_Port(portRange),this._securityGroups.forEachAndForever(securityGroup=>{this._securityGroupRules.forEachAndForever(rule=>{securityGroup.addIngressRule(rule,portRange,description),securityGroup.addEgressRule(rule,portRange,description)})})}allowToAnyIpv4(portRange,description){jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_Port(portRange),this.allowTo(peer_1.Peer.anyIpv4(),portRange,description)}allowFromAnyIpv4(portRange,description){jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_Port(portRange),this.allowFrom(peer_1.Peer.anyIpv4(),portRange,description)}allowDefaultPortFrom(other,description){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IConnectable(other),!this.defaultPort)throw new Error("Cannot call allowDefaultPortFrom(): this resource has no default port");this.allowFrom(other,this.defaultPort,description)}allowDefaultPortInternally(description){if(!this.defaultPort)throw new Error("Cannot call allowDefaultPortInternally(): this resource has no default port");this.allowInternally(this.defaultPort,description)}allowDefaultPortFromAnyIpv4(description){if(!this.defaultPort)throw new Error("Cannot call allowDefaultPortFromAnyIpv4(): this resource has no default port");this.allowFromAnyIpv4(this.defaultPort,description)}allowToDefaultPort(other,description){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IConnectable(other),other.connections.defaultPort===void 0)throw new Error("Cannot call allowToDefaultPort(): other resource has no default port");this.allowTo(other,other.connections.defaultPort,description)}allowDefaultPortTo(other,description){if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IConnectable(other),!this.defaultPort)throw new Error("Cannot call allowDefaultPortTo(): this resource has no default port");this.allowTo(other,this.defaultPort,description)}}exports.Connections=Connections,_a=JSII_RTTI_SYMBOL_1,Connections[_a]={fqn:"aws-cdk-lib.aws_ec2.Connections",version:"2.13.0"};class ReactiveList{constructor(){this.elements=new Array,this.listeners=new Array}push(...xs){this.elements.push(...xs);for(const listener of this.listeners)for(const x of xs)listener(x)}forEachAndForever(listener){for(const element of this.elements)listener(element);this.listeners.push(listener)}asArray(){return this.elements.slice()}get length(){return this.elements.length}}
//# sourceMappingURL=connections.js.map
