@csermet/multiprovider
Version:
cloud-graph provider plugin for AWS used to fetch AWS cloud data.
51 lines (50 loc) • 1.65 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"));
/**
* Route Table
*/
exports.default = ({ service: routeTable, data, region, }) => {
const connections = [];
const { Associations, RouteTableId: id, VpcId: vpcId } = routeTable;
/**
* Find VPCs
* related to this Route table
*/
const vpcs = data.find(({ name }) => name === services_1.default.vpc);
if (vpcs?.data?.[region]) {
const vpc = vpcs.data[region].find(({ VpcId }) => VpcId === vpcId);
if (vpc) {
connections.push({
id: vpc.VpcId,
resourceType: services_1.default.vpc,
relation: 'child',
field: 'vpc',
});
}
}
/**
* Find Subnets
* related to this Route Table
*/
const subnets = data.find(({ name }) => name === services_1.default.subnet);
const subnetIds = Associations.map(({ SubnetId }) => SubnetId);
if (subnets?.data?.[region]) {
const subnet = subnets.data[region].find(({ SubnetId }) => subnetIds.includes(SubnetId));
if (subnet) {
connections.push({
id: subnet.SubnetId,
resourceType: services_1.default.subnet,
relation: 'child',
field: 'subnet',
});
}
}
const routeTableResult = {
[id]: connections,
};
return routeTableResult;
};