@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
144 lines • 5.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AwsConfigKafkaClient = void 0;
const client_kafka_1 = require("@aws-sdk/client-kafka");
const AbstractClient_js_1 = require("../../customClients/AbstractClient.js");
const ResourceNotFoundException_js_1 = require("../../customClients/ResourceNotFoundException.js");
const json_js_1 = require("../../utils/json.js");
const AwsConfigClientContext_js_1 = require("../AwsConfigClientContext.js");
const awsConfigUtils_js_1 = require("../awsConfigUtils.js");
/**
* AWS Config-based Kafka client implementation
*/
class AwsConfigKafkaClient extends AbstractClient_js_1.AbstractClient {
static clientName = client_kafka_1.KafkaClient.name;
constructor(options, customContext) {
super(options, customContext);
}
/**
* Register all Kafka command implementations
*/
registerCommands() {
this.registerCommand(AwsConfigListClustersV2Command);
this.registerCommand(AwsConfigDescribeClusterCommand);
this.registerCommand(AwsConfigGetClusterPolicyCommand);
this.registerCommand(AwsConfigListTagsForResourceCommand);
}
}
exports.AwsConfigKafkaClient = AwsConfigKafkaClient;
/**
* Config-based implementation of Kafka ListClustersV2Command
*/
const AwsConfigListClustersV2Command = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_kafka_1.ListClustersV2Command,
execute: async (input, context) => {
// Query AWS Config for all MSK clusters with only needed configuration fields
const query = `
SELECT
resourceId,
resourceName,
awsRegion,
configuration.EncryptionInfo,
configuration.Policy,
tags
WHERE
resourceType = 'AWS::MSK::Cluster'
AND accountId = '${context.accountId}'
AND awsRegion = '${context.region}'
AND ${awsConfigUtils_js_1.resourceStatusWhereClause}
`;
const items = await (0, awsConfigUtils_js_1.executeConfigQuery)(query, context);
// Transform Config data to ListClustersV2Response format
const clusterInfoList = items.map((item) => {
const { configItem, configuration, tags } = (0, awsConfigUtils_js_1.parseConfigItem)(item);
// Cache data that will be needed by other commands
const clusterArn = configItem.resourceId;
context.putCache(clusterArn, 'configuration', configuration);
context.putCache(clusterArn, 'resourceName', configItem.resourceName);
context.putCache(clusterArn, 'tags', tags);
return {
ClusterArn: clusterArn,
ClusterName: configItem.resourceName,
Tags: tags || {}
};
});
return {
ClusterInfoList: clusterInfoList
};
}
});
/**
* Config-based implementation of Kafka DescribeClusterCommand
*/
const AwsConfigDescribeClusterCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_kafka_1.DescribeClusterCommand,
execute: async (input, context) => {
const { ClusterArn } = input;
if (!ClusterArn) {
throw new Error('ClusterArn is required for DescribeClusterCommand');
}
const configuration = context.getCache(ClusterArn, 'configuration');
const resourceName = context.getCache(ClusterArn, 'resourceName');
// Transform Config data to DescribeClusterResponse format
return {
ClusterInfo: {
ClusterArn: ClusterArn,
ClusterName: configuration?.clusterName || resourceName,
EncryptionInfo: configuration?.encryptionInfo
}
};
}
});
/**
* Config-based implementation of Kafka GetClusterPolicyCommand
*/
const AwsConfigGetClusterPolicyCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_kafka_1.GetClusterPolicyCommand,
execute: async (input, context) => {
const { ClusterArn } = input;
if (!ClusterArn) {
throw new Error('ClusterArn is required for GetClusterPolicyCommand');
}
// Query AWS Config for MSK cluster policy
const query = `
SELECT
resourceId,
configuration.clusterArn,
configuration.Policy
WHERE
resourceType = 'AWS::MSK::ClusterPolicy'
AND resourceId = '${ClusterArn}'
AND awsRegion = '${context.region}'
AND accountId = '${context.accountId}'
AND ${awsConfigUtils_js_1.resourceStatusWhereClause}
`;
const items = await (0, awsConfigUtils_js_1.executeConfigQuery)(query, context);
if (items.length === 0) {
throw new ResourceNotFoundException_js_1.ResourceNotFoundException(`Cluster policy not found for cluster: ${ClusterArn}`);
}
const { configuration } = (0, awsConfigUtils_js_1.parseConfigItem)(items[0]);
// Transform Config data to GetClusterPolicyResponse format
return {
CurrentVersion: '1', // Config doesn't track policy version, use default
Policy: (0, json_js_1.stringifyIfPresent)(configuration.Policy)
};
}
});
/**
* Config-based implementation of Kafka ListTagsForResourceCommand
*/
const AwsConfigListTagsForResourceCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_kafka_1.ListTagsForResourceCommand,
execute: async (input, context) => {
const { ResourceArn } = input;
if (!ResourceArn) {
throw new Error('ResourceArn is required for ListTagsForResourceCommand');
}
const tags = context.getCache(ResourceArn, 'tags');
// Transform Config data to ListTagsForResourceResponse format
return {
Tags: tags
};
}
});
//# sourceMappingURL=AwsConfigKafkaClient.js.map