diff --git a/core/src/main/scala/com/geirolz/secret/DeferredSecret.scala b/core/src/main/scala/com/geirolz/secret/DeferredSecret.scala index dc84227..4044d1d 100644 --- a/core/src/main/scala/com/geirolz/secret/DeferredSecret.scala +++ b/core/src/main/scala/com/geirolz/secret/DeferredSecret.scala @@ -47,16 +47,16 @@ sealed trait DeferredSecret[F[_], T]: def evalUseRaw[U](f: Secret[T] => F[U]): F[U] /** Map the secret value to `U` */ - def map[U: SecretStrategy](f: T => U)(using Hasher): DeferredSecret[F, U] + def map[U: SecretStrategy](f: T => U)(using Hasher): Secret.Deferred[F, U] /** FlatMap the secret value to `U` */ - def flatMap[U: SecretStrategy](f: T => DeferredSecret[F, U])(using Hasher): DeferredSecret[F, U] + def flatMap[U: SecretStrategy](f: T => Secret.Deferred[F, U])(using Hasher): Secret.Deferred[F, U] /** Handle the error of the acquisition of the secret value */ - def handleError(f: Throwable => Secret[T]): DeferredSecret[F, T] + def handleError(f: Throwable => Secret[T]): Secret.Deferred[F, T] /** Handle the error of the acquisition of the secret value */ - def handleErrorWith(f: Throwable => F[Secret[T]]): DeferredSecret[F, T] + def handleErrorWith(f: Throwable => F[Secret[T]]): Secret.Deferred[F, T] object DeferredSecret: @@ -64,27 +64,27 @@ object DeferredSecret: * * The function is called every time the DeferredSecret is used. */ - def apply[F[_]: MonadThrow, T: SecretStrategy](acquire: => F[T])(using Hasher): DeferredSecret[F, T] = + def apply[F[_]: MonadThrow, T: SecretStrategy](acquire: => F[T])(using Hasher): Secret.Deferred[F, T] = DeferredSecret.fromSecret[F, T](acquire.map(Secret(_))) /** Create a pure and constant DeferredSecret */ - def pure[F[_]: MonadThrow, T: SecretStrategy](t: T)(using Hasher): DeferredSecret[F, T] = + def pure[F[_]: MonadThrow, T: SecretStrategy](t: T)(using Hasher): Secret.Deferred[F, T] = DeferredSecret(t.pure[F]) /** Create a failed DeferredSecret which always fails with the specified error */ - def failed[F[_]: MonadThrow, T](e: Throwable): DeferredSecret[F, T] = + def failed[F[_]: MonadThrow, T](e: Throwable): Secret.Deferred[F, T] = DeferredSecret.fromSecret(MonadThrow[F].raiseError(e)) /** Create a DeferredSecret that reads the specified environment variable every time it is used. */ - def fromEnv[F[_]: MonadThrow](name: String)(using SecretStrategy[String], Hasher): DeferredSecret[F, String] = + def fromEnv[F[_]: MonadThrow](name: String)(using SecretStrategy[String], Hasher): Secret.Deferred[F, String] = DeferredSecret.fromSecret(Secret.fromEnv[F](name)) /** Create a DeferredSecret from a Secret. * * The acquire function is called every time you use the DeferredSecret. */ - def fromSecret[F[_]: MonadThrow, T](_acquire: => F[Secret[T]]): DeferredSecret[F, T] = - new DeferredSecret[F, T]: + def fromSecret[F[_]: MonadThrow, T](_acquire: => F[Secret[T]]): Secret.Deferred[F, T] = + new Secret.Deferred[F, T]: private[secret] def acquire = _acquire @@ -100,14 +100,14 @@ object DeferredSecret: override def evalUseRaw[U](f: Secret[T] => F[U]): F[U] = acquire.flatMap(f) - override def map[U: SecretStrategy](f: T => U)(using Hasher): DeferredSecret[F, U] = + override def map[U: SecretStrategy](f: T => U)(using Hasher): Secret.Deferred[F, U] = DeferredSecret.fromSecret(acquire.map(_.map(f))) - override def flatMap[U: SecretStrategy](f: T => DeferredSecret[F, U])(using Hasher): DeferredSecret[F, U] = + override def flatMap[U: SecretStrategy](f: T => Secret.Deferred[F, U])(using Hasher): Secret.Deferred[F, U] = DeferredSecret.fromSecret(evalUse(f(_).acquire)) - override def handleError(f: Throwable => Secret[T]): DeferredSecret[F, T] = + override def handleError(f: Throwable => Secret[T]): Secret.Deferred[F, T] = handleErrorWith(f.andThen(_.pure[F])) - override def handleErrorWith(f: Throwable => F[Secret[T]]): DeferredSecret[F, T] = + override def handleErrorWith(f: Throwable => F[Secret[T]]): Secret.Deferred[F, T] = DeferredSecret.fromSecret(acquire.handleErrorWith(f)) diff --git a/core/src/main/scala/com/geirolz/secret/OneShotSecret.scala b/core/src/main/scala/com/geirolz/secret/OneShotSecret.scala index f4e6693..01b8e37 100644 --- a/core/src/main/scala/com/geirolz/secret/OneShotSecret.scala +++ b/core/src/main/scala/com/geirolz/secret/OneShotSecret.scala @@ -12,11 +12,14 @@ import com.geirolz.secret.util.{Hasher, Location} * type of the secret */ final class OneShotSecret[T] private[secret] (vault: Vault[T]) extends SecretApi[T](vault) -object OneShotSecret extends SecretCompanionApi[OneShotSecret]: +object OneShotSecret extends SecretCompanionApi[Secret.OneShot]: + + private[secret] def fromVault[T](vault: Vault[T]): Secret.OneShot[T] = + new OneShotSecret(vault) /** Create a destroyed secret */ - override def destroyed[T](location: Location = Location.unknown): OneShotSecret[T] = - new OneShotSecret[T](Vault.destroyed[T](location)) + override def destroyed[T](location: Location = Location.unknown): Secret.OneShot[T] = + fromVault[T](Vault.destroyed[T](location)) /** Create a new `OneShotSecret` with the specified value. * @@ -30,4 +33,4 @@ object OneShotSecret extends SecretCompanionApi[OneShotSecret]: override def apply[T](value: => T, collectDestructionLocation: Boolean = true)(using strategy: SecretStrategy[T], hasher: Hasher - ): OneShotSecret[T] = new OneShotSecret(Vault[T](value, collectDestructionLocation)) + ): Secret.OneShot[T] = fromVault(Vault[T](value, collectDestructionLocation)) diff --git a/core/src/main/scala/com/geirolz/secret/Secret.scala b/core/src/main/scala/com/geirolz/secret/Secret.scala index 8238641..a9836f3 100644 --- a/core/src/main/scala/com/geirolz/secret/Secret.scala +++ b/core/src/main/scala/com/geirolz/secret/Secret.scala @@ -91,9 +91,9 @@ abstract sealed class Secret[T] private (vault: Vault[T]) extends SecretApi[T](v final def flatMap[U: SecretStrategy](f: T => Secret[U])(using Hasher): Secret[U] = transform(_.euse(f)) - /** [[OneShotSecret]] version of this secret */ - final def asOneShot: OneShotSecret[T] = - new OneShotSecret(vault) + /** [[Secret.OneShot]] version of this secret */ + final def asOneShot: Secret.OneShot[T] = + Secret.oneShot.fromVault(vault) /** Apply `f` with the de-obfuscated value WITHOUT destroying it. * diff --git a/core/src/test/scala/com/geirolz/secret/DeferredSecretSuite.scala b/core/src/test/scala/com/geirolz/secret/DeferredSecretSuite.scala index 4a0e4fe..68646e9 100644 --- a/core/src/test/scala/com/geirolz/secret/DeferredSecretSuite.scala +++ b/core/src/test/scala/com/geirolz/secret/DeferredSecretSuite.scala @@ -6,14 +6,16 @@ import scala.util.Try class DeferredSecretSuite extends munit.CatsEffectSuite: - test("DeferredSecret should be evaluated every time use is called with IO") { + test("Secret.Deferred should be evaluated every time use is called with IO") { var counter = 0 - val secret: DeferredSecret[IO, Int] = - DeferredSecret(IO { - counter += 1 - 1 - }).map(_ + 1) - .flatMap(v => DeferredSecret.pure(v + 1)) + val secret: Secret.Deferred[IO, Int] = + Secret + .deferred(IO { + counter += 1 + 1 + }) + .map(_ + 1) + .flatMap(v => Secret.deferred.pure(v + 1)) .handleError(_ => Secret(0)) .handleErrorWith(_ => IO(Secret(0))) @@ -26,14 +28,16 @@ class DeferredSecretSuite extends munit.CatsEffectSuite: assert(counter == 3) } - test("DeferredSecret should be evaluated every time use is called with Try") { + test("Secret.Deferred should be evaluated every time use is called with Try") { var counter = 0 - val secret: DeferredSecret[Try, Int] = - DeferredSecret(Try { - counter += 1 - 1 - }).map(_ + 1) - .flatMap(v => DeferredSecret.pure(v + 1)) + val secret: Secret.Deferred[Try, Int] = + Secret + .deferred(Try { + counter += 1 + 1 + }) + .map(_ + 1) + .flatMap(v => Secret.deferred.pure(v + 1)) .handleError(_ => Secret(0)) .handleErrorWith(_ => Try(Secret(0))) @@ -46,32 +50,32 @@ class DeferredSecretSuite extends munit.CatsEffectSuite: assert(counter == 3) } - test("DeferredSecret.pure should always return the same value") { - val secret: DeferredSecret[Try, String] = DeferredSecret.pure("hello") + test("Secret.deferred.pure should always return the same value") { + val secret: Secret.Deferred[Try, String] = Secret.deferred.pure("hello") secret.use((v: String) => assertEquals(v, "hello")) } - test("DeferredSecret.failure should always return a failure") { - val ex = new Exception("error") - val secret: DeferredSecret[Try, Int] = DeferredSecret.failed[Try, Int](ex) + test("Secret.deferred.failure should always return a failure") { + val ex = new Exception("error") + val secret: Secret.Deferred[Try, Int] = Secret.deferred.failed[Try, Int](ex) assert(secret.use(_ => ()).isFailure) } - test("DeferredSecret.map should transform the value") { - val secret: DeferredSecret[Try, Int] = DeferredSecret.pure(1) - val result = secret.map(_ + 1) + test("Secret.deferred.map should transform the value") { + val secret: Secret.Deferred[Try, Int] = Secret.deferred.pure(1) + val result = secret.map(_ + 1) result.use((v: Int) => assertEquals(v, 2)) } - test("DeferredSecret.flatMap should transform the value") { - val secret: DeferredSecret[Try, Int] = DeferredSecret.pure(1) - val result = secret.flatMap(v => DeferredSecret.pure(v + 1)) + test("Secret.deferred.flatMap should transform the value") { + val secret: Secret.Deferred[Try, Int] = Secret.deferred.pure(1) + val result = secret.flatMap(v => Secret.deferred.pure(v + 1)) result.use((v: Int) => assertEquals(v, 2)) } - test("DeferredSecret.flatMap should propagate the failure") { - val ex = new Exception("error") - val secret: DeferredSecret[Try, Int] = DeferredSecret.failed[Try, Int](ex) - val result = secret.flatMap(v => DeferredSecret.pure(v + 1)) + test("Secret.deferred.flatMap should propagate the failure") { + val ex = new Exception("error") + val secret: Secret.Deferred[Try, Int] = Secret.deferred.failed[Try, Int](ex) + val result = secret.flatMap(v => Secret.deferred.pure(v + 1)) assert(result.use(_ => ()).isFailure) } diff --git a/core/src/test/scala/com/geirolz/secret/testing/SecretBuilder.scala b/core/src/test/scala/com/geirolz/secret/testing/SecretBuilder.scala index 36d8a04..d91e9e1 100644 --- a/core/src/test/scala/com/geirolz/secret/testing/SecretBuilder.scala +++ b/core/src/test/scala/com/geirolz/secret/testing/SecretBuilder.scala @@ -1,6 +1,6 @@ package com.geirolz.secret.testing -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.internal.SecretApi import com.geirolz.secret.strategy.SecretStrategy import com.geirolz.secret.util.Hasher @@ -21,10 +21,10 @@ object SecretBuilder: hasher: Hasher ): Secret[T] = Secret(value, collectDestructionLocation) - val oneShotSecret: SecretBuilder[OneShotSecret] = - new SecretBuilder[OneShotSecret]: + val oneShotSecret: SecretBuilder[Secret.OneShot] = + new SecretBuilder[Secret.OneShot]: override val name: String = "OneShotSecret" override def apply[T](value: => T, collectDestructionLocation: Boolean = true)(using strategy: SecretStrategy[T], hasher: Hasher - ): OneShotSecret[T] = OneShotSecret(value, collectDestructionLocation) + ): Secret.OneShot[T] = Secret.oneShot(value, collectDestructionLocation) diff --git a/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/hashed/implicits.scala b/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/hashed/implicits.scala index 7dfe5d8..abd8247 100644 --- a/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/hashed/implicits.scala +++ b/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/hashed/implicits.scala @@ -3,10 +3,10 @@ package com.geirolz.secret.catsxml.hashed import cats.xml.codec.Encoder import com.geirolz.secret.internal.SecretApi import com.geirolz.secret.strategy.SecretStrategy -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret export com.geirolz.secret.catsxml.given_Decoder_Secret -export com.geirolz.secret.catsxml.given_Decoder_OneShotSecret +export com.geirolz.secret.catsxml.given_Decoder_OneShot given [S[X] <: SecretApi[X], T]: Encoder[S[T]] = Encoder.encodeString.contramap(_.hashed) diff --git a/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/implicits.scala b/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/implicits.scala index 8e7fda9..6e5b876 100644 --- a/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/implicits.scala +++ b/integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/implicits.scala @@ -2,14 +2,14 @@ package com.geirolz.secret.catsxml import cats.xml.codec.{Decoder, Encoder} import com.geirolz.secret.internal.SecretApi -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.strategy.SecretStrategy given [T: Decoder: SecretStrategy]: Decoder[Secret[T]] = Decoder[T].map(Secret[T](_)) -given [T: Decoder: SecretStrategy]: Decoder[OneShotSecret[T]] = - Decoder[T].map(OneShotSecret[T](_)) +given [T: Decoder: SecretStrategy]: Decoder[Secret.OneShot[T]] = + Decoder[T].map(Secret.oneShot[T](_)) given [S[X] <: SecretApi[X], T]: Encoder[S[T]] = Encoder.encodeString.contramap(_.toString) diff --git a/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/SecretCatsXmlSuite.scala b/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/SecretCatsXmlSuite.scala index 3f6b4bd..110b60f 100644 --- a/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/SecretCatsXmlSuite.scala +++ b/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/SecretCatsXmlSuite.scala @@ -3,7 +3,7 @@ package com.geirolz.secret.catsxml import cats.xml.codec.Decoder.Result import cats.xml.{Xml, XmlData} import cats.xml.syntax.* -import com.geirolz.secret.{secretTag, OneShotSecret, Secret} +import com.geirolz.secret.{secretTag, Secret} class SecretCatsXmlSuite extends munit.FunSuite: @@ -14,9 +14,9 @@ class SecretCatsXmlSuite extends munit.FunSuite: result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } - test("OneShotSecret should be decoded from xml") { + test("Secret.OneShot should be decoded from xml") { val xml: XmlData.XmlString = Xml.string("secret_value") - val result = xml.as[OneShotSecret[String]] + val result = xml.as[Secret.OneShot[String]] result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } @@ -28,9 +28,9 @@ class SecretCatsXmlSuite extends munit.FunSuite: assert(result == Xml.string(secretTag)) } - test("OneShotSecret should be encoded to json") { - val secret: OneShotSecret[String] = OneShotSecret("secret_value") - val result: Xml = secret.toXml + test("Secret.OneShot should be encoded to json") { + val secret: Secret.OneShot[String] = Secret.oneShot("secret_value") + val result: Xml = secret.toXml assert(result == Xml.string(secretTag)) } diff --git a/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/hashed/SecretCatsXmlHashedSuite.scala b/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/hashed/SecretCatsXmlHashedSuite.scala index 2cd2cb4..3bddfc6 100644 --- a/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/hashed/SecretCatsXmlHashedSuite.scala +++ b/integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/hashed/SecretCatsXmlHashedSuite.scala @@ -3,7 +3,7 @@ package com.geirolz.secret.catsxml.hashed import cats.xml.codec.Decoder.Result import cats.xml.syntax.* import cats.xml.{Xml, XmlData} -import com.geirolz.secret.{secretTag, OneShotSecret, Secret} +import com.geirolz.secret.{secretTag, Secret} class SecretCatsXmlHashedSuite extends munit.FunSuite: @@ -14,9 +14,9 @@ class SecretCatsXmlHashedSuite extends munit.FunSuite: result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } - test("OneShotSecret should be decoded from xml") { + test("Secret.OneShot should be decoded from xml") { val xml: XmlData.XmlString = Xml.string("secret_value") - val result = xml.as[OneShotSecret[String]] + val result = xml.as[Secret.OneShot[String]] result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } @@ -28,9 +28,9 @@ class SecretCatsXmlHashedSuite extends munit.FunSuite: assert(result == Xml.string(secret.hashed)) } - test("OneShotSecret should be encoded to json") { - val secret: OneShotSecret[String] = OneShotSecret("secret_value") - val result: Xml = secret.toXml + test("Secret.OneShot should be encoded to json") { + val secret: Secret.OneShot[String] = Secret.oneShot("secret_value") + val result: Xml = secret.toXml assert(result == Xml.string(secret.hashed)) } diff --git a/integrations/circe/src/main/scala/com/geirolz/secret/circe/hashed/implicits.scala b/integrations/circe/src/main/scala/com/geirolz/secret/circe/hashed/implicits.scala index d2a4659..456e573 100644 --- a/integrations/circe/src/main/scala/com/geirolz/secret/circe/hashed/implicits.scala +++ b/integrations/circe/src/main/scala/com/geirolz/secret/circe/hashed/implicits.scala @@ -2,7 +2,7 @@ package com.geirolz.secret.circe.hashed import com.geirolz.secret.internal.SecretApi import com.geirolz.secret.strategy.SecretStrategy -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import io.circe.{Decoder, Encoder} export com.geirolz.secret.circe.given_Decoder_Secret diff --git a/integrations/circe/src/main/scala/com/geirolz/secret/circe/implicits.scala b/integrations/circe/src/main/scala/com/geirolz/secret/circe/implicits.scala index 93fdfe3..034b999 100644 --- a/integrations/circe/src/main/scala/com/geirolz/secret/circe/implicits.scala +++ b/integrations/circe/src/main/scala/com/geirolz/secret/circe/implicits.scala @@ -1,15 +1,15 @@ package com.geirolz.secret.circe import com.geirolz.secret.internal.SecretApi -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.strategy.SecretStrategy import io.circe.{Decoder, Encoder} given [T: Decoder: SecretStrategy]: Decoder[Secret[T]] = Decoder[T].map(Secret[T](_)) -given [T: Decoder: SecretStrategy]: Decoder[OneShotSecret[T]] = - Decoder[T].map(OneShotSecret[T](_)) +given [T: Decoder: SecretStrategy]: Decoder[Secret.OneShot[T]] = + Decoder[T].map(Secret.oneShot[T](_)) given [S[X] <: SecretApi[X], T]: Encoder[S[T]] = Encoder.encodeString.contramap(_.toString) diff --git a/integrations/circe/src/test/scala/com/geirolz/secret/circe/SecretCirceSuite.scala b/integrations/circe/src/test/scala/com/geirolz/secret/circe/SecretCirceSuite.scala index d603387..20d1ba9 100644 --- a/integrations/circe/src/test/scala/com/geirolz/secret/circe/SecretCirceSuite.scala +++ b/integrations/circe/src/test/scala/com/geirolz/secret/circe/SecretCirceSuite.scala @@ -1,6 +1,6 @@ package com.geirolz.secret.circe -import com.geirolz.secret.{OneShotSecret, Secret, secretTag} +import com.geirolz.secret.{secretTag, Secret} import io.circe.Json import io.circe.syntax.* @@ -13,9 +13,9 @@ class SecretCirceSuite extends munit.FunSuite: result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } - test("OneShotSecret should be decoded from json") { + test("Secret.OneShot should be decoded from json") { val json = Json.fromString("secret_value") - val result = json.as[OneShotSecret[String]] + val result = json.as[Secret.OneShot[String]] result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } @@ -27,9 +27,9 @@ class SecretCirceSuite extends munit.FunSuite: assert(result == Json.fromString(secretTag)) } - test("OneShotSecret should be encoded to json") { - val secret: OneShotSecret[String] = OneShotSecret("secret_value") - val result: Json = secret.asJson + test("Secret.OneShot should be encoded to json") { + val secret: Secret.OneShot[String] = Secret.oneShot("secret_value") + val result: Json = secret.asJson assert(result == Json.fromString(secretTag)) } diff --git a/integrations/circe/src/test/scala/com/geirolz/secret/circe/hashed/SecretCirceHashedSuite.scala b/integrations/circe/src/test/scala/com/geirolz/secret/circe/hashed/SecretCirceHashedSuite.scala index d4354a5..06288a4 100644 --- a/integrations/circe/src/test/scala/com/geirolz/secret/circe/hashed/SecretCirceHashedSuite.scala +++ b/integrations/circe/src/test/scala/com/geirolz/secret/circe/hashed/SecretCirceHashedSuite.scala @@ -1,6 +1,6 @@ package com.geirolz.secret.circe.hashed -import com.geirolz.secret.{secretTag, OneShotSecret, Secret} +import com.geirolz.secret.{secretTag, Secret} import io.circe.Json import io.circe.syntax.* @@ -13,9 +13,9 @@ class SecretCirceHashedSuite extends munit.FunSuite: result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } - test("OneShotSecret should be decoded from json") { + test("Secret.OneShot should be decoded from json") { val json = Json.fromString("secret_value") - val result = json.as[OneShotSecret[String]] + val result = json.as[Secret.OneShot[String]] result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) } @@ -27,9 +27,9 @@ class SecretCirceHashedSuite extends munit.FunSuite: assert(result == Json.fromString(secret.hashed)) } - test("OneShotSecret should be encoded to json") { - val secret: OneShotSecret[String] = OneShotSecret("secret_value") - val result: Json = secret.asJson + test("Secret.OneShot should be encoded to json") { + val secret: Secret.OneShot[String] = Secret.oneShot("secret_value") + val result: Json = secret.asJson assert(result == Json.fromString(secret.hashed)) } diff --git a/integrations/ciris/src/main/scala/com/geirolz/secret/ciris/implicits.scala b/integrations/ciris/src/main/scala/com/geirolz/secret/ciris/implicits.scala index c193890..e04e070 100644 --- a/integrations/ciris/src/main/scala/com/geirolz/secret/ciris/implicits.scala +++ b/integrations/ciris/src/main/scala/com/geirolz/secret/ciris/implicits.scala @@ -1,11 +1,11 @@ package com.geirolz.secret.ciris import ciris.ConfigDecoder -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.strategy.SecretStrategy given [A, T: ConfigDecoder[A, *]: SecretStrategy]: ConfigDecoder[A, Secret[T]] = summon[ConfigDecoder[A, T]].map(Secret(_)) -given [A, T: ConfigDecoder[A, *]: SecretStrategy]: ConfigDecoder[A, OneShotSecret[T]] = - summon[ConfigDecoder[A, T]].map(OneShotSecret(_)) +given [A, T: ConfigDecoder[A, *]: SecretStrategy]: ConfigDecoder[A, Secret.OneShot[T]] = + summon[ConfigDecoder[A, T]].map(Secret.oneShot(_)) diff --git a/integrations/ciris/src/test/scala/com/geirolz/secret/ciris/CirisSecretSupportSuite.scala b/integrations/ciris/src/test/scala/com/geirolz/secret/ciris/CirisSecretSupportSuite.scala index a60ffa5..cb85cd8 100644 --- a/integrations/ciris/src/test/scala/com/geirolz/secret/ciris/CirisSecretSupportSuite.scala +++ b/integrations/ciris/src/test/scala/com/geirolz/secret/ciris/CirisSecretSupportSuite.scala @@ -1,19 +1,17 @@ package com.geirolz.secret.ciris -import com.geirolz.secret.{OneShotSecret, Secret} - -import scala.util.Try import cats.effect.IO import ciris.ConfigValue +import com.geirolz.secret.Secret class CirisSecretSupportSuite extends munit.CatsEffectSuite: test("Read OneShotSecret string with ciris") { - val result: IO[OneShotSecret[String]] = + val result: IO[Secret.OneShot[String]] = ConfigValue .default("my-super-secret-password") - .as[OneShotSecret[String]] + .as[Secret.OneShot[String]] .load[IO] assertIO_( diff --git a/integrations/effect/src/main/scala/com/geirolz/secret/implicits.scala b/integrations/effect/src/main/scala/com/geirolz/secret/implicits.scala index 51552b2..95772d1 100644 --- a/integrations/effect/src/main/scala/com/geirolz/secret/implicits.scala +++ b/integrations/effect/src/main/scala/com/geirolz/secret/implicits.scala @@ -1,12 +1,11 @@ package com.geirolz.secret -import cats.MonadThrow import cats.effect.{Async, Resource} import com.geirolz.secret.strategy.SecretStrategy import com.geirolz.secret.util.Hasher // one shot secret -extension [T](secret: OneShotSecret[T]) +extension [T](secret: Secret.OneShot[T]) inline def resourceDestroy[F[_]](using F: Async[F]): Resource[F, T] = Resource .fromAutoCloseable(F.delay(secret)) @@ -33,7 +32,7 @@ extension (obj: Secret.type) Secret(secret).resourceDestroy[F] // deferred secret -extension [F[_], T](secret: DeferredSecret[F, T])(using F: Async[F]) +extension [F[_], T](secret: Secret.Deferred[F, T])(using F: Async[F]) inline def resource: Resource[F, T] = Resource .make(secret.acquire)(s => F.delay(s.destroy())) diff --git a/integrations/effect/src/test/scala/com/geirolz/secret/OneShotSecretCatsEffectSuite.scala b/integrations/effect/src/test/scala/com/geirolz/secret/OneShotSecretCatsEffectSuite.scala index 9af3c0f..388e8bd 100644 --- a/integrations/effect/src/test/scala/com/geirolz/secret/OneShotSecretCatsEffectSuite.scala +++ b/integrations/effect/src/test/scala/com/geirolz/secret/OneShotSecretCatsEffectSuite.scala @@ -6,7 +6,7 @@ class OneShotSecretCatsEffectSuite extends munit.CatsEffectSuite: test("OneShotSecret should be usable as a resourceDestroy") { - val secret1: OneShotSecret[String] = OneShotSecret("password") + val secret1: Secret.OneShot[String] = Secret.oneShot("password") val test1: IO[Unit] = secret1 diff --git a/integrations/pureconfig/src/main/scala/com/geirolz/secret/pureconfig/implicits.scala b/integrations/pureconfig/src/main/scala/com/geirolz/secret/pureconfig/implicits.scala index f0be18a..725c2cb 100644 --- a/integrations/pureconfig/src/main/scala/com/geirolz/secret/pureconfig/implicits.scala +++ b/integrations/pureconfig/src/main/scala/com/geirolz/secret/pureconfig/implicits.scala @@ -1,11 +1,11 @@ package com.geirolz.secret.pureconfig import _root_.pureconfig.ConfigReader -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.strategy.SecretStrategy given [T: ConfigReader: SecretStrategy]: ConfigReader[Secret[T]] = summon[ConfigReader[T]].map(t => Secret[T](t)) -given [T: ConfigReader: SecretStrategy]: ConfigReader[OneShotSecret[T]] = - summon[ConfigReader[T]].map(t => OneShotSecret[T](t)) +given [T: ConfigReader: SecretStrategy]: ConfigReader[Secret.OneShot[T]] = + summon[ConfigReader[T]].map(t => Secret.oneShot[T](t)) diff --git a/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/PureconfigSecretSupportSuite.scala b/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/PureconfigSecretSupportSuite.scala index dae7646..40aa112 100644 --- a/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/PureconfigSecretSupportSuite.scala +++ b/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/PureconfigSecretSupportSuite.scala @@ -4,7 +4,7 @@ import _root_.pureconfig.{ConfigReader, ConfigSource} import _root_.pureconfig.backend.ConfigFactoryWrapper import com.geirolz.secret.pureconfig.testing.FooWithSecret import com.geirolz.secret.pureconfig.given -import com.geirolz.secret.{OneShotSecret, SPassword, Secret} +import com.geirolz.secret.Secret import com.typesafe.config.Config class PureconfigSecretSupportSuite extends munit.FunSuite: @@ -52,8 +52,8 @@ class PureconfigSecretSupportSuite extends munit.FunSuite: .toOption .get - val result: ConfigReader.Result[OneShotSecret[String]] = - summon[ConfigReader[OneShotSecret[String]]] + val result: ConfigReader.Result[Secret.OneShot[String]] = + summon[ConfigReader[Secret.OneShot[String]]] .from(config.getValue("conf.secret-value")) assert( diff --git a/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/testing/FooWithSecret.scala b/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/testing/FooWithSecret.scala index 5e018a6..2e6eeab 100644 --- a/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/testing/FooWithSecret.scala +++ b/integrations/pureconfig/src/test/scala/com/geirolz/secret/pureconfig/testing/FooWithSecret.scala @@ -1,12 +1,12 @@ package com.geirolz.secret.pureconfig.testing -import com.geirolz.secret.{OneShotSecret, SPassword} import com.geirolz.secret.pureconfig.given +import com.geirolz.secret.Secret import pureconfig.ConfigReader import pureconfig.generic.derivation.default.* case class FooWithSecret( bar: String, - secret: SPassword, - oneShotSecret: SPassword.OneShot + secret: Secret[String], + oneShotSecret: Secret.OneShot[String] ) derives ConfigReader diff --git a/integrations/typesafe-config/src/main/scala/com/geirolz/secret/typesafe/config/implicits.scala b/integrations/typesafe-config/src/main/scala/com/geirolz/secret/typesafe/config/implicits.scala index 1728289..ffac830 100644 --- a/integrations/typesafe-config/src/main/scala/com/geirolz/secret/typesafe/config/implicits.scala +++ b/integrations/typesafe-config/src/main/scala/com/geirolz/secret/typesafe/config/implicits.scala @@ -1,6 +1,6 @@ package com.geirolz.secret.typesafe.config -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.geirolz.secret.strategy.SecretStrategy import com.typesafe.config.Config @@ -9,5 +9,5 @@ extension (config: Config) def getSecret[P: TypesafeConfigSecretAdapter: SecretStrategy](path: String): Secret[P] = Secret(TypesafeConfigSecretAdapter[P].get(config, path)) - def getOneShotSecret[P: TypesafeConfigSecretAdapter: SecretStrategy](path: String): OneShotSecret[P] = - OneShotSecret(TypesafeConfigSecretAdapter[P].get(config, path)) + def getOneShotSecret[P: TypesafeConfigSecretAdapter: SecretStrategy](path: String): Secret.OneShot[P] = + Secret.oneShot(TypesafeConfigSecretAdapter[P].get(config, path)) diff --git a/integrations/typesafe-config/src/test/scala/com/geirolz/secret/typesafe/config/TypesafeConfigSecretSupportSuite.scala b/integrations/typesafe-config/src/test/scala/com/geirolz/secret/typesafe/config/TypesafeConfigSecretSupportSuite.scala index 52fd319..4ab71da 100644 --- a/integrations/typesafe-config/src/test/scala/com/geirolz/secret/typesafe/config/TypesafeConfigSecretSupportSuite.scala +++ b/integrations/typesafe-config/src/test/scala/com/geirolz/secret/typesafe/config/TypesafeConfigSecretSupportSuite.scala @@ -1,6 +1,6 @@ package com.geirolz.secret.typesafe.config -import com.geirolz.secret.{OneShotSecret, Secret} +import com.geirolz.secret.Secret import com.typesafe.config.{Config, ConfigFactory} class TypesafeConfigSecretSupportSuite extends munit.FunSuite: @@ -14,7 +14,7 @@ class TypesafeConfigSecretSupportSuite extends munit.FunSuite: |}""".stripMargin ) - val result: OneShotSecret[String] = config.getOneShotSecret[String]("conf.secret-value") + val result: Secret.OneShot[String] = config.getOneShotSecret[String]("conf.secret-value") assert( result