Skip to content

Commit 2f2db64

Browse files
committed
Refine APIGatewayProxy schema + test
1 parent edceba3 commit 2f2db64

File tree

3 files changed

+112
-8
lines changed

3 files changed

+112
-8
lines changed

lambda-events/src/commonMain/kotlin/io/github/trueangle/knative/lambda/runtime/events/apigateway/APIGatewayProxy.kt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import kotlinx.serialization.Serializable
55

66
@Serializable
77
data class APIGatewayProxy(
8-
@SerialName("version") val version: String?,
98
@SerialName("resource") val resource: String?,
109
@SerialName("path") val path: String?,
1110
@SerialName("httpMethod") val httpMethod: String,
@@ -25,14 +24,12 @@ data class APIGatewayProxy(
2524
@SerialName("stage") val stage: String?,
2625
@SerialName("resourceId") val resourceId: String?,
2726
@SerialName("requestId") val requestId: String?,
28-
@SerialName("operationName") val operationName: String?,
29-
@SerialName("identity") val identity: RequestIdentity?,
27+
@SerialName("identity") val identity: Identity?,
3028
@SerialName("resourcePath") val resourcePath: String?,
3129
@SerialName("httpMethod") val httpMethod: String,
3230
@SerialName("apiId") val apiId: String?,
33-
@SerialName("deploymentId") val deploymentId: String?,
3431
@SerialName("path") val path: String?,
35-
@SerialName("authorizer") val authorizer: Map<String, Map<String, String>>?,
32+
@SerialName("authorizer") val authorizer: Authorizer?,
3633
@SerialName("extendedRequestId") val extendedRequestId: String?,
3734
@SerialName("requestTime") val requestTime: String?,
3835
@SerialName("requestTimeEpoch") val requestTimeEpoch: Long,
@@ -42,19 +39,40 @@ data class APIGatewayProxy(
4239
)
4340

4441
@Serializable
45-
data class RequestIdentity(
42+
data class Authorizer(
43+
@SerialName("claims") val claims: Map<String, String?>?,
44+
@SerialName("scopes") val scopes: String?
45+
)
46+
47+
@Serializable
48+
data class Identity(
4649
@SerialName("cognitoIdentityPoolId") val cognitoIdentityPoolId: String?,
4750
@SerialName("accountId") val accountId: String?,
4851
@SerialName("cognitoIdentityId") val cognitoIdentityId: String?,
4952
@SerialName("caller") val caller: String?,
50-
@SerialName("apiKey") val apiKey: String?,
5153
@SerialName("principalOrgId") val principalOrgId: String?,
5254
@SerialName("sourceIp") val sourceIp: String?,
5355
@SerialName("cognitoAuthenticationType") val cognitoAuthenticationType: String?,
5456
@SerialName("cognitoAuthenticationProvider") val cognitoAuthenticationProvider: String?,
5557
@SerialName("userArn") val userArn: String?,
5658
@SerialName("userAgent") val userAgent: String?,
5759
@SerialName("user") val user: String?,
58-
@SerialName("accessKey") val accessKey: String?
60+
@SerialName("accessKey") val accessKey: String?,
61+
@SerialName("clientCert") val clientCert: ClientCert?
62+
)
63+
64+
@Serializable
65+
data class ClientCert(
66+
@SerialName("clientCertPem") val clientCertPem: String?,
67+
@SerialName("subjectDN") val subjectDN: String?,
68+
@SerialName("issuerDN") val issuerDN: String?,
69+
@SerialName("serialNumber") val serialNumber: String?,
70+
@SerialName("validity") val validity: Validity?
71+
)
72+
73+
@Serializable
74+
data class Validity(
75+
@SerialName("notBefore") val notBefore: String?,
76+
@SerialName("notAfter") val notAfter: String?
5977
)
6078
}

lambda-events/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/events/apigateway/APIGatewayTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ class APIGatewayTest {
1919
val jsonString = Resource("$RESOURCES_PATH/example-apigw-v2-custom-authorizer-v1-request.json").readText()
2020
Json.decodeFromString<APIGatewayCustomAuthorizer>(jsonString)
2121
}
22+
23+
@Test
24+
fun `WHEN APIGatewayProxy json THEN parse`() {
25+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
26+
val jsonString = Resource("$RESOURCES_PATH/example-apigw-proxy-request.json").readText()
27+
Json.decodeFromString<APIGatewayProxy>(jsonString)
28+
}
2229
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"resource": "/my/path",
3+
"path": "/my/path",
4+
"httpMethod": "GET",
5+
"headers": {
6+
"header1": "value1",
7+
"header2": "value1,value2"
8+
},
9+
"multiValueHeaders": {
10+
"header1": [
11+
"value1"
12+
],
13+
"header2": [
14+
"value1",
15+
"value2"
16+
]
17+
},
18+
"queryStringParameters": {
19+
"parameter1": "value1,value2",
20+
"parameter2": "value"
21+
},
22+
"multiValueQueryStringParameters": {
23+
"parameter1": [
24+
"value1",
25+
"value2"
26+
],
27+
"parameter2": [
28+
"value"
29+
]
30+
},
31+
"requestContext": {
32+
"accountId": "123456789012",
33+
"apiId": "id",
34+
"authorizer": {
35+
"claims": null,
36+
"scopes": null
37+
},
38+
"domainName": "id.execute-api.us-east-1.amazonaws.com",
39+
"domainPrefix": "id",
40+
"extendedRequestId": "request-id",
41+
"httpMethod": "GET",
42+
"identity": {
43+
"accessKey": null,
44+
"accountId": null,
45+
"caller": null,
46+
"cognitoAuthenticationProvider": null,
47+
"cognitoAuthenticationType": null,
48+
"cognitoIdentityId": null,
49+
"cognitoIdentityPoolId": null,
50+
"principalOrgId": null,
51+
"sourceIp": "IP",
52+
"user": null,
53+
"userAgent": "user-agent",
54+
"userArn": null,
55+
"clientCert": {
56+
"clientCertPem": "CERT_CONTENT",
57+
"subjectDN": "www.example.com",
58+
"issuerDN": "Example issuer",
59+
"serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
60+
"validity": {
61+
"notBefore": "May 28 12:30:02 2019 GMT",
62+
"notAfter": "Aug 5 09:36:04 2021 GMT"
63+
}
64+
}
65+
},
66+
"path": "/my/path",
67+
"protocol": "HTTP/1.1",
68+
"requestId": "id=",
69+
"requestTime": "04/Mar/2020:19:15:17 +0000",
70+
"requestTimeEpoch": 1583349317135,
71+
"resourceId": null,
72+
"resourcePath": "/my/path",
73+
"stage": "$default"
74+
},
75+
"pathParameters": null,
76+
"stageVariables": null,
77+
"body": "Hello from Lambda!",
78+
"isBase64Encoded": false
79+
}

0 commit comments

Comments
 (0)