-
Notifications
You must be signed in to change notification settings - Fork 40
/
S3Event.scala
291 lines (236 loc) · 7.89 KB
/
S3Event.scala
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
/*
* Copyright 2021 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feral.lambda.events
import com.comcast.ip4s.IpAddress
import io.circe.Decoder
import java.time.Instant
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/s3.d.ts
sealed abstract class S3Event {
def records: List[S3EventRecord]
}
object S3Event {
def apply(records: List[S3EventRecord]): S3Event =
new Impl(records)
implicit val decoder: Decoder[S3Event] = Decoder.forProduct1("Records")(S3Event.apply)
private final case class Impl(records: List[S3EventRecord]) extends S3Event {
override def productPrefix = "S3Event"
}
}
sealed abstract class S3EventRecord {
def eventVersion: String
def eventSource: String
def awsRegion: String
def eventTime: Instant
def eventName: String
def userIdentity: S3UserIdentity
def requestParameters: S3RequestParameters
def responseElements: S3ResponseElements
def s3: S3
def glacierEventData: Option[S3EventRecordGlacierEventData]
}
object S3EventRecord {
def apply(
eventVersion: String,
eventSource: String,
awsRegion: String,
eventTime: Instant,
eventName: String,
userIdentity: S3UserIdentity,
requestParameters: S3RequestParameters,
responseElements: S3ResponseElements,
s3: S3,
glacierEventData: Option[S3EventRecordGlacierEventData]
): S3EventRecord =
new Impl(
eventVersion,
eventSource,
awsRegion,
eventTime,
eventName,
userIdentity,
requestParameters,
responseElements,
s3,
glacierEventData
)
private[events] implicit val decoder: Decoder[S3EventRecord] =
Decoder.forProduct10(
"eventVersion",
"eventSource",
"awsRegion",
"eventTime",
"eventName",
"userIdentity",
"requestParameters",
"responseElements",
"s3",
"glacierEventData"
)(S3EventRecord.apply)
private final case class Impl(
eventVersion: String,
eventSource: String,
awsRegion: String,
eventTime: Instant,
eventName: String,
userIdentity: S3UserIdentity,
requestParameters: S3RequestParameters,
responseElements: S3ResponseElements,
s3: S3,
glacierEventData: Option[S3EventRecordGlacierEventData])
extends S3EventRecord {
override def productPrefix = "S3EventRecord"
}
}
sealed abstract class S3UserIdentity { def principalId: String }
object S3UserIdentity {
def apply(principalId: String): S3UserIdentity =
new Impl(principalId)
private[events] implicit val decoder: Decoder[S3UserIdentity] =
Decoder.forProduct1("principalId")(S3UserIdentity.apply)
private final case class Impl(principalId: String) extends S3UserIdentity {
override def productPrefix = "S3UserIdentity"
}
}
sealed abstract class S3RequestParameters {
def sourceIpAddress: IpAddress
}
object S3RequestParameters {
def apply(sourceIpAddress: IpAddress): S3RequestParameters =
new Impl(sourceIpAddress)
import codecs.decodeIpAddress
private[events] implicit val decoder: Decoder[S3RequestParameters] =
Decoder.forProduct1("sourceIPAddress")(S3RequestParameters.apply)
private final case class Impl(sourceIpAddress: IpAddress) extends S3RequestParameters {
override def productPrefix = "S3RequestParameters"
}
}
sealed abstract class S3ResponseElements {
def `x-amz-request-id`: String
def `x-amz-id-2`: String
}
object S3ResponseElements {
def apply(`x-amz-request-id`: String, `x-amz-id-2`: String): S3ResponseElements =
new Impl(`x-amz-request-id`, `x-amz-id-2`)
private[events] implicit val decoder: Decoder[S3ResponseElements] =
Decoder.forProduct2("x-amz-request-id", "x-amz-id-2")(S3ResponseElements.apply)
private final case class Impl(`x-amz-request-id`: String, `x-amz-id-2`: String)
extends S3ResponseElements {
override def productPrefix = "S3ResponseElements"
}
}
sealed abstract class S3 {
def s3SchemaVersion: String
def configurationId: String
def bucket: S3Bucket
def `object`: S3Object
}
object S3 {
def apply(
s3SchemaVersion: String,
configurationId: String,
bucket: S3Bucket,
`object`: S3Object
): S3 =
new Impl(s3SchemaVersion, configurationId, bucket, `object`)
private[events] implicit val decoder: Decoder[S3] =
Decoder.forProduct4("s3SchemaVersion", "configurationId", "bucket", "object")(S3.apply)
private final case class Impl(
s3SchemaVersion: String,
configurationId: String,
bucket: S3Bucket,
`object`: S3Object)
extends S3 {
override def productPrefix = "S3"
}
}
sealed abstract class S3Bucket {
def name: String
def ownerIdentity: S3UserIdentity
def arn: String
}
object S3Bucket {
def apply(name: String, ownerIdentity: S3UserIdentity, arn: String): S3Bucket =
new Impl(name, ownerIdentity, arn)
private[events] implicit val decoder: Decoder[S3Bucket] =
Decoder.forProduct3("name", "ownerIdentity", "arn")(S3Bucket.apply)
private final case class Impl(name: String, ownerIdentity: S3UserIdentity, arn: String)
extends S3Bucket {
override def productPrefix = "S3Bucket"
}
}
sealed abstract class S3Object {
def key: String
def size: Long
def eTag: String
def versionId: Option[String]
def sequencer: String
}
object S3Object {
def apply(
key: String,
size: Long,
eTag: String,
versionId: Option[String],
sequencer: String
): S3Object =
new Impl(key, size, eTag, versionId, sequencer)
private[events] implicit val decoder: Decoder[S3Object] =
Decoder.forProduct5("key", "size", "eTag", "versionId", "sequencer")(S3Object.apply)
private final case class Impl(
key: String,
size: Long,
eTag: String,
versionId: Option[String],
sequencer: String)
extends S3Object {
override def productPrefix = "S3Object"
}
}
sealed abstract class S3EventRecordGlacierEventData {
def restoreEventData: S3EventRecordGlacierRestoreEventData
}
object S3EventRecordGlacierEventData {
def apply(
restoreEventData: S3EventRecordGlacierRestoreEventData): S3EventRecordGlacierEventData =
new Impl(restoreEventData)
private[events] implicit val decoder: Decoder[S3EventRecordGlacierEventData] =
Decoder.forProduct1("restoreEventData")(S3EventRecordGlacierEventData.apply)
private final case class Impl(restoreEventData: S3EventRecordGlacierRestoreEventData)
extends S3EventRecordGlacierEventData {
override def productPrefix = "S3EventRecordGlacierEventData"
}
}
sealed abstract class S3EventRecordGlacierRestoreEventData {
def lifecycleRestorationExpiryTime: Instant
def lifecycleRestoreStorageClass: String
}
object S3EventRecordGlacierRestoreEventData {
def apply(
lifecycleRestorationExpiryTime: Instant,
lifecycleRestoreStorageClass: String
): S3EventRecordGlacierRestoreEventData =
new Impl(lifecycleRestorationExpiryTime, lifecycleRestoreStorageClass)
private[events] implicit val decoder: Decoder[S3EventRecordGlacierRestoreEventData] =
Decoder.forProduct2("lifecycleRestorationExpiryTime", "lifecycleRestoreStorageClass")(
S3EventRecordGlacierRestoreEventData.apply
)
private final case class Impl(
lifecycleRestorationExpiryTime: Instant,
lifecycleRestoreStorageClass: String
) extends S3EventRecordGlacierRestoreEventData {
override def productPrefix = "S3EventRecordGlacierRestoreEventData"
}
}