UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

57 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VpcEndpointIndexer = void 0; const iam_utils_1 = require("@cloud-copilot/iam-utils"); const indexName = 'vpcs-to-endpoints'; exports.VpcEndpointIndexer = { awsService: 'ec2', name: 'vpcsToEndpoints', 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 vpcs for the account in the specified regions for (const key of currentCacheKeys) { const arnParts = (0, iam_utils_1.splitArnParts)(key); if (arnParts.accountId == accountId && matchesRegion(arnParts.region)) { delete existingCache[key]; } } const currentEndpoints = []; if (regions.length == 0) { const gateways = await storage.findResourceMetadata(accountId, { service: 'ec2', region: '*', resourceType: 'vpc-endpoint' }); currentEndpoints.push(...gateways); } else { for (const region of regions) { const gateways = await storage.findResourceMetadata(accountId, { service: 'ec2', region: region, resourceType: 'vpc-endpoint' }); currentEndpoints.push(...gateways); } } for (const endpoint of currentEndpoints) { const vpcId = endpoint.vpc; if (!existingCache[vpcId]) { existingCache[vpcId] = []; } existingCache[vpcId].push(endpoint.arn); } } }; //# sourceMappingURL=vpcEndpoints.js.map