Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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 io.circe.Decoder

import java.time.Instant

// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/cloudwatch-logs.d.ts

sealed abstract class CloudWatchLogsEvent {
def awslogs: CloudWatchLogsEventData
}

object CloudWatchLogsEvent {
def apply(awslogs: CloudWatchLogsEventData): CloudWatchLogsEvent =
new Impl(awslogs)

implicit val decoder: Decoder[CloudWatchLogsEvent] =
Decoder.forProduct1("awslogs")(CloudWatchLogsEvent.apply)

private final case class Impl(
awslogs: CloudWatchLogsEventData
) extends CloudWatchLogsEvent {
override def productPrefix = "CloudWatchLogsEvent"
}
}

sealed abstract class CloudWatchLogsEventData {
def data: String
}

object CloudWatchLogsEventData {
def apply(data: String): CloudWatchLogsEventData =
new Impl(data)

private[events] implicit val decoder: Decoder[CloudWatchLogsEventData] =
Decoder.forProduct1("data")(CloudWatchLogsEventData.apply)

private final case class Impl(
data: String
) extends CloudWatchLogsEventData {
override def productPrefix = "CloudWatchLogsEventData"
}
}

sealed abstract class CloudWatchLogsDecodedData {
def owner: String
def logGroup: String
def logStream: String
def subscriptionFilters: List[String]
def messageType: String
def logEvents: List[CloudWatchLogsLogEvent]
}

object CloudWatchLogsDecodedData {
def apply(
owner: String,
logGroup: String,
logStream: String,
subscriptionFilters: List[String],
messageType: String,
logEvents: List[CloudWatchLogsLogEvent]
): CloudWatchLogsDecodedData =
new Impl(owner, logGroup, logStream, subscriptionFilters, messageType, logEvents)

implicit val decoder: Decoder[CloudWatchLogsDecodedData] =
Decoder.forProduct6(
"owner",
"logGroup",
"logStream",
"subscriptionFilters",
"messageType",
"logEvents"
)(CloudWatchLogsDecodedData.apply)

private final case class Impl(
owner: String,
logGroup: String,
logStream: String,
subscriptionFilters: List[String],
messageType: String,
logEvents: List[CloudWatchLogsLogEvent]
) extends CloudWatchLogsDecodedData {
override def productPrefix = "CloudWatchLogsDecodedData"
}
}

sealed abstract class CloudWatchLogsLogEvent {
def id: String
def timestamp: Instant
def message: String
def extractedFields: Option[Map[String, String]]
}

object CloudWatchLogsLogEvent {
import codecs.decodeInstant

def apply(
id: String,
timestamp: Instant,
message: String,
extractedFields: Option[Map[String, String]]
): CloudWatchLogsLogEvent =
new Impl(id, timestamp, message, extractedFields)

private[events] implicit val decoder: Decoder[CloudWatchLogsLogEvent] =
Decoder.forProduct4(
"id",
"timestamp",
"message",
"extractedFields"
)(CloudWatchLogsLogEvent.apply)

private final case class Impl(
id: String,
timestamp: Instant,
message: String,
extractedFields: Option[Map[String, String]]
) extends CloudWatchLogsLogEvent {
override def productPrefix = "CloudWatchLogsLogEvent"
}
}
180 changes: 180 additions & 0 deletions lambda/shared/src/main/scala/feral/lambda/events/CodeCommitEvent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* 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 io.circe.Decoder

// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/codecommit.d.ts

sealed abstract class CodeCommitEvent {
def records: List[CodeCommitRecord]
}

object CodeCommitEvent {
def apply(records: List[CodeCommitRecord]): CodeCommitEvent =
new Impl(records)

implicit val decoder: Decoder[CodeCommitEvent] =
Decoder.forProduct1("Records")(CodeCommitEvent.apply)

private final case class Impl(
records: List[CodeCommitRecord]
) extends CodeCommitEvent {
override def productPrefix = "CodeCommitEvent"
}
}

sealed abstract class CodeCommitRecord {
def awsRegion: String
def codecommit: CodeCommitData
def customData: Option[String]
def eventId: String
def eventName: String
def eventPartNumber: Int
def eventSource: String
def eventSourceArn: String
def eventTime: String
def eventTotalParts: Int
def eventTriggerConfigId: String
def eventTriggerName: String
def eventVersion: String
def userIdentityArn: String
}

