-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add circe and cats-xml support (#14)
- Loading branch information
Showing
9 changed files
with
168 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
integrations/cats-xml/src/main/scala/com/geirolz/secret/catsxml/implicits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.geirolz.secret.catsxml | ||
|
||
import cats.xml.codec.Decoder | ||
import com.geirolz.secret.{OneShotSecret, 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](_)) |
21 changes: 21 additions & 0 deletions
21
integrations/cats-xml/src/test/scala/com/geirolz/secret/catsxml/SecretCatsXmlSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.geirolz.secret.catsxml | ||
|
||
import cats.xml.codec.Decoder.Result | ||
import cats.xml.{Xml, XmlData} | ||
import com.geirolz.secret.{OneShotSecret, Secret} | ||
|
||
class SecretCatsXmlSuite extends munit.FunSuite: | ||
|
||
test("Secret should be decoded from xml") { | ||
val xml: XmlData.XmlString = Xml.string("secret_value") | ||
val result: Result[Secret[String]] = xml.as[Secret[String]] | ||
|
||
result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) | ||
} | ||
|
||
test("OneShotSecret should be decoded from xml") { | ||
val xml: XmlData.XmlString = Xml.string("secret_value") | ||
val result = xml.as[OneShotSecret[String]] | ||
|
||
result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) | ||
} |
11 changes: 11 additions & 0 deletions
11
integrations/circe/src/main/scala/com/geirolz/secret/circe/implicits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.geirolz.secret.circe | ||
|
||
import com.geirolz.secret.{OneShotSecret, Secret} | ||
import com.geirolz.secret.strategy.SecretStrategy | ||
import io.circe.Decoder | ||
|
||
given [T: Decoder: SecretStrategy]: Decoder[Secret[T]] = | ||
Decoder[T].map(Secret[T](_)) | ||
|
||
given [T: Decoder: SecretStrategy]: Decoder[OneShotSecret[T]] = | ||
Decoder[T].map(OneShotSecret[T](_)) |
20 changes: 20 additions & 0 deletions
20
integrations/circe/src/test/scala/com/geirolz/secret/circe/SecretCirceSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.geirolz.secret.circe | ||
|
||
import com.geirolz.secret.{OneShotSecret, Secret} | ||
import io.circe.Json | ||
|
||
class SecretCirceSuite extends munit.FunSuite: | ||
|
||
test("Secret should be decoded from json") { | ||
val json: Json = Json.fromString("secret_value") | ||
val result = json.as[Secret[String]] | ||
|
||
result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) | ||
} | ||
|
||
test("OneShotSecret should be decoded from json") { | ||
val json = Json.fromString("secret_value") | ||
val result = json.as[OneShotSecret[String]] | ||
|
||
result.toOption.get.euseAndDestroy(v => assert(v == "secret_value")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters