-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapigw.go
More file actions
109 lines (95 loc) · 5.36 KB
/
apigw.go
File metadata and controls
109 lines (95 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package lambada
import (
"github.com/aws/aws-lambda-go/events"
"github.com/morelj/lambada/jwtclaims"
)
// Request represents an API Gateway event.
// This struct is both compatible with V1 (Lambda Proxy Integration) and V2 (HTTP API) events and is basically a merge
// of the `APIGatewayProxyRequest` and `APIGatewayV2HTTPRequest` structs defined in the
// `github.com/aws/aws-lambda-go/events` package.
type Request struct {
// V1 only
Resource string `json:"resource"` // V1 - The resource path defined in API Gateway
Path string `json:"path"` // V1 - The url path for the caller
HTTPMethod string `json:"httpMethod"` // V1
MultiValueHeaders map[string][]string `json:"multiValueHeaders"` // V1
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"` // V1
// V2 only
Version string `json:"version"` // V2
RouteKey string `json:"routeKey"` // V2
RawPath string `json:"rawPath"` // V2
RawQueryString string `json:"rawQueryString"` // V2
Cookies []string `json:"cookies,omitempty"` // V2
// V1+V2
Headers map[string]string `json:"headers"` // V1+V2
QueryStringParameters map[string]string `json:"queryStringParameters,omitempty"` // V1+V2
PathParameters map[string]string `json:"pathParameters,omitempty"` // V1+V2
StageVariables map[string]string `json:"stageVariables,omitempty"` // V1+V2
Body string `json:"body,omitempty"` // V1+V2
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` // V1+V2
RequestContext RequestContext `json:"requestContext"` // V1+V2
version uint8 // Numeric version
}
// VersionNumber returns the version number of the request (1 or 2)
func (r *Request) VersionNumber() uint8 {
return r.version
}
// RequestContext contains the information to identify the AWS account and resources invoking the Lambda function.
// This struct is both compatible with V1 (Lambda Proxy Integration) and V2 (HTTP API) events and is basically a merge
// of the `APIGatewayProxyRequestContext` and `APIGatewayV2HTTPRequestContext` structs defined in the
// `github.com/aws/aws-lambda-go/events` package.
type RequestContext struct {
// V1 Only
ResourceID string `json:"resourceId"`
OperationName string `json:"operationName,omitempty"`
Protocol string `json:"protocol"`
Identity events.APIGatewayRequestIdentity `json:"identity"`
ResourcePath string `json:"resourcePath"`
HTTPMethod string `json:"httpMethod"`
RequestTime string `json:"requestTime"`
RequestTimeEpoch int64 `json:"requestTimeEpoch"`
// V2 Only
RouteKey string `json:"routeKey"`
Time string `json:"time"`
TimeEpoch int64 `json:"timeEpoch"`
HTTP events.APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"`
// V1 + V2
AccountID string `json:"accountId"`
Stage string `json:"stage"`
DomainName string `json:"domainName"`
DomainPrefix string `json:"domainPrefix"`
RequestID string `json:"requestId"`
APIID string `json:"apiId"` // The API Gateway rest API Id
Authorizer *Authorizer `json:"authorizer,omitempty"`
}
// Response contains the response to send back to API Gateway
// This struct is both compatible with V1 (Lambda Proxy Integration) and V2 (HTTP API) events and is basically a merge
// of the `APIGatewayProxyResponse` and `APIGatewayV2HTTPResponse` structs defined in the
// `github.com/aws/aws-lambda-go/events` package.
type Response struct {
Cookies []string `json:"cookies,omitempty"` // V2
StatusCode int `json:"statusCode"` // V1+V2
Headers map[string]string `json:"headers"` // V1+V2
MultiValueHeaders map[string][]string `json:"multiValueHeaders"` // V1+V2
Body string `json:"body"` // V1+V2
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` // V1+V2
}
// Authorizer contains authorizer details
type Authorizer struct {
IAM *IAMAuthorizer `json:"iam,omitempty"`
JWT *JWTAuthorizer `json:"jwt,omitempty"`
}
// IAMAuthorizer contains the details of a request authenticated using the AWS SignV4 authorizer.
type IAMAuthorizer struct {
AccessKey string `json:"accessKey,omitempty"`
AccountID string `json:"accountId,omitempty"`
CallerID string `json:"callerId,omitempty"`
PrincipalOrgID string `json:"principalOrgId,omitempty"`
UserARN string `json:"userArn,omitempty"`
UserID string `json:"userId,omitempty"`
}
// JWTAuthorizer contains the details of a request authenticated using the JWT authorizer.
type JWTAuthorizer struct {
Claims jwtclaims.Claims `json:"claims,omitempty"`
Scopes any `json:"scopes,omitempty"`
}