UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

154 lines 6.06 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cli_1 = require("@cloud-copilot/cli"); const analyze_js_1 = require("./analysis/analyze.js"); const configFile_js_1 = require("./config/configFile.js"); const createConfigFile_js_1 = require("./config/createConfigFile.js"); const defaultConfig_js_1 = require("./config/defaultConfig.js"); const packageVersion_js_1 = require("./config/packageVersion.js"); const download_js_1 = require("./download/download.js"); const index_js_1 = require("./index/index.js"); const log_js_1 = require("./utils/log.js"); const main = async () => { const version = await (0, packageVersion_js_1.iamCollectVersion)(); const cli = (0, cli_1.parseCliArguments)('iam-collect', { init: { description: 'Initialize the iam-collect configuration file', options: {} }, download: { description: 'Download IAM data and update indexes', options: { configFiles: { type: 'string', description: 'The configuration files to use', values: 'multiple' }, accounts: { type: 'string', description: 'The account IDs to download from', values: 'multiple' }, regions: { type: 'string', description: 'The regions to download from', values: 'multiple' }, services: { type: 'string', description: 'The services to download', values: 'multiple' }, concurrency: { type: 'number', description: 'The maximum number of concurrent downloads to allow. Defaults based on your system CPUs', values: 'single' }, noIndex: { type: 'boolean', description: 'Skip refreshing the indexes after downloading', character: 'n' } } }, index: { description: 'Refresh the IAM data indexes', options: { configFiles: { type: 'string', description: 'The configuration files to use', values: 'multiple' }, partition: { type: 'string', description: 'The partition to refresh index data for. Defaults to aws', values: 'single' }, accounts: { type: 'string', description: 'The account IDs to refresh index data for', values: 'multiple' }, regions: { type: 'string', description: 'The regions to refresh index data for', values: 'multiple' }, services: { type: 'string', description: 'The services to refresh index data for', values: 'multiple' }, concurrency: { type: 'number', description: 'The maximum number of concurrent indexers to run. Defaults based on your system CPUs', values: 'single' } } }, 'analyze-logs': { description: 'Analyze iam-collect trace logs and summarize job execution times', options: { logFile: { type: 'string', description: 'The path to the log file to analyze', values: 'single' } } } }, { log: { type: 'enum', description: 'The log level to use', values: 'single', validValues: log_js_1.LogLevels } }, { envPrefix: 'IAM_COLLECT', showHelpIfNoArgs: true, requireSubcommand: true, version: version }); if (cli.args.log) { (0, log_js_1.setLogLevel)(cli.args.log); } if (cli.subcommand === 'init') { if ((0, defaultConfig_js_1.defaultConfigExists)()) { console.error('Configuration file already exists'); process.exit(1); } console.log('Initializing...'); await (0, createConfigFile_js_1.createDefaultConfiguration)(); } else if (cli.subcommand === 'download') { const defaultConfig = './iam-collect.jsonc'; const configFiles = cli.args.configFiles?.length > 0 ? cli.args.configFiles : [defaultConfig]; const configs = (0, configFile_js_1.loadConfigFiles)(configFiles); await (0, download_js_1.downloadData)(configs, cli.args.accounts, cli.args.regions, cli.args.services, cli.args.concurrency, cli.args.noIndex); } else if (cli.subcommand === 'index') { const defaultConfig = './iam-collect.jsonc'; const configFiles = cli.args.configFiles?.length > 0 ? cli.args.configFiles : [defaultConfig]; const configs = (0, configFile_js_1.loadConfigFiles)(configFiles); await (0, index_js_1.index)(configs, cli.args.partition || 'aws', cli.args.accounts, cli.args.regions, cli.args.services, cli.args.concurrency); } else if (cli.subcommand === 'analyze-logs') { if (!cli.args.logFile) { console.error('You must specify a log file to analyze using --log-file'); process.exit(1); } const allComplete = await (0, analyze_js_1.conductLogAnalysis)(cli.args.logFile); if (!allComplete) { process.exit(1); } } }; main() .catch((e) => { console.error(e); process.exit(1); }) .then(() => { }) .finally(() => { }); //# sourceMappingURL=cli.js.map