From c6baf122b6d6970c2b8dee013e0dfc9917ac0c51 Mon Sep 17 00:00:00 2001 From: Ran Ribenzaft Date: Tue, 6 Apr 2021 20:15:24 +0300 Subject: [PATCH] feat(aws-sdk.js): support cognito calls (#470) --- src/events/aws_sdk.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/events/aws_sdk.js b/src/events/aws_sdk.js index a772aa48..a4c809f7 100644 --- a/src/events/aws_sdk.js +++ b/src/events/aws_sdk.js @@ -781,6 +781,37 @@ const CloudWatchEventsEventCreator = { }, }; + +const CognitoIDPEventsEventCreator = { + /** + * Updates an event with the appropriate fields from an AWS Cognito IDP Events request + * @param {object} request The AWS.Request object + * @param {proto.event_pb.Event} event The event to update the data on + */ + requestHandler(request, event) { + const parameters = request.params || {}; + const resource = event.getResource(); + if (parameters.UserPoolId) { + resource.setName(parameters.UserPoolId); + } + resource.setType('cognito-idp'); + eventInterface.addToMetadata(event, {}, { + 'aws.cognito.request': parameters, + }); + }, + + /** + * Updates an event with the appropriate fields from an AWS Cognito IDP Events response + * @param {object} response The AWS.Response object + * @param {proto.event_pb.Event} event The event to update the data on + */ + responseHandler(response, event) { + eventInterface.addToMetadata(event, {}, { + 'aws.cognito.response': response.data, + }); + }, +}; + const CloudWatchLogsEventCreator = { /** * Updates an event with the appropriate fields from an AWS CloudWatch Logs request @@ -888,6 +919,7 @@ const specificEventCreators = { stepfunctions: stepFunctionsEventCreator, batch: batchEventCreator, cloudwatchevents: CloudWatchEventsEventCreator, + cognitoidentityserviceprovider: CognitoIDPEventsEventCreator, eventbridge: CloudWatchEventsEventCreator, cloudwatchlogs: CloudWatchLogsEventCreator, ssm: SSMEventCreator, @@ -905,6 +937,7 @@ function AWSSDKWrapper(wrappedFunction) { const { serviceIdentifier } = ( request.service.constructor.prototype ); + if (!(serviceIdentifier in specificEventCreators)) { // resource is not supported yet return wrappedFunction.apply(this, [callback]);