UNPKG

@csermet/multiprovider

Version:

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

87 lines (86 loc) 3.27 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")); const regions_1 = require("../../enums/regions"); /** * Cloud Formation Stack */ exports.default = ({ service: cfStack, data, region, }) => { const connections = []; const { StackId: id, RoleARN: roleArn, NotificationARNs: notificationARNs, ParentId: parentId, RootId: rootId, } = cfStack; /** * Find related Cloudformation stacks */ const CFStacks = data.find(({ name }) => name === services_1.default.cloudFormationStack); if (CFStacks?.data?.[region]) { // Find root stack if (rootId) { const rootStack = CFStacks.data[region].find(({ StackId }) => StackId === rootId); if (rootStack) { connections.push({ id: rootStack.StackId, resourceType: services_1.default.cloudFormationStack, relation: 'child', field: 'rootStack', insertAfterNodeInsertion: true, }); } } // Find parent stack if (parentId) { const parentStack = CFStacks.data[region].find(({ StackId }) => StackId === parentId); if (parentStack) { connections.push({ id: parentStack.StackId, resourceType: services_1.default.cloudFormationStack, relation: 'child', field: 'parentStack', insertAfterNodeInsertion: true, }); } } } /** * Find related IAM Roles */ const roles = data.find(({ name }) => name === services_1.default.iamRole); if (roles?.data?.[regions_1.globalRegionName]) { const dataAtRegion = roles.data[regions_1.globalRegionName].filter(role => role.Arn === roleArn); if (!isEmpty_1.default(dataAtRegion)) { for (const instance of dataAtRegion) { const { Arn: arn } = instance; connections.push({ id: arn, resourceType: services_1.default.iamRole, relation: 'child', field: 'iamRole', }); } } } /** * Find related SNS topic */ const snsTopics = data.find(({ name }) => name === services_1.default.sns); if (snsTopics?.data?.[region]) { const snsTopicsInRegion = snsTopics.data[region].filter(topic => topic.TopicArn === notificationARNs); if (!isEmpty_1.default(snsTopicsInRegion)) { for (const topic of snsTopicsInRegion) { connections.push({ id: topic.TopicArn, resourceType: services_1.default.sns, relation: 'child', field: 'sns', }); } } } const cfStackResult = { [id]: connections, }; return cfStackResult; };