UNPKG

@csermet/multiprovider

Version:

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

63 lines (62 loc) 2.32 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"); /** * Dynamo DB */ exports.default = ({ service: dynamoDbTable, data, region, }) => { const connections = []; const { TableId: id, SSEDescription: sseDescription, Replicas: replicas, } = dynamoDbTable; /** * Find KMS * related to this dynamo db table */ const kmsMasterKeyArn = sseDescription?.KMSMasterKeyArn; const kms = data.find(({ name }) => name === services_1.default.kms); if (kmsMasterKeyArn && kms?.data?.[region]) { const kmsInRegion = kms.data[region].find(({ Arn }) => kmsMasterKeyArn === Arn); if (kmsInRegion) { connections.push({ id: kmsInRegion.KeyId, resourceType: services_1.default.kms, relation: 'child', field: 'kms', }); } } /** * Find IAM Roles * related to this dynamo db table */ const roleArns = []; replicas?.map(({ AutoScaling: autoScaling }) => { roleArns.push(autoScaling?.ReplicaProvisionedReadCapacityAutoScalingSettings ?.AutoScalingRoleArn); roleArns.push(autoScaling?.ReplicaProvisionedWriteCapacityAutoScalingSettings ?.AutoScalingRoleArn); }); const roles = data.find(({ name }) => name === services_1.default.iamRole); if (roles?.data?.[regions_1.globalRegionName]) { const dataAtRegion = roles.data[regions_1.globalRegionName].filter(({ Arn }) => roleArns?.includes(Arn)); if (!lodash_1.isEmpty(dataAtRegion)) { for (const iamRole of dataAtRegion) { const { Arn: arn } = iamRole; connections.push({ id: arn, resourceType: services_1.default.iamRole, relation: 'child', field: 'iamRoles', }); } } } const dynamoDbResult = { [id]: connections, }; return dynamoDbResult; };