|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// API Gateway Commands |
| 4 | +const { |
| 5 | + GetAccountCommand, |
| 6 | + UpdateAccountCommand, |
| 7 | + GetApiKeyCommand, |
| 8 | + CreateStageCommand, |
| 9 | + GetUsagePlansCommand, |
| 10 | + UpdateUsagePlanCommand, |
| 11 | + TagResourceCommand, |
| 12 | + UntagResourceCommand, |
| 13 | + UpdateStageCommand, |
| 14 | +} = require('@aws-sdk/client-api-gateway'); |
| 15 | + |
| 16 | +// API Gateway V2 Commands |
| 17 | +const { GetApiCommand } = require('@aws-sdk/client-apigatewayv2'); |
| 18 | + |
| 19 | +// CloudFormation Commands |
| 20 | +const { |
| 21 | + CreateStackCommand, |
| 22 | + CreateChangeSetCommand, |
| 23 | + DeleteChangeSetCommand, |
| 24 | + ExecuteChangeSetCommand, |
| 25 | + UpdateStackCommand, |
| 26 | + DeleteStackCommand, |
| 27 | + DescribeStacksCommand, |
| 28 | + ValidateTemplateCommand, |
| 29 | + SetStackPolicyCommand, |
| 30 | + GetTemplateCommand, |
| 31 | + ListStackResourcesCommand, |
| 32 | + DescribeStackResourceCommand, |
| 33 | + DescribeStackEventsCommand, |
| 34 | + ListExportsCommand, |
| 35 | +} = require('@aws-sdk/client-cloudformation'); |
| 36 | + |
| 37 | +// CloudWatch Commands |
| 38 | +const { GetMetricStatisticsCommand } = require('@aws-sdk/client-cloudwatch'); |
| 39 | + |
| 40 | +// CloudWatch Logs Commands |
| 41 | +const { |
| 42 | + DescribeLogStreamsCommand, |
| 43 | + FilterLogEventsCommand, |
| 44 | + DeleteSubscriptionFilterCommand, |
| 45 | +} = require('@aws-sdk/client-cloudwatch-logs'); |
| 46 | + |
| 47 | +// Cognito Identity Provider Commands |
| 48 | +const { |
| 49 | + ListUserPoolsCommand, |
| 50 | + DescribeUserPoolCommand, |
| 51 | + UpdateUserPoolCommand, |
| 52 | +} = require('@aws-sdk/client-cognito-identity-provider'); |
| 53 | + |
| 54 | +// ECR Commands |
| 55 | +const { |
| 56 | + DeleteRepositoryCommand, |
| 57 | + DescribeRepositoriesCommand, |
| 58 | + GetAuthorizationTokenCommand, |
| 59 | + CreateRepositoryCommand, |
| 60 | + DescribeImagesCommand, |
| 61 | +} = require('@aws-sdk/client-ecr'); |
| 62 | + |
| 63 | +// EventBridge Commands |
| 64 | +const { |
| 65 | + CreateEventBusCommand, |
| 66 | + DeleteEventBusCommand, |
| 67 | + PutRuleCommand, |
| 68 | + DeleteRuleCommand, |
| 69 | + PutTargetsCommand, |
| 70 | + RemoveTargetsCommand, |
| 71 | +} = require('@aws-sdk/client-eventbridge'); |
| 72 | + |
| 73 | +// IAM Commands |
| 74 | +const { |
| 75 | + GetRoleCommand, |
| 76 | + ListAttachedRolePoliciesCommand, |
| 77 | + CreateRoleCommand, |
| 78 | + AttachRolePolicyCommand, |
| 79 | +} = require('@aws-sdk/client-iam'); |
| 80 | + |
| 81 | +// Lambda Commands |
| 82 | +const { |
| 83 | + GetFunctionCommand, |
| 84 | + UpdateFunctionConfigurationCommand, |
| 85 | + UpdateFunctionCodeCommand, |
| 86 | + InvokeCommand, |
| 87 | + ListVersionsByFunctionCommand, |
| 88 | + GetLayerVersionCommand, |
| 89 | + AddPermissionCommand, |
| 90 | + RemovePermissionCommand, |
| 91 | +} = require('@aws-sdk/client-lambda'); |
| 92 | + |
| 93 | +// S3 Commands |
| 94 | +const { |
| 95 | + ListObjectsV2Command, |
| 96 | + ListObjectVersionsCommand, |
| 97 | + DeleteObjectsCommand, |
| 98 | + HeadObjectCommand, |
| 99 | + PutObjectCommand, |
| 100 | + GetObjectCommand, |
| 101 | + GetBucketLocationCommand, |
| 102 | + HeadBucketCommand, |
| 103 | + GetBucketNotificationConfigurationCommand, |
| 104 | + PutBucketNotificationConfigurationCommand, |
| 105 | +} = require('@aws-sdk/client-s3'); |
| 106 | + |
| 107 | +// SSM Commands |
| 108 | +const { GetParameterCommand } = require('@aws-sdk/client-ssm'); |
| 109 | + |
| 110 | +// STS Commands |
| 111 | +const { GetCallerIdentityCommand } = require('@aws-sdk/client-sts'); |
| 112 | + |
| 113 | +/** |
| 114 | + * Map v2 method names to v3 command classes |
| 115 | + * Format: { ServiceName: { methodName: CommandClass } } |
| 116 | + */ |
| 117 | +const COMMAND_MAP = { |
| 118 | + APIGateway: { |
| 119 | + getAccount: GetAccountCommand, |
| 120 | + updateAccount: UpdateAccountCommand, |
| 121 | + getApiKey: GetApiKeyCommand, |
| 122 | + createStage: CreateStageCommand, |
| 123 | + getUsagePlans: GetUsagePlansCommand, |
| 124 | + updateUsagePlan: UpdateUsagePlanCommand, |
| 125 | + tagResource: TagResourceCommand, |
| 126 | + untagResource: UntagResourceCommand, |
| 127 | + updateStage: UpdateStageCommand, |
| 128 | + }, |
| 129 | + |
| 130 | + ApiGatewayV2: { |
| 131 | + getApi: GetApiCommand, |
| 132 | + }, |
| 133 | + |
| 134 | + CloudFormation: { |
| 135 | + createStack: CreateStackCommand, |
| 136 | + createChangeSet: CreateChangeSetCommand, |
| 137 | + deleteChangeSet: DeleteChangeSetCommand, |
| 138 | + executeChangeSet: ExecuteChangeSetCommand, |
| 139 | + updateStack: UpdateStackCommand, |
| 140 | + deleteStack: DeleteStackCommand, |
| 141 | + describeStacks: DescribeStacksCommand, |
| 142 | + validateTemplate: ValidateTemplateCommand, |
| 143 | + setStackPolicy: SetStackPolicyCommand, |
| 144 | + getTemplate: GetTemplateCommand, |
| 145 | + listStackResources: ListStackResourcesCommand, |
| 146 | + describeStackResource: DescribeStackResourceCommand, |
| 147 | + describeStackEvents: DescribeStackEventsCommand, |
| 148 | + listExports: ListExportsCommand, |
| 149 | + }, |
| 150 | + |
| 151 | + CloudWatch: { |
| 152 | + getMetricStatistics: GetMetricStatisticsCommand, |
| 153 | + }, |
| 154 | + |
| 155 | + CloudWatchLogs: { |
| 156 | + describeLogStreams: DescribeLogStreamsCommand, |
| 157 | + filterLogEvents: FilterLogEventsCommand, |
| 158 | + deleteSubscriptionFilter: DeleteSubscriptionFilterCommand, |
| 159 | + }, |
| 160 | + |
| 161 | + CognitoIdentityProvider: { |
| 162 | + listUserPools: ListUserPoolsCommand, |
| 163 | + describeUserPool: DescribeUserPoolCommand, |
| 164 | + updateUserPool: UpdateUserPoolCommand, |
| 165 | + }, |
| 166 | + |
| 167 | + ECR: { |
| 168 | + deleteRepository: DeleteRepositoryCommand, |
| 169 | + describeRepositories: DescribeRepositoriesCommand, |
| 170 | + getAuthorizationToken: GetAuthorizationTokenCommand, |
| 171 | + createRepository: CreateRepositoryCommand, |
| 172 | + describeImages: DescribeImagesCommand, |
| 173 | + }, |
| 174 | + |
| 175 | + EventBridge: { |
| 176 | + createEventBus: CreateEventBusCommand, |
| 177 | + deleteEventBus: DeleteEventBusCommand, |
| 178 | + putRule: PutRuleCommand, |
| 179 | + deleteRule: DeleteRuleCommand, |
| 180 | + putTargets: PutTargetsCommand, |
| 181 | + removeTargets: RemoveTargetsCommand, |
| 182 | + }, |
| 183 | + |
| 184 | + IAM: { |
| 185 | + getRole: GetRoleCommand, |
| 186 | + listAttachedRolePolicies: ListAttachedRolePoliciesCommand, |
| 187 | + createRole: CreateRoleCommand, |
| 188 | + attachRolePolicy: AttachRolePolicyCommand, |
| 189 | + }, |
| 190 | + |
| 191 | + Lambda: { |
| 192 | + getFunction: GetFunctionCommand, |
| 193 | + updateFunctionConfiguration: UpdateFunctionConfigurationCommand, |
| 194 | + updateFunctionCode: UpdateFunctionCodeCommand, |
| 195 | + invoke: InvokeCommand, |
| 196 | + listVersionsByFunction: ListVersionsByFunctionCommand, |
| 197 | + getLayerVersion: GetLayerVersionCommand, |
| 198 | + addPermission: AddPermissionCommand, |
| 199 | + removePermission: RemovePermissionCommand, |
| 200 | + }, |
| 201 | + |
| 202 | + S3: { |
| 203 | + listObjectsV2: ListObjectsV2Command, |
| 204 | + listObjectVersions: ListObjectVersionsCommand, |
| 205 | + deleteObjects: DeleteObjectsCommand, |
| 206 | + headObject: HeadObjectCommand, |
| 207 | + putObject: PutObjectCommand, |
| 208 | + getObject: GetObjectCommand, |
| 209 | + getBucketLocation: GetBucketLocationCommand, |
| 210 | + headBucket: HeadBucketCommand, |
| 211 | + getBucketNotificationConfiguration: GetBucketNotificationConfigurationCommand, |
| 212 | + putBucketNotificationConfiguration: PutBucketNotificationConfigurationCommand, |
| 213 | + // Note: upload is handled separately as it's not a direct API call |
| 214 | + }, |
| 215 | + |
| 216 | + SSM: { |
| 217 | + getParameter: GetParameterCommand, |
| 218 | + }, |
| 219 | + |
| 220 | + STS: { |
| 221 | + getCallerIdentity: GetCallerIdentityCommand, |
| 222 | + }, |
| 223 | +}; |
| 224 | + |
| 225 | +/** |
| 226 | + * Get command class for a service method |
| 227 | + * @param {string} serviceName - AWS service name |
| 228 | + * @param {string} methodName - Method name from v2 SDK |
| 229 | + * @returns {Function} Command class constructor |
| 230 | + */ |
| 231 | +function getCommand(serviceName, methodName) { |
| 232 | + const serviceCommands = COMMAND_MAP[serviceName]; |
| 233 | + if (!serviceCommands) { |
| 234 | + throw new Error(`Unknown AWS service: ${serviceName}`); |
| 235 | + } |
| 236 | + |
| 237 | + const CommandClass = serviceCommands[methodName]; |
| 238 | + if (!CommandClass) { |
| 239 | + throw new Error(`Unknown method '${methodName}' for service '${serviceName}'`); |
| 240 | + } |
| 241 | + |
| 242 | + return CommandClass; |
| 243 | +} |
| 244 | + |
| 245 | +/** |
| 246 | + * Create a command instance for a service method |
| 247 | + * @param {string} serviceName - AWS service name |
| 248 | + * @param {string} methodName - Method name from v2 SDK |
| 249 | + * @param {Object} params - Parameters for the command |
| 250 | + * @returns {Object} Command instance |
| 251 | + */ |
| 252 | +function createCommand(serviceName, methodName, params = {}) { |
| 253 | + const CommandClass = getCommand(serviceName, methodName); |
| 254 | + return new CommandClass(params); |
| 255 | +} |
| 256 | + |
| 257 | +module.exports = { |
| 258 | + createCommand, |
| 259 | +}; |
0 commit comments