@csermet/multiprovider
Version:
cloud-graph provider plugin for AWS used to fetch AWS cloud data.
57 lines (56 loc) • 2.21 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mwaa_1 = __importDefault(require("aws-sdk/clients/mwaa"));
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
const groupBy_1 = __importDefault(require("lodash/groupBy"));
const fetchUtils_1 = require("../../utils/fetchUtils");
const utils_1 = require("../../utils");
const errorLog_1 = __importDefault(require("../../utils/errorLog"));
const serviceName = 'managedAirflow';
const errorLog = new errorLog_1.default(serviceName);
const endpoint = utils_1.initTestEndpoint(serviceName);
/**
* ManagedAirflow
*/
exports.default = async ({ regions, config, }) => {
const result = [];
const activeRegions = regions.split(',');
for (const region of activeRegions) {
const client = new mwaa_1.default({ ...config, region, endpoint });
let envNames;
try {
envNames = await fetchUtils_1.fetchAllPaginatedData({
getResourcesFn: fetchUtils_1.convertToPromise({
sdkContext: client,
fnName: 'listEnvironments',
}),
accessor: '',
});
}
catch (err) {
errorLog.generateAwsErrorLog({ functionName: 'listEnvironments', err });
}
if (!isEmpty_1.default(envNames)) {
const promises = [];
envNames.forEach(async (name) => {
try {
promises.push(client.getEnvironment({ Name: name }).promise());
}
catch (err) {
errorLog.generateAwsErrorLog({ functionName: 'getEnvironments', err });
}
});
await Promise.all(promises)
.then(envs => envs.forEach(val => result.push({ ...val.Environment, region })))
.catch(err => errorLog.generateAwsErrorLog({
functionName: 'getEnvironments',
err,
}));
}
}
errorLog.reset();
return groupBy_1.default(result, 'region');
};