cloud-report
Version:
Collects and analyzes cloud resources
44 lines (43 loc) • 1.92 kB
JavaScript
;
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 BucketAnalyticsCollector extends base_1.BaseCollector {
collect() {
return this.listAllBucketAnalytics();
}
async listAllBucketAnalytics() {
const s3 = this.getClient("S3", "us-east-1");
const bucketsCollector = new buckets_1.BucketsCollector();
bucketsCollector.setSession(this.getSession());
const bucket_analytics = {};
try {
const bucketsData = await utils_1.CollectorUtil.cachedCollect(bucketsCollector);
for (const bucket of bucketsData.buckets) {
bucket_analytics[bucket.Name] = [];
let fetchPending = true;
let marker;
try {
while (fetchPending) {
const s3BucketAnalyticsConfigOutput = await s3.listBucketAnalyticsConfigurations({ Bucket: bucket.Name, ContinuationToken: marker }).promise();
bucket_analytics[bucket.Name] =
bucket_analytics[bucket.Name].concat(s3BucketAnalyticsConfigOutput.AnalyticsConfigurationList);
marker = s3BucketAnalyticsConfigOutput.NextContinuationToken;
fetchPending = marker !== undefined;
await utils_1.CommonUtil.wait(200);
}
}
catch (err) {
aws_1.AWSErrorHandler.handle(err);
}
}
}
catch (err) {
aws_1.AWSErrorHandler.handle(err);
}
return { bucket_analytics };
}
}
exports.BucketAnalyticsCollector = BucketAnalyticsCollector;