object CodeCommitRecord {
def apply(
awsRegion: String,
codecommit: CodeCommitData,
customData: Option[String],
eventId: String,
eventName: String,
eventPartNumber: Int,
eventSource: String,
eventSourceArn: String,
eventTime: String,
eventTotalParts: Int,
eventTriggerConfigId: String,
eventTriggerName: String,
eventVersion: String,
userIdentityArn: String
): CodeCommitRecord =
new Impl(
awsRegion,
codecommit,
customData,
eventId,
eventName,
eventPartNumber,
eventSource,
eventSourceArn,
eventTime,
eventTotalParts,
eventTriggerConfigId,
eventTriggerName,
eventVersion,
userIdentityArn
)

private[events] implicit val decoder: Decoder[CodeCommitRecord] =
Decoder.forProduct14(
"awsRegion",
"codecommit",
"customData",
"eventId",
"eventName",
"eventPartNumber",
"eventSource",
"eventSourceARN",
"eventTime",
"eventTotalParts",
"eventTriggerConfigId",
"eventTriggerName",
"eventVersion",
"userIdentityARN"
)(CodeCommitRecord.apply)

private final case class Impl(
awsRegion: String,
codecommit: CodeCommitData,
customData: Option[String],
eventId: String,
eventName: String,
eventPartNumber: Int,
eventSource: String,
eventSourceArn: String,
eventTime: String,
eventTotalParts: Int,
eventTriggerConfigId: String,
eventTriggerName: String,
eventVersion: String,
userIdentityArn: String
) extends CodeCommitRecord {
override def productPrefix = "CodeCommitRecord"
}
}

sealed abstract class CodeCommitData {
def references: List[CodeCommitReference]
}

object CodeCommitData {
def apply(references: List[CodeCommitReference]): CodeCommitData =
new Impl(references)

private[events] implicit val decoder: Decoder[CodeCommitData] =
Decoder.forProduct1("references")(CodeCommitData.apply)

private final case class Impl(
references: List[CodeCommitReference]
) extends CodeCommitData {
override def productPrefix = "CodeCommitData"
}
}

sealed abstract class CodeCommitReference {
def commit: String
def ref: String
def created: Option[Boolean]
def deleted: Option[Boolean]
}

object CodeCommitReference {
def apply(
commit: String,
ref: String,
created: Option[Boolean],
deleted: Option[Boolean]
): CodeCommitReference =
new Impl(commit, ref, created, deleted)

private[events] implicit val decoder: Decoder[CodeCommitReference] =
Decoder.forProduct4(
"commit",
"ref",
"created",
"deleted"
)(CodeCommitReference.apply)

private final case class Impl(
commit: String,
ref: String,
created: Option[Boolean],
deleted: Option[Boolean]
) extends CodeCommitReference {
override def productPrefix = "CodeCommitReference"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 io.circe.Decoder

// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/secretsmanager.d.ts

sealed abstract class SecretsManagerRotationEvent {
def step: SecretsManagerRotationEvent.Step
def secretId: String
def clientRequestToken: String
}

object SecretsManagerRotationEvent {

def apply(
step: Step,
secretId: String,
clientRequestToken: String
): SecretsManagerRotationEvent =
new Impl(step, secretId, clientRequestToken)

implicit val decoder: Decoder[SecretsManagerRotationEvent] =
Decoder.forProduct3(
"Step",
"SecretId",
"ClientRequestToken"
)(SecretsManagerRotationEvent.apply)

private final case class Impl(
step: Step,
secretId: String,
clientRequestToken: String
) extends SecretsManagerRotationEvent {
override def productPrefix = "SecretsManagerRotationEvent"
}

sealed abstract class Step
object Step {
case object CreateSecret extends Step
case object SetSecret extends Step
case object TestSecret extends Step
case object FinishSecret extends Step

implicit val decoder: Decoder[Step] = Decoder.decodeString.emap {
case "createSecret" => Right(CreateSecret)
case "setSecret" => Right(SetSecret)
case "testSecret" => Right(TestSecret)
case "finishSecret" => Right(FinishSecret)
case other => Left(s"Unknown rotation step: $other")
}
}
}
Loading