UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

58 lines 2.3 kB
import { DescribeVpcEndpointsCommand, EC2Client } from '@aws-sdk/client-ec2'; import {} from '../../aws/coreAuth.js'; import { AbstractClient } from '../../customClients/AbstractClient.js'; import { awsConfigCommand } from '../AwsConfigClientContext.js'; import { executeConfigQuery, parseConfigItem, resourceStatusWhereClause } from '../awsConfigUtils.js'; /** * AWS Config-based EC2 client implementation */ export class AwsConfigEC2Client extends AbstractClient { constructor(options, customContext) { super(options, customContext); } /** * Register all EC2 command implementations */ registerCommands() { this.registerCommand(AwsConfigDescribeVpcEndpointsCommand); } } AwsConfigEC2Client.clientName = EC2Client.name; /** * Config-based implementation of EC2 DescribeVpcEndpointsCommand * Retrieves VPC endpoint information including endpoint policies from AWS Config */ const AwsConfigDescribeVpcEndpointsCommand = awsConfigCommand({ command: DescribeVpcEndpointsCommand, execute: async (input, context) => { let query = ` SELECT configuration.vpcEndpointId, configuration.vpcEndpointType, configuration.serviceName, configuration.policyDocument WHERE resourceType = 'AWS::EC2::VPCEndpoint' AND awsRegion = '${context.region}' AND accountId = '${context.accountId}' AND ${resourceStatusWhereClause} `; const results = await executeConfigQuery(query, context); // Transform Config results to match AWS SDK format with only essential fields const vpcEndpoints = results.map((resultString) => { const { configItem } = parseConfigItem(resultString); const config = configItem.configuration || {}; return { VpcEndpointId: config.vpcEndpointId, VpcEndpointType: config.vpcEndpointType, ServiceName: config.serviceName, PolicyDocument: config.policyDocument // The endpoint policy as a string }; }); return { VpcEndpoints: vpcEndpoints, NextToken: undefined // Config doesn't support pagination in this context }; } }); //# sourceMappingURL=AwsConfigEC2Client.js.map