@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
66 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractClientPool = void 0;
const ClientPool_js_1 = require("../aws/ClientPool.js");
/**
* AWS Config-based client pool using dedicated Config client classes with registry
*/
class AbstractClientPool extends ClientPool_js_1.AwsClientPool {
configClientCache = new Map();
clientRegistry = new Map();
constructor() {
super();
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;
}
}
exports.AbstractClientPool = AbstractClientPool;
//# sourceMappingURL=AbstractClientPool.js.map