|
| 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.events |
| 18 | + |
| 19 | +import io.circe.Decoder |
| 20 | + |
| 21 | +import java.time.Instant |
| 22 | + |
| 23 | +// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/s3.d.ts |
| 24 | + |
| 25 | +final case class S3Event(records: List[S3EventRecord]) |
| 26 | + |
| 27 | +object S3Event { |
| 28 | + implicit val decoder: Decoder[S3Event] = Decoder.forProduct1("Records")(S3Event.apply) |
| 29 | +} |
| 30 | + |
| 31 | +final case class S3EventRecord( |
| 32 | + eventVersion: String, |
| 33 | + eventSource: String, |
| 34 | + awsRegion: String, |
| 35 | + eventTime: Instant, |
| 36 | + eventName: String, |
| 37 | + userIdentity: S3UserIdentity, |
| 38 | + requestParameters: S3RequestParameters, |
| 39 | + responseElements: S3ResponseElements, |
| 40 | + s3: S3, |
| 41 | + glacierEventData: Option[S3EventRecordGlacierEventData]) |
| 42 | + |
| 43 | +object S3EventRecord { |
| 44 | + |
| 45 | + implicit val decoder: Decoder[S3EventRecord] = |
| 46 | + Decoder.forProduct10( |
| 47 | + "eventVersion", |
| 48 | + "eventSource", |
| 49 | + "awsRegion", |
| 50 | + "eventTime", |
| 51 | + "eventName", |
| 52 | + "userIdentity", |
| 53 | + "requestParameters", |
| 54 | + "responseElements", |
| 55 | + "s3", |
| 56 | + "glacierEventData" |
| 57 | + )(S3EventRecord.apply) |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +final case class S3UserIdentity(principalId: String) |
| 62 | + |
| 63 | +object S3UserIdentity { |
| 64 | + |
| 65 | + implicit val decoder: Decoder[S3UserIdentity] = |
| 66 | + Decoder.forProduct1("principalId")(S3UserIdentity.apply) |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +final case class S3RequestParameters(sourceIPAddress: String) |
| 71 | + |
| 72 | +object S3RequestParameters { |
| 73 | + |
| 74 | + implicit val decoder: Decoder[S3RequestParameters] = |
| 75 | + Decoder.forProduct1("sourceIPAddress")(S3RequestParameters.apply) |
| 76 | + |
| 77 | +} |
| 78 | + |
| 79 | +final case class S3ResponseElements(`x-amz-request-id`: String, `x-amz-id-2`: String) |
| 80 | + |
| 81 | +object S3ResponseElements { |
| 82 | + |
| 83 | + implicit val decoder: Decoder[S3ResponseElements] = |
| 84 | + Decoder.forProduct2("x-amz-request-id", "x-amz-id-2")(S3ResponseElements.apply) |
| 85 | + |
| 86 | +} |
| 87 | + |
| 88 | +final case class S3( |
| 89 | + s3SchemaVersion: String, |
| 90 | + configurationId: String, |
| 91 | + bucket: S3Bucket, |
| 92 | + `object`: S3Object) |
| 93 | + |
| 94 | +object S3 { |
| 95 | + |
| 96 | + implicit val decoder: Decoder[S3] = |
| 97 | + Decoder.forProduct4("s3SchemaVersion", "configurationId", "bucket", "object")(S3.apply) |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +final case class S3Bucket(name: String, ownerIdentity: S3UserIdentity, arn: String) |
| 102 | + |
| 103 | +object S3Bucket { |
| 104 | + |
| 105 | + implicit val decoder: Decoder[S3Bucket] = |
| 106 | + Decoder.forProduct3("name", "ownerIdentity", "arn")(S3Bucket.apply) |
| 107 | + |
| 108 | +} |
| 109 | + |
| 110 | +final case class S3Object( |
| 111 | + key: String, |
| 112 | + size: Long, |
| 113 | + eTag: String, |
| 114 | + versionId: Option[String], |
| 115 | + sequencer: String) |
| 116 | + |
| 117 | +object S3Object { |
| 118 | + |
| 119 | + implicit val decoder: Decoder[S3Object] = |
| 120 | + Decoder.forProduct5("key", "size", "eTag", "versionId", "sequencer")(S3Object.apply) |
| 121 | + |
| 122 | +} |
| 123 | + |
| 124 | +final case class S3EventRecordGlacierEventData( |
| 125 | + restoreEventData: S3EventRecordGlacierRestoreEventData) |
| 126 | + |
| 127 | +object S3EventRecordGlacierEventData { |
| 128 | + |
| 129 | + implicit val decoder: Decoder[S3EventRecordGlacierEventData] = |
| 130 | + Decoder.forProduct1("restoreEventData")(S3EventRecordGlacierEventData.apply) |
| 131 | + |
| 132 | +} |
| 133 | + |
| 134 | +final case class S3EventRecordGlacierRestoreEventData( |
| 135 | + lifecycleRestorationExpiryTime: Instant, |
| 136 | + lifecycleRestoreStorageClass: String) |
| 137 | + |
| 138 | +object S3EventRecordGlacierRestoreEventData { |
| 139 | + |
| 140 | + implicit val decoder: Decoder[S3EventRecordGlacierRestoreEventData] = |
| 141 | + Decoder.forProduct2("lifecycleRestorationExpiryTime", "lifecycleRestoreStorageClass")( |
| 142 | + S3EventRecordGlacierRestoreEventData.apply |
| 143 | + ) |
| 144 | + |
| 145 | +} |
0 commit comments