UNPKG

@csermet/multiprovider

Version:

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

69 lines (68 loc) 2.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const cloudformation_1 = __importDefault(require("aws-sdk/clients/cloudformation")); const lodash_1 = require("lodash"); const utils_1 = require("../../utils"); const errorLog_1 = __importDefault(require("../../utils/errorLog")); const format_1 = require("../../utils/format"); const serviceName = 'CloudFormationStackSet'; const errorLog = new errorLog_1.default(serviceName); const endpoint = utils_1.initTestEndpoint(serviceName); const listStackSets = async (cf) => { try { const fullStackSets = []; let stackSets = await cf.listStackSets().promise(); fullStackSets.push(...stackSets.Summaries); let nextToken = stackSets.NextToken; while (nextToken) { stackSets = await cf.listStackSets({ NextToken: nextToken }).promise(); fullStackSets.push(...stackSets.Summaries); nextToken = stackSets.NextToken; } return fullStackSets; } catch (err) { errorLog.generateAwsErrorLog({ functionName: 'CloudFormationStackSet:listStackSets', err, }); } return []; }; const describeStackSet = async (cf, StackSetName) => { try { const stackSetData = await cf.describeStackSet({ StackSetName }).promise(); return stackSetData.StackSet; } catch (err) { errorLog.generateAwsErrorLog({ functionName: 'CloudFormationStackSet:describeStackSet', err, }); } return null; }; exports.default = async ({ regions, config, }) => { const cfStackSetData = []; for (const region of regions.split(',')) { const cf = new cloudformation_1.default({ ...config, region, endpoint }); const stackSets = await listStackSets(cf); const describeStackSetPromises = []; for (const stackSet of stackSets) { describeStackSetPromises.push(describeStackSet(cf, stackSet.StackSetName)); } const stackSetList = await Promise.all(describeStackSetPromises); if (!lodash_1.isEmpty(stackSetList)) { cfStackSetData.push(...stackSetList.map((stackSet) => ({ ...stackSet, Tags: format_1.convertAwsTagsToTagMap(stackSet.Tags), region, }))); } } errorLog.reset(); return lodash_1.groupBy(cfStackSetData, 'region'); };