UNPKG

@csermet/multiprovider

Version:

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

132 lines (131 loc) 5.8 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"); const ids_1 = require("../../utils/ids"); exports.default = ({ service, data, region, }) => { const connections = []; const { DBInstanceArn: id, VpcSecurityGroups, DBSubnetGroup, MonitoringRoleArn: monitoringRoleArn, AssociatedRoles: associatedRoles = [], PerformanceInsightsKMSKeyId, KmsKeyId, ActivityStreamKmsKeyId, DomainMemberships, EnhancedMonitoringResourceArn, Endpoint, } = service; const sgIds = VpcSecurityGroups.map(({ VpcSecurityGroupId }) => VpcSecurityGroupId); const subnetIds = (DBSubnetGroup?.Subnets || []).map(({ SubnetIdentifier }) => SubnetIdentifier); /** * Find Security Groups VPC Security Groups */ 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 */ const subnets = data.find(({ name }) => name === services_1.default.subnet); if (subnets?.data?.[region]) { const subnetsInRegion = subnets.data[region].filter((subnet) => subnetIds.includes(subnet.SubnetId)); if (!lodash_1.isEmpty(subnetsInRegion)) { for (const subnet of subnetsInRegion) { const { SubnetId } = subnet; connections.push({ id: SubnetId, resourceType: services_1.default.subnet, relation: 'child', field: 'subnet', }); } } } /** * Find Cloudwatch Logs */ const cloudwatchLogs = data.find(({ name }) => name === services_1.default.cloudwatchLog); if (cloudwatchLogs?.data?.[region]) { // Search the correspondent cloudwatch log group name for the rds logs // e.g. enhancedMonitoringArn arn:aws:logs:us-east-1::log-group:RDSOSMetrics:log-stream:db-databaseid // belongs to cloudwatchLogs group arn arn:aws:logs:us-east-1::log-group:RDSOSMetrics:* const cloudwatchLogsInRegion = cloudwatchLogs.data[region].filter(({ arn }) => arn && EnhancedMonitoringResourceArn?.includes(arn.substring(0, arn.length - 1))); if (!lodash_1.isEmpty(cloudwatchLogsInRegion)) { for (const cloudwatchLog of cloudwatchLogsInRegion) { connections.push({ id: cloudwatchLog.logGroupName, resourceType: services_1.default.cloudwatchLog, relation: 'child', field: 'cloudwatchLogs', }); } } } /** * Find Route53 Hosted Zone */ const route53HostedZones = data.find(({ name }) => name === services_1.default.route53HostedZone); if (route53HostedZones?.data?.[regions_1.globalRegionName]) { const route53HostedZonesInRegion = route53HostedZones.data[regions_1.globalRegionName].filter(({ Id }) => Endpoint?.HostedZoneId && Id.includes(Endpoint.HostedZoneId)); if (!lodash_1.isEmpty(route53HostedZonesInRegion)) { for (const route53HostedZone of route53HostedZonesInRegion) { connections.push({ id: ids_1.getHostedZoneId(route53HostedZone.Id), resourceType: services_1.default.route53HostedZone, relation: 'child', field: 'route53HostedZone', }); } } } /** * Find KMS */ const kmsKeys = data.find(({ name }) => name === services_1.default.kms); if (kmsKeys?.data?.[region]) { const kmsKeyInRegion = kmsKeys.data[region].filter(({ Arn }) => Arn === KmsKeyId || Arn === ActivityStreamKmsKeyId || Arn === PerformanceInsightsKMSKeyId); 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 IAM Role * related to this RDS Cluster */ 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, RoleName }) => Arn === monitoringRoleArn || associatedRoles.find(r => r.RoleArn === Arn) || DomainMemberships.find(d => d.IAMRoleName === RoleName)); if (!lodash_1.isEmpty(iamRolesInRegion)) { for (const instance of iamRolesInRegion) { connections.push({ id: instance.Arn, resourceType: services_1.default.iamRole, relation: 'child', field: 'iamRoles', }); } } } const rdsDbInstanceResult = { [id]: connections, }; return rdsDbInstanceResult; };