UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

57 lines 2.32 kB
import { AccountClient, ListRegionsCommand } from '@aws-sdk/client-account'; import {} from '../../aws/coreAuth.js'; import { AbstractClient } from '../../customClients/AbstractClient.js'; import { awsConfigCommand } from '../AwsConfigClientContext.js'; import { executeConfigQuery, resourceStatusWhereClause } from '../awsConfigUtils.js'; /** * Account client implementation using AWS Config as data source */ export class AwsConfigAccountClient extends AbstractClient { constructor(options, customContext) { super(options, customContext); } /** * Register all Account command implementations */ registerCommands() { this.registerCommand(awsConfigCommand({ command: ListRegionsCommand, execute: async (input, context) => { const globalRegion = 'us-east-1'; const partition = context.partition; if (partition !== 'aws') { throw new Error(`Unknown global region for partition ${partition}. Please file an issue with the default region for your partition.`); } const accountId = context.accountId; const query = ` SELECT awsRegion WHERE accountId = '${accountId}' AND ${resourceStatusWhereClause} GROUP BY awsRegion `; const results = await executeConfigQuery(query, context); // Convert the results to the expected format const uniqueRegions = new Set(); results.forEach((resultString) => { const result = JSON.parse(resultString); if (result.awsRegion === 'global') { uniqueRegions.add(globalRegion); } else if (result.awsRegion) { uniqueRegions.add(result.awsRegion); } }); return { Regions: Array.from(uniqueRegions).map((regionName) => ({ RegionName: regionName })) }; } })); } } AwsConfigAccountClient.clientName = AccountClient.name; //# sourceMappingURL=AwsConfigAccountClient.js.map