Skip to content

Commit 29bc1ed

Browse files
committed
Add ApplicationLoadBalancer and CodeCommit Lambda event models (issue #48)
1 parent 017f4ae commit 29bc1ed

File tree

6 files changed

+649
-0
lines changed

6 files changed

+649
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright 2021 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package feral.lambda
18+
package events
19+
20+
import io.circe.Decoder
21+
import org.typelevel.ci.CIString
22+
23+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/alb.d.ts
24+
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
25+
26+
sealed abstract class ApplicationLoadBalancerRequestContext {
27+
def elb: ApplicationLoadBalancerTargetGroup
28+
}
29+
30+
object ApplicationLoadBalancerRequestContext {
31+
32+
def apply(elb: ApplicationLoadBalancerTargetGroup): ApplicationLoadBalancerRequestContext =
33+
new Impl(elb)
34+
35+
private[events] implicit val decoder: Decoder[ApplicationLoadBalancerRequestContext] =
36+
Decoder.forProduct1("elb")(ApplicationLoadBalancerRequestContext.apply)
37+
38+
private final case class Impl(elb: ApplicationLoadBalancerTargetGroup)
39+
extends ApplicationLoadBalancerRequestContext {
40+
override def productPrefix = "ApplicationLoadBalancerRequestContext"
41+
}
42+
}
43+
44+
sealed abstract class ApplicationLoadBalancerTargetGroup {
45+
def targetGroupArn: String
46+
}
47+
48+
object ApplicationLoadBalancerTargetGroup {
49+
50+
def apply(targetGroupArn: String): ApplicationLoadBalancerTargetGroup =
51+
new Impl(targetGroupArn)
52+
53+
private[events] implicit val decoder: Decoder[ApplicationLoadBalancerTargetGroup] =
54+
Decoder.forProduct1("targetGroupArn")(ApplicationLoadBalancerTargetGroup.apply)
55+
56+
private final case class Impl(targetGroupArn: String)
57+
extends ApplicationLoadBalancerTargetGroup {
58+
override def productPrefix = "ApplicationLoadBalancerTargetGroup"
59+
}
60+
}
61+
62+
sealed abstract class ApplicationLoadBalancerRequestEvent {
63+
def requestContext: ApplicationLoadBalancerRequestContext
64+
def httpMethod: String
65+
def path: String
66+
def queryStringParameters: Option[Map[String, String]]
67+
def headers: Option[Map[CIString, String]]
68+
def multiValueQueryStringParameters: Option[Map[String, List[String]]]
69+
def multiValueHeaders: Option[Map[CIString, List[String]]]
70+
def body: Option[String]
71+
def isBase64Encoded: Boolean
72+
}
73+
74+
object ApplicationLoadBalancerRequestEvent {
75+
76+
def apply(
77+
requestContext: ApplicationLoadBalancerRequestContext,
78+
httpMethod: String,
79+
path: String,
80+
queryStringParameters: Option[Map[String, String]],
81+
headers: Option[Map[CIString, String]],
82+
multiValueQueryStringParameters: Option[Map[String, List[String]]],
83+
multiValueHeaders: Option[Map[CIString, List[String]]],
84+
body: Option[String],
85+
isBase64Encoded: Boolean
86+
): ApplicationLoadBalancerRequestEvent =
87+
new Impl(
88+
requestContext,
89+
httpMethod,
90+
path,
91+
queryStringParameters,
92+
headers,
93+
multiValueQueryStringParameters,
94+
multiValueHeaders,
95+
body,
96+
isBase64Encoded
97+
)
98+
99+
import codecs.decodeKeyCIString
100+
implicit val decoder: Decoder[ApplicationLoadBalancerRequestEvent] =
101+
Decoder.forProduct9(
102+
"requestContext",
103+
"httpMethod",
104+
"path",
105+
"queryStringParameters",
106+
"headers",
107+
"multiValueQueryStringParameters",
108+
"multiValueHeaders",
109+
"body",
110+
"isBase64Encoded"
111+
)(ApplicationLoadBalancerRequestEvent.apply)
112+
113+
private final case class Impl(
114+
requestContext: ApplicationLoadBalancerRequestContext,
115+
httpMethod: String,
116+
path: String,
117+
queryStringParameters: Option[Map[String, String]],
118+
headers: Option[Map[CIString, String]],
119+
multiValueQueryStringParameters: Option[Map[String, List[String]]],
120+
multiValueHeaders: Option[Map[CIString, List[String]]],
121+
body: Option[String],
122+
isBase64Encoded: Boolean
123+
) extends ApplicationLoadBalancerRequestEvent {
124+
override def productPrefix = "ApplicationLoadBalancerRequestEvent"
125+
}
126+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2021 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package feral.lambda
18+
package events
19+
20+
import io.circe.Decoder
21+
import io.circe.Encoder
22+
import org.typelevel.ci.CIString
23+
24+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/alb.d.ts (ALBResult)
25+
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
26+
27+
sealed abstract class ApplicationLoadBalancerResponseEvent {
28+
def statusCode: Int
29+
def statusDescription: Option[String]
30+
def headers: Option[Map[CIString, String]]
31+
def multiValueHeaders: Option[Map[CIString, List[String]]]
32+
def body: Option[String]
33+
def isBase64Encoded: Option[Boolean]
34+
}
35+
36+
object ApplicationLoadBalancerResponseEvent {
37+
38+
def apply(
39+
statusCode: Int,
40+
statusDescription: Option[String],
41+
headers: Option[Map[CIString, String]],
42+
multiValueHeaders: Option[Map[CIString, List[String]]],
43+
body: Option[String],
44+
isBase64Encoded: Option[Boolean]
45+
): ApplicationLoadBalancerResponseEvent =
46+
new Impl(
47+
statusCode,
48+
statusDescription,
49+
headers,
50+
multiValueHeaders,
51+
body,
52+
isBase64Encoded
53+
)
54+
55+
import codecs.decodeKeyCIString
56+
import codecs.encodeKeyCIString
57+
implicit val decoder: Decoder[ApplicationLoadBalancerResponseEvent] =
58+
Decoder.forProduct6(
59+
"statusCode",
60+
"statusDescription",
61+
"headers",
62+
"multiValueHeaders",
63+
"body",
64+
"isBase64Encoded"
65+
)(ApplicationLoadBalancerResponseEvent.apply)
66+
67+
implicit val encoder: Encoder[ApplicationLoadBalancerResponseEvent] =
68+
Encoder.forProduct6(
69+
"statusCode",
70+
"statusDescription",
71+
"headers",
72+
"multiValueHeaders",
73+
"body",
74+
"isBase64Encoded"
75+
)(r =>
76+
(
77+
r.statusCode,
78+
r.statusDescription,
79+
r.headers,
80+
r.multiValueHeaders,
81+
r.body,
82+
r.isBase64Encoded
83+
))
84+
85+
private final case class Impl(
86+
statusCode: Int,
87+
statusDescription: Option[String],
88+
headers: Option[Map[CIString, String]],
89+
multiValueHeaders: Option[Map[CIString, List[String]]],
90+
body: Option[String],
91+
isBase64Encoded: Option[Boolean]
92+
) extends ApplicationLoadBalancerResponseEvent {
93+
override def productPrefix = "ApplicationLoadBalancerResponseEvent"
94+
}
95+
}

0 commit comments

Comments
 (0)