@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
70 lines • 2.37 kB
JavaScript
import {} from '../aws/coreAuth.js';
import {} from './AbstractCommand.js';
/**
* Base class for Custom AWS service clients
*/
export class AbstractClient {
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.config = {};
this.middlewareStack = {};
this.commandRegistry = new Map();
this.detailsCache = {};
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() { }
}
//# sourceMappingURL=AbstractClient.js.map