UNPKG

@csermet/multiprovider

Version:

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

86 lines (85 loc) 3.22 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: lambda, data, region, }) => { const { KMSKeyArn, FunctionArn: id, Role, VpcConfig: { SecurityGroupIds: sgIds = [], SubnetIds: subnetIds = [] } = {}, } = lambda; const connections = []; /** * Find KmsKey used in lambda function */ const kmsKeys = data.find(({ name }) => name === services_1.default.kms); if (kmsKeys?.data?.[region]) { const kmsKey = kmsKeys.data[region].find(({ Arn }) => Arn === KMSKeyArn); if (!lodash_1.isEmpty(kmsKey)) { connections.push({ id: kmsKey.KeyId, resourceType: services_1.default.kms, relation: 'child', field: 'kms', }); } } /** * Find from VPC, Security Groups * related to this lambda function */ 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 * related to this lambda function */ const subnets = data.find(({ name }) => name === services_1.default.subnet); if (subnets?.data?.[region]) { 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: 'subnet', }); } } } /** * Find IAM Role * related to this lambda function */ const iamRoles = data.find(({ name }) => name === services_1.default.iamRole); if (iamRoles?.data?.[regions_1.globalRegionName]) { const iamRolesInRegion = iamRoles.data[regions_1.globalRegionName].filter(({ Arn }) => Arn === Role); if (!lodash_1.isEmpty(iamRolesInRegion)) { for (const role of iamRolesInRegion) { connections.push({ id: role.Arn, resourceType: services_1.default.iamRole, relation: 'child', field: 'iamRole', }); } } } const lambdaResult = { [id]: connections, }; return lambdaResult; };