@csermet/multiprovider
Version:
cloud-graph provider plugin for AWS used to fetch AWS cloud data.
67 lines (66 loc) • 2.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const services_1 = __importDefault(require("../../enums/services"));
exports.default = ({ service, data, region, }) => {
const connections = [];
const { ARN: id, SecurityGroups, CacheSubnetGroup } = service;
const sgIds = SecurityGroups.map(({ SecurityGroupId }) => SecurityGroupId);
/**
* Find SecurityGroups
*/
const securityGroups = data.find(({ name }) => name === services_1.default.sg);
if (securityGroups?.data?.[region]) {
const sgsInRegion = securityGroups.data[region].filter(({ GroupId }) => sgIds.includes(GroupId));
if (!lodash_1.isEmpty(sgsInRegion)) {
for (const sg of sgsInRegion) {
connections.push({
id: sg.GroupId,
resourceType: services_1.default.sg,
relation: 'child',
field: 'securityGroups',
});
}
}
}
/**
* Find Subnets
*/
const subnets = data.find(({ name }) => name === services_1.default.subnet);
const subnetIds = CacheSubnetGroup?.Subnets?.map(({ SubnetIdentifier }) => SubnetIdentifier);
if (subnets?.data?.[region] && subnetIds?.length > 0) {
const subnetsInRegion = subnets.data[region].filter(({ SubnetId }) => subnetIds.includes(SubnetId));
if (!lodash_1.isEmpty(subnetsInRegion)) {
for (const subnet of subnetsInRegion) {
connections.push({
id: subnet.SubnetId,
resourceType: services_1.default.subnet,
relation: 'child',
field: 'subnets',
});
}
}
}
/**
* Find related Vpc
*/
const vpcs = data.find(({ name }) => name === services_1.default.vpc);
if (vpcs?.data?.[region]) {
const vpc = vpcs.data[region].find(({ VpcId }) => VpcId === CacheSubnetGroup?.VpcId);
if (!lodash_1.isEmpty(vpc)) {
connections.push({
id: vpc.VpcId,
resourceType: services_1.default.vpc,
relation: 'child',
field: 'vpc',
});
}
}
const result = {
[id]: connections,
};
return result;
};