From db38628a91d4e60c58b1f191b860484d3777b99c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 2 Apr 2020 08:30:49 -0400 Subject: [PATCH 1/3] Remove nested structure definitions for `APIGatewayV2HTTPRequestContext`. --- events/apigw.go | 53 ++++++++++++++++++++++++++------------------ events/apigw_test.go | 6 +++++ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/events/apigw.go b/events/apigw.go index 8a47d336..fe4e5254 100644 --- a/events/apigw.go +++ b/events/apigw.go @@ -60,28 +60,37 @@ type APIGatewayV2HTTPRequest struct { // APIGatewayV2HTTPRequestContext contains the information to identify the AWS account and resources invoking the Lambda function. type APIGatewayV2HTTPRequestContext struct { - RouteKey string `json:"routeKey"` - AccountID string `json:"accountId"` - Stage string `json:"stage"` - RequestID string `json:"requestId"` - Authorizer struct { - JWT struct { - Claims map[string]string `json:"claims"` - Scopes []string `json:"scopes"` - } `json:"jwt"` - } `json:"authorizer"` - APIID string `json:"apiId"` // The API Gateway HTTP API Id - DomainName string `json:"domainName"` - DomainPrefix string `json:"domainPrefix"` - Time string `json:"time"` - TimeEpoch int64 `json:"timeEpoch"` - HTTP struct { - Method string `json:"method"` - Path string `json:"path"` - Protocol string `json:"protocol"` - SourceIP string `json:"sourceIp"` - UserAgent string `json:"userAgent"` - } `json:"http"` + RouteKey string `json:"routeKey"` + AccountID string `json:"accountId"` + Stage string `json:"stage"` + RequestID string `json:"requestId"` + Authorizer APIGatewayV2HTTPRequestContextAuthorizerDescription `json:"authorizer"` + APIID string `json:"apiId"` // The API Gateway HTTP API Id + DomainName string `json:"domainName"` + DomainPrefix string `json:"domainPrefix"` + Time string `json:"time"` + TimeEpoch int64 `json:"timeEpoch"` + HTTP APIGatewayV2HTTPRequestContextHttpDescription `json:"http"` +} + +// APIGatewayV2HTTPRequestContextAuthorizerDescription contains authorizer information for the request context. +type APIGatewayV2HTTPRequestContextAuthorizerDescription struct { + JWT APIGatewayV2HTTPRequestContextAuthorizerJwtDescription `json:"jwt"` +} + +// APIGatewayV2HTTPRequestContextAuthorizerJwtDescription contains JWT authorizer information for the request context. +type APIGatewayV2HTTPRequestContextAuthorizerJwtDescription struct { + Claims map[string]string `json:"claims"` + Scopes []string `json:"scopes"` +} + +// APIGatewayV2HTTPRequestContextHttpDescription contains HTTP information for the request context. +type APIGatewayV2HTTPRequestContextHttpDescription struct { + Method string `json:"method"` + Path string `json:"path"` + Protocol string `json:"protocol"` + SourceIP string `json:"sourceIp"` + UserAgent string `json:"userAgent"` } // APIGatewayRequestIdentity contains identity information for the request caller. diff --git a/events/apigw_test.go b/events/apigw_test.go index 89eab6ff..0e2b0c0b 100644 --- a/events/apigw_test.go +++ b/events/apigw_test.go @@ -230,6 +230,12 @@ func TestApiGatewayV2HTTPRequestMarshaling(t *testing.T) { t.Errorf("could not extract authorizer claim from JWT: %v", authContext) } + // validate HTTP details + http := inputEvent.RequestContext.HTTP + if http.Path != "/my/path" { + t.Errorf("could not extract HTTP details: %v", http) + } + // serialize to json outputJSON, err := json.Marshal(inputEvent) if err != nil { From 63ae1b5bb11c81128d1f27b9dbe7cc3f1259b862 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Thu, 2 Apr 2020 14:39:56 +0100 Subject: [PATCH 2/3] Update apigw.go Jwt -> JWT Http -> HTTP --- events/apigw.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/events/apigw.go b/events/apigw.go index fe4e5254..7d2fbd92 100644 --- a/events/apigw.go +++ b/events/apigw.go @@ -70,22 +70,22 @@ type APIGatewayV2HTTPRequestContext struct { DomainPrefix string `json:"domainPrefix"` Time string `json:"time"` TimeEpoch int64 `json:"timeEpoch"` - HTTP APIGatewayV2HTTPRequestContextHttpDescription `json:"http"` + HTTP APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"` } // APIGatewayV2HTTPRequestContextAuthorizerDescription contains authorizer information for the request context. type APIGatewayV2HTTPRequestContextAuthorizerDescription struct { - JWT APIGatewayV2HTTPRequestContextAuthorizerJwtDescription `json:"jwt"` + JWT APIGatewayV2HTTPRequestContextAuthorizerJWTDescription `json:"jwt"` } // APIGatewayV2HTTPRequestContextAuthorizerJwtDescription contains JWT authorizer information for the request context. -type APIGatewayV2HTTPRequestContextAuthorizerJwtDescription struct { +type APIGatewayV2HTTPRequestContextAuthorizerJWTDescription struct { Claims map[string]string `json:"claims"` Scopes []string `json:"scopes"` } // APIGatewayV2HTTPRequestContextHttpDescription contains HTTP information for the request context. -type APIGatewayV2HTTPRequestContextHttpDescription struct { +type APIGatewayV2HTTPRequestContextHTTPDescription struct { Method string `json:"method"` Path string `json:"path"` Protocol string `json:"protocol"` From 0ea59d40fe49d1c0d0e5892012123877d4297bf2 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Thu, 2 Apr 2020 14:43:01 +0100 Subject: [PATCH 3/3] Update apigw.go updated the comments too --- events/apigw.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/events/apigw.go b/events/apigw.go index 7d2fbd92..8db0d2e5 100644 --- a/events/apigw.go +++ b/events/apigw.go @@ -78,13 +78,13 @@ type APIGatewayV2HTTPRequestContextAuthorizerDescription struct { JWT APIGatewayV2HTTPRequestContextAuthorizerJWTDescription `json:"jwt"` } -// APIGatewayV2HTTPRequestContextAuthorizerJwtDescription contains JWT authorizer information for the request context. +// APIGatewayV2HTTPRequestContextAuthorizerJWTDescription contains JWT authorizer information for the request context. type APIGatewayV2HTTPRequestContextAuthorizerJWTDescription struct { Claims map[string]string `json:"claims"` Scopes []string `json:"scopes"` } -// APIGatewayV2HTTPRequestContextHttpDescription contains HTTP information for the request context. +// APIGatewayV2HTTPRequestContextHTTPDescription contains HTTP information for the request context. type APIGatewayV2HTTPRequestContextHTTPDescription struct { Method string `json:"method"` Path string `json:"path"`