Skip to content

Commit

Permalink
Merge pull request #239 from typelevel/merge/0.1-1.x
Browse files Browse the repository at this point in the history
0.1 -> 1.x
  • Loading branch information
armanbilge authored Jul 6, 2022
2 parents 1d87385 + ee426c1 commit 647cffe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ val Scala213 = "2.13.8"
val Scala3 = "3.1.3"
ThisBuild / crossScalaVersions := Seq(Scala212, Scala3, Scala213)

val catsEffectVersion = "3.3.12"
val catsEffectVersion = "3.3.13"
val circeVersion = "0.14.2"
val fs2Version = "3.2.8"
val http4sVersion = "1.0.0-M33"
val fs2Version = "3.2.9"
val http4sVersion = "1.0.0-M34"
val natchezVersion = "0.1.6"
val munitVersion = "0.7.29"
val munitCEVersion = "1.0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ import org.http4s.client.dsl.Http4sClientDsl

trait CloudFormationCustomResource[F[_], Input, Output] {
def createResource(input: Input): F[HandlerResponse[Output]]
def updateResource(input: Input): F[HandlerResponse[Output]]
def deleteResource(input: Input): F[HandlerResponse[Output]]
def updateResource(
input: Input,
physicalResourceId: PhysicalResourceId): F[HandlerResponse[Output]]
def deleteResource(
input: Input,
physicalResourceId: PhysicalResourceId): F[HandlerResponse[Output]]
}

object CloudFormationCustomResource {
Expand All @@ -47,11 +51,11 @@ object CloudFormationCustomResource {
import http4sClientDsl._

env.event.flatMap { event =>
(event.RequestType match {
case CreateRequest => handler.createResource(event.ResourceProperties)
case UpdateRequest => handler.updateResource(event.ResourceProperties)
case DeleteRequest => handler.deleteResource(event.ResourceProperties)
case OtherRequestType(other) => illegalRequestType(other)
((event.RequestType, event.PhysicalResourceId) match {
case (CreateRequest, None) => handler.createResource(event.ResourceProperties)
case (UpdateRequest, Some(id)) => handler.updateResource(event.ResourceProperties, id)
case (DeleteRequest, Some(id)) => handler.deleteResource(event.ResourceProperties, id)
case (other, _) => illegalRequestType(other.toString)
}).attempt
.map(_.fold(exceptionResponse(event)(_), successResponse(event)(_)))
.flatMap { resp => client.successful(PUT(resp.asJson, event.ResponseURL)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ package cloudformation {
case object CreateRequest extends CloudFormationRequestType
case object UpdateRequest extends CloudFormationRequestType
case object DeleteRequest extends CloudFormationRequestType
final case class OtherRequestType(requestType: String) extends CloudFormationRequestType
final case class OtherRequestType(requestType: String) extends CloudFormationRequestType {
override def toString: String = requestType
}

implicit val encoder: Encoder[CloudFormationRequestType] = {
case CreateRequest => "Create".asJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ trait CloudFormationCustomResourceArbitraries {
requestId <- arbitrary[RequestId]
resourceType <- arbitrary[ResourceType]
logicalResourceId <- arbitrary[LogicalResourceId]
physicalResourceId <- arbitrary[Option[PhysicalResourceId]]
physicalResourceId <- arbitrary[PhysicalResourceId]
resourceProperties <- arbitrary[A]
oldResourceProperties <- arbitrary[Option[JsonObject]]
} yield CloudFormationCustomResourceRequest(
Expand All @@ -175,7 +175,7 @@ trait CloudFormationCustomResourceArbitraries {
requestId,
resourceType,
logicalResourceId,
physicalResourceId,
if (requestType == CreateRequest) None else physicalResourceId.some,
resourceProperties,
oldResourceProperties
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ResponseSerializationSuite
}
)
.deepDropNullValues
case _ =>
case CreateRequest =>
Json.obj(
"Status" -> "SUCCESS".asJson,
"PhysicalResourceId" -> convertInputToFakePhysicalResourceId(
Expand All @@ -93,6 +93,15 @@ class ResponseSerializationSuite
"LogicalResourceId" -> event.LogicalResourceId.asJson,
"Data" -> event.RequestType.asJson
)
case UpdateRequest | DeleteRequest =>
Json.obj(
"Status" -> "SUCCESS".asJson,
"PhysicalResourceId" -> event.PhysicalResourceId.get.asJson,
"StackId" -> event.StackId.asJson,
"RequestId" -> event.RequestId.asJson,
"LogicalResourceId" -> event.LogicalResourceId.asJson,
"Data" -> event.RequestType.asJson
)
}

expect(body eqv expectedJson)
Expand Down Expand Up @@ -142,14 +151,16 @@ object ResponseSerializationSuite {
convertInputToFakePhysicalResourceId(input),
CreateRequest.some.widen[CloudFormationRequestType]).pure[F]

override def updateResource(input: String): F[HandlerResponse[CloudFormationRequestType]] =
HandlerResponse(
convertInputToFakePhysicalResourceId(input),
UpdateRequest.some.widen[CloudFormationRequestType]).pure[F]
override def updateResource(
input: String,
physicalResourceId: PhysicalResourceId): F[HandlerResponse[CloudFormationRequestType]] =
HandlerResponse(physicalResourceId, UpdateRequest.some.widen[CloudFormationRequestType])
.pure[F]

override def deleteResource(input: String): F[HandlerResponse[CloudFormationRequestType]] =
HandlerResponse(
convertInputToFakePhysicalResourceId(input),
DeleteRequest.some.widen[CloudFormationRequestType]).pure[F]
override def deleteResource(
input: String,
physicalResourceId: PhysicalResourceId): F[HandlerResponse[CloudFormationRequestType]] =
HandlerResponse(physicalResourceId, DeleteRequest.some.widen[CloudFormationRequestType])
.pure[F]
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.12")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

0 comments on commit 647cffe

Please sign in to comment.