UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

64 lines 2.44 kB
import { AwsClientPool } from '../aws/ClientPool.js'; import {} from '../aws/coreAuth.js'; import { AbstractClient } from './AbstractClient.js'; /** * AWS Config-based client pool using dedicated Config client classes with registry */ export class AbstractClientPool extends AwsClientPool { constructor() { super(); this.configClientCache = new Map(); this.clientRegistry = new Map(); this.registerDefaultClients(); } /** * Register the default supported clients */ registerDefaultClients() { } /** * Get the custom client context for a specific client type and configuration * @param ClientType The client constructor * @param credentials AWS credentials * @param region AWS region * @param endpoint Custom endpoint * @returns Custom client context */ getClientContext(ClientType, credentials, region, endpoint) { return {}; } /** * Register a Config client implementation - automatically extracts SDK client name * * @param customClientConstructor The custom client constructor */ registerClient(customClientConstructor) { this.clientRegistry.set(customClientConstructor.clientName, customClientConstructor); } /** * Returns a Config-based client that implements the same interface as the AWS SDK client * * @param ClientType The AWS SDK client constructor * @param credentials AWS credentials * @param region AWS region * @param endpoint Custom endpoint */ client(ClientType, credentials, region, endpoint) { const cacheKey = `${ClientType.name}:${credentials.accountId}:${credentials.cacheKey}:${region}`; if (this.configClientCache.has(cacheKey)) { return this.configClientCache.get(cacheKey); } const ClientConstructor = this.clientRegistry.get(ClientType.name); if (!ClientConstructor) { throw new Error(`No Config implementation registered for ${ClientType.name}`); } const customClientContext = this.getClientContext(ClientType, credentials, region, endpoint); const configClient = new ClientConstructor({ credentials, region, endpoint }, customClientContext); this.configClientCache.set(cacheKey, configClient); return configClient; } } //# sourceMappingURL=AbstractClientPool.js.map