UNPKG

@csermet/multiprovider

Version:

cloud-graph provider plugin for AWS used to fetch AWS cloud data.

113 lines (112 loc) 4.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const isEmpty_1 = __importDefault(require("lodash/isEmpty")); const services_1 = __importDefault(require("../../enums/services")); /** * Vpc Endpoint */ exports.default = ({ service: vpcEndpoint, data, region, }) => { const connections = []; const { VpcEndpointId: id, VpcId: vpcId, RouteTableIds: routeTableIds, SubnetIds: subnetIds, Groups: groups, NetworkInterfaceIds: networkInterfaceIds, } = vpcEndpoint; /** * Find VPC * related to this Vpc Endpoint */ const vpcs = data.find(({ name }) => name === services_1.default.vpc); if (vpcs?.data?.[region]) { const vpcsInRegion = vpcs.data[region].filter(({ VpcId }) => VpcId === vpcId); if (!isEmpty_1.default(vpcsInRegion)) { for (const vpc of vpcsInRegion) { const { VpcId } = vpc; connections.push({ id: VpcId, resourceType: services_1.default.vpc, relation: 'child', field: 'vpc', }); } } } /** * Find Route Tables * related to this Vpc Endpoint */ const routeTables = data.find(({ name }) => name === services_1.default.routeTable); if (routeTables?.data?.[region] && routeTableIds?.length > 0) { const routeTablesRegion = routeTables.data[region].filter(({ RouteTableId }) => routeTableIds.includes(RouteTableId)); if (!isEmpty_1.default(routeTablesRegion)) { for (const routeTable of routeTablesRegion) { const { RouteTableId } = routeTable; connections.push({ id: RouteTableId, resourceType: services_1.default.routeTable, relation: 'child', field: 'routeTables', }); } } } /** * Find Subnets * related to this Vpc Endpoint */ const subnets = data.find(({ name }) => name === services_1.default.subnet); if (subnets?.data?.[region] && subnetIds?.length > 0) { const subnetsInRegion = subnets.data[region].filter(({ SubnetId }) => subnetIds.includes(SubnetId)); if (!isEmpty_1.default(subnetsInRegion)) { for (const subnet of subnetsInRegion) { const { SubnetId } = subnet; connections.push({ id: SubnetId, resourceType: services_1.default.subnet, relation: 'child', field: 'subnets', }); } } } /** * Find Security Groups * related to this Vpc Endpoint */ const securityGroups = data.find(({ name }) => name === services_1.default.sg); const sgIds = groups?.map(({ GroupId }) => GroupId) || []; if (securityGroups?.data?.[region] && sgIds?.length > 0) { const sgsInRegion = securityGroups.data[region].filter(({ GroupId }) => sgIds.includes(GroupId)); if (!isEmpty_1.default(sgsInRegion)) { for (const sg of sgsInRegion) { const { GroupId } = sg; connections.push({ id: GroupId, resourceType: services_1.default.sg, relation: 'child', field: 'securityGroups', }); } } } /** * Find Network Interfaces * related to this Vpc Endpoint */ const netInterfaces = data.find(({ name }) => name === services_1.default.networkInterface); if (netInterfaces?.data?.[region] && networkInterfaceIds?.length > 0) { const dataAtRegion = netInterfaces.data[region].filter(({ NetworkInterfaceId }) => networkInterfaceIds.includes(NetworkInterfaceId)); for (const net of dataAtRegion) { const { NetworkInterfaceId } = net; connections.push({ id: NetworkInterfaceId, resourceType: services_1.default.networkInterface, relation: 'child', field: 'networkInterfaces', }); } } const vpnGatewayResult = { [id]: connections, }; return vpnGatewayResult; };