Skip to content

Commit

Permalink
WIP: Switch from AWS SDK to Smithy4s
Browse files Browse the repository at this point in the history
  • Loading branch information
bpholt committed Dec 11, 2023
1 parent e66f972 commit 88d0340
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ lazy val `secure-config` = (project in file("."))
Seq(
"com.github.pureconfig" %% "pureconfig-cats-effect" % "0.17.4",
"io.monix" %% "newtypes-core" % "0.2.3",
"com.dwolla" %% "fs2-aws-java-sdk2" % "3.0.0-RC2",
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value,
"com.disneystreaming.smithy4s" %% "smithy4s-aws-http4s" % smithy4sVersion.value,
"org.typelevel" %% "mouse" % "1.2.1",
)
},
smithy4sAwsSpecs ++= Seq(AWS.kms),
scalacOptions += "-Wconf:src=src_managed/.*:s",
)
.enablePlugins(
Smithy4sCodegenPlugin,
)
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel-ci-release" % "0.5.3")
addSbtPlugin("org.typelevel" % "sbt-typelevel-settings" % "0.5.3")
addSbtPlugin("org.typelevel" % "sbt-typelevel-mergify" % "0.5.3")
addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.18.3")
16 changes: 11 additions & 5 deletions src/main/scala/com/dwolla/config/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ package com.dwolla

import cats.*
import cats.syntax.all.*
import com.dwolla.fs2aws.kms.*
import com.amazonaws.kms.{CiphertextType, KMS}
import monix.newtypes.NewtypeWrapped
import mouse.all.*
import pureconfig.ConfigReader
import smithy4s.Blob

package object config {
private[this] val secureStringRegex = "^SECURE: (.+)".r

def SecureReader[F[_] : Monad](decryptionClient: KmsAlg[F]): ConfigReader[F[SecurableString]] =
def SecureReader[F[_] : MonadThrow](kms: KMS[F]): ConfigReader[F[SecurableString]] =
ConfigReader[String].map {
case secureStringRegex(cryptotext) =>
for {
bytes <- decryptionClient.decrypt(cryptotext)
} yield SecurableString(bytes)
kms.decrypt(CiphertextType(Blob(cryptotext.getBytes())))
.map(_.plaintext) // TODO does this need to be base64-decoded?
.liftOptionT
.getOrRaise(new RuntimeException("boom")) // TODO convert to a better exception
.map(_.value.toUTF8String)
.map(SecurableString(_))

case s => SecurableString(s).pure[F]
}

Expand Down

0 comments on commit 88d0340

Please sign in to comment.