diff --git a/cdk/lib/__snapshots__/support-reminders.test.ts.snap b/cdk/lib/__snapshots__/support-reminders.test.ts.snap index c806d1f..33f9ff1 100644 --- a/cdk/lib/__snapshots__/support-reminders.test.ts.snap +++ b/cdk/lib/__snapshots__/support-reminders.test.ts.snap @@ -350,8 +350,10 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Type": "AWS::IAM::Role", "UpdateReplacePolicy": "Retain", }, - "RestApiDeployment180EC503fcf0333a4041292d1f2defc7f14d62da": { + "RestApiDeployment180EC503a345def70b385514941e7a699c9d376f": { "DependsOn": [ + "oneoffvalidator0C4177E4", + "recurringvalidatorA3C040BF", "RestApicancelOPTIONS8CB256F3", "RestApicancelPOST51F94A62", "RestApicancel928D6387", @@ -382,7 +384,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` ], "Properties": { "DeploymentId": { - "Ref": "RestApiDeployment180EC503fcf0333a4041292d1f2defc7f14d62da", + "Ref": "RestApiDeployment180EC503a345def70b385514941e7a699c9d376f", }, "RestApiId": { "Ref": "RestApi0C43BF4B", @@ -791,6 +793,12 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "StatusCode": "200", }, ], + "RequestParameters": { + "method.request.header.X-GU-GeoIP-Country-Code": true, + }, + "RequestValidatorId": { + "Ref": "oneoffvalidator0C4177E4", + }, "ResourceId": { "Ref": "RestApicreateoneoff2D1FCD3C", }, @@ -911,6 +919,12 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "StatusCode": "200", }, ], + "RequestParameters": { + "method.request.header.X-GU-GeoIP-Country-Code": true, + }, + "RequestValidatorId": { + "Ref": "recurringvalidatorA3C040BF", + }, "ResourceId": { "Ref": "RestApicreaterecurringA327119C", }, @@ -2211,6 +2225,15 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` }, "Type": "AWS::Events::Rule", }, + "oneoffvalidator0C4177E4": { + "Properties": { + "RestApiId": { + "Ref": "RestApi0C43BF4B", + }, + "ValidateRequestParameters": true, + }, + "Type": "AWS::ApiGateway::RequestValidator", + }, "reactivaterecurringreminder0045F57B": { "DependsOn": [ "reactivaterecurringreminderServiceRoleDefaultPolicyA6827EC3", @@ -2444,6 +2467,15 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` }, "Type": "AWS::IAM::Policy", }, + "recurringvalidatorA3C040BF": { + "Properties": { + "RestApiId": { + "Ref": "RestApi0C43BF4B", + }, + "ValidateRequestParameters": true, + }, + "Type": "AWS::ApiGateway::RequestValidator", + }, "signupexportsDBFAB572": { "DependsOn": [ "signupexportsServiceRoleDefaultPolicy7B14F7DA", @@ -3322,8 +3354,10 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Type": "AWS::IAM::Role", "UpdateReplacePolicy": "Retain", }, - "RestApiDeployment180EC503aeb5683c0cd969c7e8fc564945b91afc": { + "RestApiDeployment180EC503527c2dadd44b8927ecf4437252adb507": { "DependsOn": [ + "oneoffvalidator0C4177E4", + "recurringvalidatorA3C040BF", "RestApicancelOPTIONS8CB256F3", "RestApicancelPOST51F94A62", "RestApicancel928D6387", @@ -3354,7 +3388,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` ], "Properties": { "DeploymentId": { - "Ref": "RestApiDeployment180EC503aeb5683c0cd969c7e8fc564945b91afc", + "Ref": "RestApiDeployment180EC503527c2dadd44b8927ecf4437252adb507", }, "RestApiId": { "Ref": "RestApi0C43BF4B", @@ -3763,6 +3797,12 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "StatusCode": "200", }, ], + "RequestParameters": { + "method.request.header.X-GU-GeoIP-Country-Code": true, + }, + "RequestValidatorId": { + "Ref": "oneoffvalidator0C4177E4", + }, "ResourceId": { "Ref": "RestApicreateoneoff2D1FCD3C", }, @@ -3883,6 +3923,12 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "StatusCode": "200", }, ], + "RequestParameters": { + "method.request.header.X-GU-GeoIP-Country-Code": true, + }, + "RequestValidatorId": { + "Ref": "recurringvalidatorA3C040BF", + }, "ResourceId": { "Ref": "RestApicreaterecurringA327119C", }, @@ -5183,6 +5229,15 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` }, "Type": "AWS::Events::Rule", }, + "oneoffvalidator0C4177E4": { + "Properties": { + "RestApiId": { + "Ref": "RestApi0C43BF4B", + }, + "ValidateRequestParameters": true, + }, + "Type": "AWS::ApiGateway::RequestValidator", + }, "reactivaterecurringreminder0045F57B": { "DependsOn": [ "reactivaterecurringreminderServiceRoleDefaultPolicyA6827EC3", @@ -5416,6 +5471,15 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` }, "Type": "AWS::IAM::Policy", }, + "recurringvalidatorA3C040BF": { + "Properties": { + "RestApiId": { + "Ref": "RestApi0C43BF4B", + }, + "ValidateRequestParameters": true, + }, + "Type": "AWS::ApiGateway::RequestValidator", + }, "signupexportsDBFAB572": { "DependsOn": [ "signupexportsServiceRoleDefaultPolicy7B14F7DA", diff --git a/cdk/lib/support-reminders.ts b/cdk/lib/support-reminders.ts index 3f111c3..2e871d7 100644 --- a/cdk/lib/support-reminders.ts +++ b/cdk/lib/support-reminders.ts @@ -6,7 +6,7 @@ import {GuVpc} from "@guardian/cdk/lib/constructs/ec2"; import {GuLambdaFunction} from "@guardian/cdk/lib/constructs/lambda"; import type {App} from "aws-cdk-lib"; import {Duration} from "aws-cdk-lib"; -import { AwsIntegration, CfnBasePathMapping, CfnDomainName, Cors } from "aws-cdk-lib/aws-apigateway"; +import {AwsIntegration, CfnBasePathMapping, CfnDomainName, Cors, RequestValidator} from "aws-cdk-lib/aws-apigateway"; import {ComparisonOperator, Metric} from "aws-cdk-lib/aws-cloudwatch"; import {SecurityGroup} from "aws-cdk-lib/aws-ec2"; import {Schedule} from "aws-cdk-lib/aws-events"; @@ -174,14 +174,28 @@ export class SupportReminders extends GuStack { { statusCode: '200', }, - ] + ], + requestParameters: { + 'method.request.header.X-GU-GeoIP-Country-Code': true, + }, + requestValidator: new RequestValidator(this, 'one-off-validator', { + restApi: supportRemindersApi.api, + validateRequestParameters: true + }), }); supportRemindersApi.api.root.resourceForPath('/create/recurring').addMethod('POST', sendMessageIntegration, { methodResponses: [ { statusCode: '200', }, - ] + ], + requestParameters: { + 'method.request.header.X-GU-GeoIP-Country-Code': true, + }, + requestValidator: new RequestValidator(this, 'recurring-validator', { + restApi: supportRemindersApi.api, + validateRequestParameters: true + }), });