-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1188 from Mee-Tree/fix/masking
fix: Masking for contramapped loggables
- Loading branch information
Showing
5 changed files
with
120 additions
and
197 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
.../logging/derivation/src/test/scala-2/tofu/logging/derivation/DerivedLoggableSamples.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,55 @@ | ||
package tofu.logging.derivation | ||
|
||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
import derevo.derive | ||
import tofu.logging.derivation.MaskMode.Custom | ||
|
||
object DerivedLoggableSamples { | ||
@derive(loggable) | ||
final case class Foo(lol: String, kek: Option[Long]) | ||
|
||
@derive(loggable) | ||
final case class Bar( | ||
@hidden foo1: Option[Foo] = None, | ||
@unembed foo2: Option[Foo] = None, | ||
foo3: Option[Foo] = None | ||
) | ||
|
||
@derive(loggable) | ||
final case class Jak( | ||
@masked(MaskMode.Erase) one: String, | ||
@masked(MaskMode.ForLength(1)) two: Long, | ||
@masked(MaskMode.Regexp("\\d*\\.(\\d*)".r)) three: Double, | ||
@masked(MaskMode.Regexp("-?\\d*\\.(\\d*)".r)) four: List[Double], | ||
) | ||
|
||
@derive(loggable) | ||
final case class Baz(foos: List[Foo] = Nil, ys: Vector[Int] = Vector(), zs: Option[List[List[String]]] = None) | ||
|
||
@derive(loggable) | ||
final case class MaskedBaz(@masked kek: Option[String], @ignoreOpt a: Option[String] = None) | ||
|
||
@derive(loggable) | ||
final case class MaskedOptBaz( | ||
@masked maybeStr: Option[String], | ||
@masked maybeInt: Option[Int], | ||
@masked maybeBool: Option[Boolean], | ||
@masked maybeDouble: Option[Double], | ||
@masked maybeStr2: Option[String] | ||
) | ||
|
||
@derive(loggable) | ||
final case class MaskedCustom( | ||
@masked(Custom(_ => "*")) sensitiveField: String, | ||
@masked(Custom(name => name.take(1) + "***")) firstName: Option[String], | ||
@masked(Custom(i => "*" * i.length())) age: Int | ||
) | ||
|
||
@derive(loggable) | ||
final case class MaskedContra( | ||
@masked(MaskMode.Erase) id: UUID, | ||
@masked(MaskMode.ForLength(4)) date: LocalDate, | ||
) | ||
} |
149 changes: 0 additions & 149 deletions
149
...es/logging/derivation/src/test/scala-2/tofu/logging/derivation/DerivedLoggableSuite.scala
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
modules/logging/derivation/src/test/scala-3/DerivedLoggableSamples.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,47 @@ | ||
package tofu.logging | ||
package derivation | ||
|
||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
import tofu.logging.derivation.MaskMode.Custom | ||
|
||
object DerivedLoggableSamples: | ||
final case class Foo(lol: String, kek: Option[Long]) derives Loggable | ||
|
||
final case class Bar( | ||
@hidden foo1: Option[Foo] = None, | ||
@unembed foo2: Option[Foo] = None, | ||
foo3: Option[Foo] = None | ||
) derives Loggable | ||
|
||
final case class Jak( | ||
@masked(MaskMode.Erase) one: String, | ||
@masked(MaskMode.ForLength(1)) two: Long, | ||
@masked(MaskMode.Regexp("\\d*\\.(\\d*)".r)) three: Double, | ||
@masked(MaskMode.Regexp("-?\\d*\\.(\\d*)".r)) four: List[Double], | ||
) derives Loggable | ||
|
||
final case class Baz(foos: List[Foo] = Nil, ys: Vector[Int] = Vector(), zs: Option[List[List[String]]] = None) | ||
derives Loggable | ||
|
||
final case class MaskedBaz(@masked kek: Option[String], @ignoreOpt a: Option[String] = None) derives Loggable | ||
|
||
final case class MaskedOptBaz( | ||
@masked maybeStr: Option[String], | ||
@masked maybeInt: Option[Int], | ||
@masked maybeBool: Option[Boolean], | ||
@masked maybeDouble: Option[Double], | ||
@masked maybeStr2: Option[String] | ||
) derives Loggable | ||
|
||
final case class MaskedCustom( | ||
@masked(Custom(_ => "*")) sensitiveField: String, | ||
@masked(Custom(name => name.take(1) + "***")) firstName: Option[String], | ||
@masked(Custom(i => "*" * i.length())) age: Int | ||
) derives Loggable | ||
|
||
final case class MaskedContra( | ||
@masked(MaskMode.Erase) id: UUID, | ||
@masked(MaskMode.ForLength(4)) date: LocalDate, | ||
) derives Loggable |
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