UNPKG

cloud-report

Version:

Collects and analyzes cloud resources

34 lines (33 loc) 1.29 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 iam_1 = require("../iam"); class AccountIdCollector extends base_1.BaseCollector { collect() { return this.getAccountId(); } async getAccountId() { try { const credentialsReportCollector = new iam_1.CredentialsReportCollector(); credentialsReportCollector.setSession(this.getSession()); const credsReportData = await utils_1.CollectorUtil.cachedCollect(credentialsReportCollector); if (credsReportData.credentials) { const rootAccountDetails = credsReportData.credentials.find((credential) => { return credential.user === "<root_account>"; }); if (rootAccountDetails) { return { id: this.getAccountIdFromArn(rootAccountDetails.arn) }; } } } catch (error) { aws_1.AWSErrorHandler.handle(error); } } getAccountIdFromArn(arn) { return arn.split(":")[4]; } } exports.AccountIdCollector = AccountIdCollector;