UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

54 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiGatewayIndexer = void 0; const iam_utils_1 = require("@cloud-copilot/iam-utils"); const indexName = 'apigateways-to-accounts'; exports.ApiGatewayIndexer = { awsService: 'apigateway', name: 'apigatewaysToAccounts', getCache: async (storage) => { const data = await storage.getIndex(indexName, {}); return data; }, saveCache: async (storage, cache, lockId) => { return storage.saveIndex(indexName, cache, lockId); }, updateCache: async (existingCache, accountId, regions, storage) => { const regionsSet = new Set(regions); const matchesRegion = (region) => { return region && (regionsSet.size == 0 || regionsSet.has(region)); }; const currentCacheKeys = Object.keys(existingCache); // Remove all existing gateways for the account in the specified regions for (const key of currentCacheKeys) { const arnParts = (0, iam_utils_1.splitArnParts)(key); if (existingCache[key] == accountId && matchesRegion(arnParts.region)) { delete existingCache[key]; } } const currentGateways = []; if (regions.length == 0) { const gateways = await storage.findResourceMetadata(accountId, { service: 'apigateway', region: '*', resourceType: 'restapis' }); currentGateways.push(...gateways); } else { for (const region of regions) { const gateways = await storage.findResourceMetadata(accountId, { service: 'apigateway', region: region, resourceType: 'restapis' }); currentGateways.push(...gateways); } } // Add the new gateways to the cache for (const gateway of currentGateways) { existingCache[gateway.arn] = accountId; } } }; //# sourceMappingURL=apigateways.js.map