UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

75 lines 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractClient = void 0; /** * Base class for Custom AWS service clients */ class AbstractClient { customContext; config = {}; middlewareStack = {}; commandRegistry = new Map(); credentials; region; detailsCache = {}; cache(resourceId, type, data) { if (!this.detailsCache[resourceId]) { this.detailsCache[resourceId] = {}; } this.detailsCache[resourceId][type] = data; } getCached(resourceId, type) { const value = this.detailsCache[resourceId]?.[type]; if (!value) { return undefined; } delete this.detailsCache[resourceId][type]; // Clear empty cache entries if (Object.keys(this.detailsCache[resourceId] || {}).length === 0) { delete this.detailsCache[resourceId]; // Remove resourceId entry if empty } return value; } constructor(options, customContext) { this.customContext = customContext; this.credentials = options.credentials; this.region = options.region; this.registerCommands(); } getCustomClientContext() { return this.customContext; } /** * Register a command implementation */ registerCommand(customCommand) { this.commandRegistry.set(customCommand.commandName(), customCommand); } /** * Send a command using the registered implementation */ async send(command) { const commandName = command.constructor.name; const implementation = this.commandRegistry.get(commandName); if (!implementation) { throw new Error(`No Config implementation found for ${this.constructor.name}.${commandName}`); } const customContext = this.getCustomClientContext(); const context = { credentials: this.credentials, region: this.region, accountId: this.credentials.accountId, partition: this.credentials.partition, putCache: this.cache.bind(this), getCache: this.getCached.bind(this), ...customContext }; return implementation.execute(command.input, context); } /** * Destroy the client and cleanup resources */ destroy() { } } exports.AbstractClient = AbstractClient; //# sourceMappingURL=AbstractClient.js.map