Skip to content

Commit 0fb41de

Browse files
committed
update contexts
1 parent 01e00e3 commit 0fb41de

File tree

2 files changed

+98
-102
lines changed

2 files changed

+98
-102
lines changed

localstack-core/localstack/services/apigateway/next_gen/execute_api/context.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,52 +52,6 @@ class IntegrationRequest(TypedDict, total=False):
5252
"""Body content of the request"""
5353

5454

55-
class AuthorizerContext(TypedDict, total=False):
56-
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
57-
claims: Optional[dict[str, str]]
58-
"""Claims returned from the Amazon Cognito user pool after the method caller is successfully authenticated"""
59-
principal_id: Optional[str]
60-
"""The principal user identification associated with the token sent by the client and returned from an API Gateway Lambda authorizer"""
61-
context: Optional[dict[str, str]]
62-
"""The stringified value of the specified key-value pair of the context map returned from an API Gateway Lambda authorizer function"""
63-
64-
65-
class IdentityContext(TypedDict, total=False):
66-
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
67-
accountId: Optional[str]
68-
"""The AWS account ID associated with the request."""
69-
apiKey: Optional[str]
70-
"""For API methods that require an API key, this variable is the API key associated with the method request."""
71-
apiKeyId: Optional[str]
72-
"""The API key ID associated with an API request that requires an API key."""
73-
caller: Optional[str]
74-
"""The principal identifier of the caller that signed the request. Supported for resources that use IAM authorization."""
75-
cognitoAuthenticationProvider: Optional[str]
76-
"""A comma-separated list of the Amazon Cognito authentication providers used by the caller making the request"""
77-
cognitoAuthenticationType: Optional[str]
78-
"""The Amazon Cognito authentication type of the caller making the request"""
79-
cognitoIdentityId: Optional[str]
80-
"""The Amazon Cognito identity ID of the caller making the request"""
81-
cognitoIdentityPoolId: Optional[str]
82-
"""The Amazon Cognito identity pool ID of the caller making the request"""
83-
principalOrgId: Optional[str]
84-
"""The AWS organization ID."""
85-
sourceIp: Optional[str]
86-
"""The source IP address of the immediate TCP connection making the request to the API Gateway endpoint"""
87-
clientCert: Optional[dict[str, str]]
88-
"""Certificate that a client presents. Present only in access logs if mutual TLS authentication fails."""
89-
vpcId: Optional[str]
90-
"""The VPC ID of the VPC making the request to the API Gateway endpoint."""
91-
vpceId: Optional[str]
92-
"""The VPC endpoint ID of the VPC endpoint making the request to the API Gateway endpoint."""
93-
user: Optional[str]
94-
"""The principal identifier of the user that will be authorized against resource access for resources that use IAM authorization."""
95-
userAgent: Optional[str]
96-
"""The User-Agent header of the API caller."""
97-
userArn: Optional[str]
98-
"""The Amazon Resource Name (ARN) of the effective user identified after authentication."""
99-
100-
10155
class RestApiInvocationContext(RequestContext):
10256
"""
10357
This context is going to be used to pass relevant information across an API Gateway invocation.

localstack-core/localstack/services/apigateway/next_gen/execute_api/variables.py

Lines changed: 98 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
class ContextVarsAuthorizer(TypedDict, total=False):
55
# this is merged with the Context returned by the Authorizer, which can attach any property to this dict in string
66
# format
7+
8+
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
79
claims: Optional[dict[str, str]]
8-
principalId: Optional[str]
10+
"""Claims returned from the Amazon Cognito user pool after the method caller is successfully authenticated"""
11+
principal_id: Optional[str]
12+
"""The principal user identification associated with the token sent by the client and returned from an API Gateway Lambda authorizer"""
913

1014

1115
class ContextVarsIdentityClientCertValidity(TypedDict, total=False):
@@ -14,6 +18,8 @@ class ContextVarsIdentityClientCertValidity(TypedDict, total=False):
1418

1519

1620
class ContextVarsIdentityClientCert(TypedDict, total=False):
21+
"""Certificate that a client presents. Present only in access logs if mutual TLS authentication fails."""
22+
1723
clientCertPem: str
1824
subjectDN: str
1925
issuerDN: str
@@ -22,21 +28,38 @@ class ContextVarsIdentityClientCert(TypedDict, total=False):
2228

2329

2430
class ContextVarsIdentity(TypedDict, total=False):
25-
accountId: str
31+
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
32+
accountId: Optional[str]
33+
"""The AWS account ID associated with the request."""
2634
apiKey: Optional[str]
27-
apiKeyId: str
28-
cognitoAuthenticationProvider: str
29-
cognitoAuthenticationType: str
30-
cognitoIdentityId: str
31-
cognitoIdentityPoolId: str
32-
principalOrgId: str
33-
sourceIp: str
35+
"""For API methods that require an API key, this variable is the API key associated with the method request."""
36+
apiKeyId: Optional[str]
37+
"""The API key ID associated with an API request that requires an API key."""
38+
caller: Optional[str]
39+
"""The principal identifier of the caller that signed the request. Supported for resources that use IAM authorization."""
40+
cognitoAuthenticationProvider: Optional[str]
41+
"""A comma-separated list of the Amazon Cognito authentication providers used by the caller making the request"""
42+
cognitoAuthenticationType: Optional[str]
43+
"""The Amazon Cognito authentication type of the caller making the request"""
44+
cognitoIdentityId: Optional[str]
45+
"""The Amazon Cognito identity ID of the caller making the request"""
46+
cognitoIdentityPoolId: Optional[str]
47+
"""The Amazon Cognito identity pool ID of the caller making the request"""
48+
principalOrgId: Optional[str]
49+
"""The AWS organization ID."""
50+
sourceIp: Optional[str]
51+
"""The source IP address of the immediate TCP connection making the request to the API Gateway endpoint"""
3452
clientCert: ContextVarsIdentityClientCert
35-
vpcId: str
36-
vpceId: str
37-
user: str
38-
userAgent: str
39-
userArn: str
53+
vpcId: Optional[str]
54+
"""The VPC ID of the VPC making the request to the API Gateway endpoint."""
55+
vpceId: Optional[str]
56+
"""The VPC endpoint ID of the VPC endpoint making the request to the API Gateway endpoint."""
57+
user: Optional[str]
58+
"""The principal identifier of the user that will be authorized against resource access for resources that use IAM authorization."""
59+
userAgent: Optional[str]
60+
"""The User-Agent header of the API caller."""
61+
userArn: Optional[str]
62+
"""The Amazon Resource Name (ARN) of the effective user identified after authentication."""
4063

4164

4265
class ContextVarsRequestOverride(TypedDict, total=False):
@@ -54,25 +77,44 @@ class ContextVarsResponseOverride(TypedDict, total=False):
5477
class ContextVariables(TypedDict, total=False):
5578
# https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
5679
accountId: str
80+
"""The API owner's AWS account ID."""
5781
apiId: str
58-
awsEndpointRequestId: str
82+
"""The identifier API Gateway assigns to your API."""
83+
awsEndpointRequestId: Optional[str]
84+
"""The AWS endpoint's request ID."""
5985
deploymentId: str
60-
domainName: Optional[str]
86+
"""The ID of the API deployment."""
87+
domainName: str
88+
"""The full domain name used to invoke the API. This should be the same as the incoming Host header."""
6189
domainPrefix: str
90+
"""The first label of the $context.domainName."""
6291
extendedRequestId: str
63-
httpMethod: str # TODO: type?
64-
identity: ContextVarsIdentity
65-
isCanaryRequest: bool | str # TODO: verify type
92+
"""The extended ID that API Gateway generates and assigns to the API request. """
93+
httpMethod: str
94+
"""The HTTP method used"""
95+
identity: Optional[ContextVarsIdentity]
96+
isCanaryRequest: Optional[bool | str] # TODO: verify type
97+
"""Indicates if the request was directed to the canary"""
6698
path: str
99+
"""The request path."""
67100
protocol: str
101+
"""The request protocol"""
68102
requestId: str
103+
"""An ID for the request. Clients can override this request ID. """
69104
requestTime: str
70-
requestTimeEpoch: str # TODO: type?
71-
resourceId: str
72-
resourcePath: str
105+
"""The CLF-formatted request time (dd/MMM/yyyy:HH:mm:ss +-hhmm)."""
106+
requestTimeEpoch: int
107+
"""The Epoch-formatted request time, in milliseconds."""
108+
resourceId: Optional[str]
109+
"""The identifier that API Gateway assigns to your resource."""
110+
resourcePath: Optional[str]
111+
"""The path to your resource"""
73112
stage: str
113+
"""The deployment stage of the API request """
74114
wafResponseCode: Optional[str]
115+
"""The response received from AWS WAF: WAF_ALLOW or WAF_BLOCK. Will not be set if the stage is not associated with a web ACL"""
75116
webaclArn: Optional[str]
117+
"""The complete ARN of the web ACL that is used to decide whether to allow or block the request. Will not be set if the stage is not associated with a web ACL."""
76118

