-
Notifications
You must be signed in to change notification settings - Fork 30
/
apigateway_event.dart
304 lines (236 loc) · 7.42 KB
/
apigateway_event.dart
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import 'dart:io';
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
part 'apigateway_event.g.dart';
/// API Gateway Response contains the data for a response
/// to the API Gateway. It contains the [body] of the HTTP response.
/// It also contains a HTTP Status Code which by default is `200`.
/// Furthermore it indicates if the [body] is Base64 encoded or not.
class AwsApiGatewayResponse {
/// The body of the HTTP Response send from the API Gateway to the client.
String body;
/// Indicates if the [body] is Base64 encoded or not. By default is `false`.
bool isBase64Encoded;
// HTTP Status Code of the response of the API Gateway to the client.
int statusCode;
/// The HTTP headers that should be send with the response to the client.
Map<String, String> headers;
/// Returns the JSON representation of the response. This is called by
/// the JSON encoder to produce the response.
Map<String, dynamic> toJson() => {
'body': body,
'isBase64Encoded': isBase64Encoded,
'statusCode': statusCode,
'headers': headers
};
/// The factory creates a new [AwsApiGatewayResponse] from JSON.
/// It optionally accepts the Base64 encoded flag and a HTTP Status Code
/// for the response.
factory AwsApiGatewayResponse.fromJson(Map<String, dynamic> body,
{bool isBase64Encoded, int statusCode, Map<String, String> headers}) {
return AwsApiGatewayResponse(
body: json.encode(body),
isBase64Encoded: isBase64Encoded,
headers: headers,
statusCode: statusCode);
}
/// The Response that should be returned by the API Gateway for the
/// Lambda invocation. It has a [body] which reflects the body of the HTTP Response.
/// But also it signals if the [body] is Base64 encoded and what the HTTP Status Code
/// of the response is.
AwsApiGatewayResponse({
String body,
bool isBase64Encoded,
Map<String, String> headers,
int statusCode,
}) {
this.body = body ?? '';
this.isBase64Encoded = isBase64Encoded ?? false;
this.headers = headers ?? {"Content-Type": "application/json"};
this.statusCode = statusCode ?? HttpStatus.ok;
}
}
/// API Gateway Event ...
@JsonSerializable()
class AwsApiGatewayEvent {
/// URL Path ...
@JsonKey()
final String path;
/// Resource ...
@JsonKey()
final String resource;
/// HTTP Method ...
@JsonKey()
final String httpMethod;
/// Body ...
@JsonKey()
final String body;
/// Headers ...
@JsonKey()
final AwsApiGatewayEventHeaders headers;
/// Path Parameters ...
@JsonKey()
final Map<String, dynamic> pathParameters;
/// Query String Parameters ...
@JsonKey()
final Map<String, dynamic> queryStringParameters;
/// Stage Variables ...
@JsonKey()
final Map<String, dynamic> stageVariables;
/// Request Context ...
final AwsApiGatewayEventRequestContext requestContext;
factory AwsApiGatewayEvent.fromJson(Map<String, dynamic> json) =>
_$AwsApiGatewayEventFromJson(json);
Map<String, dynamic> toJson() => _$AwsApiGatewayEventToJson(this);
const AwsApiGatewayEvent(
{this.resource,
this.path,
this.httpMethod,
this.body,
this.headers,
this.queryStringParameters,
this.stageVariables,
this.requestContext,
this.pathParameters});
}
/// API Gateway Event Headers ...
@JsonSerializable()
class AwsApiGatewayEventHeaders {
@JsonKey(name: "Accept")
final String accept;
@JsonKey(name: "Accept-Encoding")
final String acceptEncoding;
@JsonKey(name: "CloudFront-Forwarded-Proto")
final String cloudfrontForwardProto;
@JsonKey(name: "CloudFront-Is-Desktop-Viewer")
final String cloudfrontIsDesktopViewer;
@JsonKey(name: "CloudFront-Is-Mobile-Viewer")
final String cloudfrontIsMobileViewer;
@JsonKey(name: "CloudFront-Is-SmartTV-Viewer")
final String cloudfrontIsSmartTvViewer;
@JsonKey(name: "CloudFront-Is-Tablet-Viewer")
final String cloudfrontIsTabletViewer;
@JsonKey(name: "CloudFront-Viewer-Country")
final String cloudfrontViewerCountry;
@JsonKey(name: "Host")
final String host;
@JsonKey(name: "Upgrade-Insecure-Requests")
final String upgradeInsecureRequests;
@JsonKey(name: "User-Agent")
final String userAgent;
@JsonKey(name: "Via")
final String via;
@JsonKey(name: "X-Amz-Cf-Id")
final String xAmzCfId;
@JsonKey(name: "X-Forwarded-For")
final String xForwardedFor;
@JsonKey(name: "X-Forwarded-Port")
final String xForwardedPort;
@JsonKey(name: "X-Forwarded-Proto")
final String xForwardedProto;
@JsonKey(name: "Cache-Control")
final String cacheControl;
@JsonKey(name: "X-Amzn-Trace-Id")
final String xAmznTraceId;
@JsonKey(ignore: true)
Map<String, dynamic> raw;
factory AwsApiGatewayEventHeaders.fromJson(Map<String, dynamic> json) {
final event = _$AwsApiGatewayEventHeadersFromJson(json);
event.raw = json;
return event;
}
Map<String, dynamic> toJson() => _$AwsApiGatewayEventHeadersToJson(this);
AwsApiGatewayEventHeaders(
{this.accept,
this.acceptEncoding,
this.cloudfrontIsDesktopViewer,
this.cloudfrontIsMobileViewer,
this.cloudfrontIsSmartTvViewer,
this.cloudfrontForwardProto,
this.cloudfrontIsTabletViewer,
this.cloudfrontViewerCountry,
this.upgradeInsecureRequests,
this.cacheControl,
this.host,
this.via,
this.userAgent,
this.xAmzCfId,
this.xAmznTraceId,
this.xForwardedFor,
this.xForwardedPort,
this.xForwardedProto});
}
/// API Gateway Event Request Context ...
@JsonSerializable()
class AwsApiGatewayEventRequestContext {
@JsonKey()
final String accountId;
@JsonKey()
final String resourceId;
@JsonKey()
final String stage;
@JsonKey()
final String requestId;
@JsonKey()
final String resourcePath;
@JsonKey()
final String httpMethod;
@JsonKey()
final String apiId;
factory AwsApiGatewayEventRequestContext.fromJson(
Map<String, dynamic> json) =>
_$AwsApiGatewayEventRequestContextFromJson(json);
Map<String, dynamic> toJson() =>
_$AwsApiGatewayEventRequestContextToJson(this);
const AwsApiGatewayEventRequestContext(
{this.accountId,
this.resourceId,
this.stage,
this.requestId,
this.resourcePath,
this.httpMethod,
this.apiId});
}
/// API Gateway Event Identity
@JsonSerializable()
class AwsApiGatewayEventRequestContextIdentity {
@JsonKey()
final String cognitoIdentityPoolId;
@JsonKey()
final String accountId;
@JsonKey()
final String cognitoIdentityId;
@JsonKey()
final String caller;
@JsonKey()
final String apiKey;
@JsonKey()
final String sourceIp;
@JsonKey()
final String cognitoAuthenticationType;
@JsonKey()
final String cognitoAuthenticationProvider;
@JsonKey()
final String userArn;
@JsonKey()
final String userAgent;
@JsonKey()
final String user;
factory AwsApiGatewayEventRequestContextIdentity.fromJson(
Map<String, dynamic> json) =>
_$AwsApiGatewayEventRequestContextIdentityFromJson(json);
Map<String, dynamic> toJson() =>
_$AwsApiGatewayEventRequestContextIdentityToJson(this);
const AwsApiGatewayEventRequestContextIdentity(
{this.cognitoIdentityPoolId,
this.cognitoAuthenticationProvider,
this.cognitoAuthenticationType,
this.caller,
this.accountId,
this.cognitoIdentityId,
this.apiKey,
this.sourceIp,
this.user,
this.userAgent,
this.userArn});
}