@csermet/multiprovider
Version:
cloud-graph provider plugin for AWS used to fetch AWS cloud data.
72 lines (71 loc) • 2.85 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const services_1 = __importDefault(require("../../enums/services"));
/**
* Vpn Connection
*/
exports.default = ({ service: vpn, data, region, }) => {
const connections = [];
const { VpnConnectionId: id, TransitGatewayId: transitGatewayId, CustomerGatewayId: customerGatewayId, VpnGatewayId: vpnGatewayId, } = vpn;
/**
* Find Transit Gateway
* related to this Vpn Connection
*/
const transitGateways = data.find(({ name }) => name === services_1.default.transitGateway);
if (transitGateways?.data?.[region]) {
const awsTransitGateways = transitGateways.data[region].filter(({ TransitGatewayId }) => TransitGatewayId === transitGatewayId);
if (awsTransitGateways) {
for (const transitGateway of awsTransitGateways) {
connections.push({
id: transitGateway.TransitGatewayId,
resourceType: services_1.default.transitGateway,
relation: 'child',
field: 'transitGateway',
});
}
}
}
/**
* Find Customer Gateway
* related to this Vpn Connection
*/
const customerGateways = data.find(({ name }) => name === services_1.default.customerGateway);
if (customerGateways?.data?.[region]) {
const awsCustomerGateways = customerGateways.data[region].filter(({ CustomerGatewayId }) => CustomerGatewayId === customerGatewayId);
if (awsCustomerGateways) {
for (const customerGateway of awsCustomerGateways) {
connections.push({
id: customerGateway.CustomerGatewayId,
resourceType: services_1.default.customerGateway,
relation: 'child',
field: 'customerGateway',
});
}
}
}
/**
* Find Vpn Gateway
* related to this Vpn Connection
*/
const vpnGateways = data.find(({ name }) => name === services_1.default.vpnGateway);
if (vpnGateways?.data?.[region]) {
const awsVpnGateways = vpnGateways.data[region].filter(({ VpnGatewayId }) => VpnGatewayId === vpnGatewayId);
if (awsVpnGateways) {
for (const vpnGateway of awsVpnGateways) {
connections.push({
id: vpnGateway.VpnGatewayId,
resourceType: services_1.default.vpnGateway,
relation: 'child',
field: 'vpnGateway',
});
}
}
}
const vpnConnectionResult = {
[id]: connections,
};
return vpnConnectionResult;
};