77119

78120
class GatewayResponseContextVarsError(TypedDict, total=False):
@@ -85,55 +127,55 @@ class GatewayResponseContextVarsError(TypedDict, total=False):
85127

86128

87129
class LoggingContextVarsAuthorize(TypedDict, total=False):
88-
error: str
89-
latency: str
90-
status: str
130+
error: Optional[str]
131+
latency: Optional[str]
132+
status: Optional[str]
91133

92134

93135
class LoggingContextVarsAuthorizer(TypedDict, total=False):
94-
error: str
95-
integrationLatency: str
96-
integrationStatus: str
97-
latency: str
98-
requestId: str
99-
status: str
136+
error: Optional[str]
137+
integrationLatency: Optional[str]
138+
integrationStatus: Optional[str]
139+
latency: Optional[str]
140+
requestId: Optional[str]
141+
status: Optional[str]
100142

101143

102144
class LoggingContextVarsAuthenticate(TypedDict, total=False):
103-
error: str
104-
latency: str
105-
status: str
145+
error: Optional[str]
146+
latency: Optional[str]
147+
status: Optional[str]
106148

107149

108150
class LoggingContextVarsCustomDomain(TypedDict, total=False):
109-
basePathMatched: str
151+
basePathMatched: Optional[str]
110152

111153

