UNPKG

@csermet/multiprovider

Version:

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

68 lines (67 loc) 2.49 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 ids_1 = require("../../utils/ids"); exports.default = ({ service: ecsCluster, data, region, }) => { const { clusterArn: arn, configuration: { executeCommandConfiguration: { logConfiguration, kmsKeyId } = {}, } = {}, } = ecsCluster; const connections = []; /** * Find S3 * related to this ecs cluster */ const buckets = data.find(({ name }) => name === services_1.default.s3); if (buckets?.data?.[region]) { const dataAtRegion = buckets.data[region].filter(({ Name: name }) => name === logConfiguration?.s3BucketName); for (const bucket of dataAtRegion) { connections.push({ id: ids_1.gets3BucketId(bucket.Name), resourceType: services_1.default.s3, relation: 'child', field: 's3', }); } } /** * Find Cloudwatch Log Group * related to this ecs cluster */ const logGroups = data.find(({ name }) => name === services_1.default.cloudwatchLog); let logGroupsInRegion = []; if (logGroups?.data?.[region]) { logGroupsInRegion = logGroups.data[region].filter(({ logGroupName }) => logGroupName === logConfiguration?.cloudWatchLogGroupName); } if (!lodash_1.isEmpty(logGroupsInRegion)) { for (const logGroup of logGroupsInRegion) { connections.push({ id: logGroup.logGroupName, resourceType: services_1.default.cloudwatchLog, relation: 'child', field: 'cloudwatchLog', }); } } /** * Find MKS * related to this ecs cluster */ const kms = data.find(({ name }) => name === services_1.default.kms); if (kms?.data?.[region]) { const kmsInRegion = kms.data[region].find(({ KeyArn }) => KeyArn === kmsKeyId); if (kmsInRegion) { connections.push({ id: kmsInRegion.KeyId, resourceType: services_1.default.kms, relation: 'child', field: 'kms', }); } } const natResult = { [arn]: connections, }; return natResult; };