UNPKG

@csermet/multiprovider

Version:

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

69 lines (68 loc) 2.62 kB
"use strict"; 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")); const regions_1 = require("../../enums/regions"); exports.default = ({ service, data, region, }) => { const { ClusterArn: id, Ec2InstanceAttributes, LogEncryptionKmsKeyId, ServiceRole, AutoScalingRole, } = service; const connections = []; const subnetId = Ec2InstanceAttributes?.Ec2SubnetId; /** * Find KMS */ const kmsKeys = data.find(({ name }) => name === services_1.default.kms); if (kmsKeys?.data?.[region]) { const kmsKeyInRegion = kmsKeys.data[region].filter(kmsKey => kmsKey.Arn === LogEncryptionKmsKeyId); if (!lodash_1.isEmpty(kmsKeyInRegion)) { for (const kms of kmsKeyInRegion) { connections.push({ id: kms.KeyId, resourceType: services_1.default.kms, relation: 'child', field: 'kms', }); } } } /** * Find Subnets */ const subnets = data.find(({ name }) => name === services_1.default.subnet); if (subnets?.data?.[region]) { const subnetsInRegion = subnets.data[region].filter(({ SubnetId }) => SubnetId === subnetId); if (!lodash_1.isEmpty(subnetsInRegion)) { for (const subnet of subnetsInRegion) { connections.push({ id: subnet.SubnetId, resourceType: services_1.default.subnet, relation: 'child', field: 'subnet', }); } } } /** * Find IAM Roles */ const iamRoles = data.find(({ name }) => name === services_1.default.iamRole); if (iamRoles?.data?.[regions_1.globalRegionName]) { const iamRolesInRegion = iamRoles.data[regions_1.globalRegionName].filter(({ RoleName }) => RoleName === ServiceRole || RoleName === AutoScalingRole); if (!lodash_1.isEmpty(iamRolesInRegion)) { for (const role of iamRolesInRegion) { connections.push({ id: role.Arn, resourceType: services_1.default.iamRole, relation: 'child', field: 'iamRoles', }); } } } const result = { [id]: connections, }; return result; };