112154
class LoggingContextVarsIntegration(TypedDict, total=False):
113-
error: str
114-
integrationStatus: str
115-
latency: str
116-
requestId: str
117-
status: str
155+
error: Optional[str]
156+
integrationStatus: Optional[str]
157+
latency: Optional[str]
158+
requestId: Optional[str]
159+
status: Optional[str]
118160

119161

120162
class LoggingContextVarsWaf(TypedDict, total=False):
121-
error: str
122-
latency: str
123-
status: str
163+
error: Optional[str]
164+
latency: Optional[str]
165+
status: Optional[str]
124166

125167

126168
class LoggingContextVariables(TypedDict, total=False):
127-
authorize: LoggingContextVarsAuthorize
128-
authorizer: LoggingContextVarsAuthorizer
129-
authenticate: LoggingContextVarsAuthenticate
130-
customDomain: LoggingContextVarsCustomDomain
131-
endpointType: str
132-
integration: LoggingContextVarsIntegration
133-
integrationLatency: str
134-
integrationStatus: str
135-
responseLatency: str
136-
responseLength: str
137-
status: str
138-
waf: LoggingContextVarsWaf
139-
xrayTraceId: str
169+
authorize: Optional[LoggingContextVarsAuthorize]
170+
authorizer: Optional[LoggingContextVarsAuthorizer]
171+
authenticate: Optional[LoggingContextVarsAuthenticate]
172+
customDomain: Optional[LoggingContextVarsCustomDomain]
173+
endpointType: Optional[str]
174+
integration: Optional[LoggingContextVarsIntegration]
175+
integrationLatency: Optional[str]
176+
integrationStatus: Optional[str]
177+
responseLatency: Optional[str]
178+
responseLength: Optional[str]
179+
status: Optional[str]
180+
waf: Optional[LoggingContextVarsWaf]
181+
xrayTraceId: Optional[str]

0 commit comments

Comments
 (0)