UNPKG

cloud-report

Version:

Collects and analyzes cloud resources

36 lines (35 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../../../utils"); const aws_1 = require("../../../utils/aws"); const base_1 = require("../../base"); const buckets_1 = require("./buckets"); class BucketPoliciesCollector extends base_1.BaseCollector { collect() { return this.listAllBucketPolicies(); } async listAllBucketPolicies() { const s3 = this.getClient("S3", "us-east-1"); const bucketsCollector = new buckets_1.BucketsCollector(); bucketsCollector.setSession(this.getSession()); const bucket_policies = {}; try { const bucketsData = await utils_1.CollectorUtil.cachedCollect(bucketsCollector); for (const bucket of bucketsData.buckets) { try { const s3BucketPolicy = await s3.getBucketPolicy({ Bucket: bucket.Name }).promise(); bucket_policies[bucket.Name] = s3BucketPolicy.Policy; } catch (err) { aws_1.AWSErrorHandler.handle(err); } await utils_1.CommonUtil.wait(200); } } catch (err) { aws_1.AWSErrorHandler.handle(err); } return { bucket_policies }; } } exports.BucketPoliciesCollector = BucketPoliciesCollector;