@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
40 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.S3BucketIndexer = void 0;
const indexName = 'buckets-to-accounts';
exports.S3BucketIndexer = {
awsService: 's3',
name: 'bucketsToAccounts',
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 buckets for the account in the specified regions
for (const key of currentCacheKeys) {
if (existingCache[key].accountId == accountId && matchesRegion(existingCache[key].region)) {
delete existingCache[key];
}
}
const currentBuckets = await storage.findResourceMetadata(accountId, {
service: 's3'
});
for (const bucket of currentBuckets) {
if (matchesRegion(bucket.region)) {
existingCache[bucket.name] = {
accountId: accountId,
region: bucket.region
};
}
}
}
};
//# sourceMappingURL=buckets.js.map