|
| 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 | +} |
0 commit comments