Package

net.cakesolutions

config

Permalink

package config

Using Typesafe config we read in and parse configuration files. Paths into these files are then retrieved and type checked using Ficus.

Using a lightweight DSL, we are able to then check and validate these type checked values. For example, given that the Typesafe configuration:

top-level-name = "test"
test {
  nestedVal = 50.68
  nestedDuration = 4 h
  nestedList = []
  context {
    valueInt = 30
    valueStr = "test string"
    valueDuration = 12 ms
    valueStrList = [ "addr1:10", "addr2:20", "addr3:30" ]
    valueDoubleList = [ 10.2, 20, 0.123 ]
  }
}

has been parsed and read into an implicit of type Config, then we are able to validate that the value at the path test.nestedVal has type Double and that it satisfies specified size bounds as follows:

case object ShouldBeAPercentageValue extends Exception

validate[Double]("test.nestedVal", ShouldBeAPercentageValue)(n => 0 <= n && n <= 100)

If the configuration value at path test.nestedVal fails to pass the percentage bounds check, then Left(ShouldBeAPercentageValue) is returned.

Likewise, we can enforce that all values in the array at the path test.context.valueStrList match the regular expression pattern [a-z0-9]+:[0-9]+ as follows:

case object ShouldBeASocketValue extends Exception

validate[List[String]]("test.context.valueStrList", ShouldBeASocketValue)(_.matches("[a-z0-9]+:[0-9]+"))

In some instances, we may not care about checking the value at a configuration path. In these cases we can use unchecked:

unchecked[FiniteDuration]("test.nestedDuration")
Linear Supertypes
FicusInstances, LocalDateReader, PeriodReader, ISOZonedDateTimeReader, BigNumberReaders, ConfigValueReader, TryReader, DurationReaders, ConfigReader, CollectionReaders, OptionReader, SymbolReader, StringReader, AnyValReaders, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. config
  2. FicusInstances
  3. LocalDateReader
  4. PeriodReader
  5. ISOZonedDateTimeReader
  6. BigNumberReaders
  7. ConfigValueReader
  8. TryReader
  9. DurationReaders
  10. ConfigReader
  11. CollectionReaders
  12. OptionReader
  13. SymbolReader
  14. StringReader
  15. AnyValReaders
  16. AnyRef
  17. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait ConfigError extends AnyRef

    Permalink

    General reasons for why a config value might fail to be validated by validate.

  2. final case class FileNotFound(file: String, reason: Throwable) extends ConfigError with Product with Serializable

    Permalink
  3. sealed trait PathSpec extends AnyRef

    Permalink

    Ensures that the specified path has a value defined for it.

    Ensures that the specified path has a value defined for it. This may be achieved:

    • at the Typesafe configuration file level: the path must exist and have a non-null value
    • using a sentinal value: the path has the sentinal value if and only if it has not been set or assigned to.
  4. type ValidationFailure[Value] = Validated[NonEmptyList[ValueFailure], Value]

    Permalink

    Applicative functor for value validation

  5. sealed trait ValueError extends AnyRef

    Permalink

    Reasons why we might fail to parse a value from the config file

  6. final case class ValueErrors(errors: ValueError*) extends ConfigError with Product with Serializable

    Permalink
  7. final case class ValueFailure(path: String, reason: Throwable) extends ValueError with Product with Serializable

    Permalink
  8. final case class optional(value: String) extends PathSpec with Product with Serializable

    Permalink
  9. final case class required extends PathSpec with Product with Serializable

    Permalink

Value Members

  1. object MissingValue extends Exception with Product with Serializable

    Permalink
  2. object NullValue extends Exception with Product with Serializable

    Permalink
  3. object RequiredValueNotSet extends Exception with Product with Serializable

    Permalink
  4. implicit val bigDecimalReader: ValueReader[BigDecimal]

    Permalink
    Definition Classes
    BigNumberReaders
  5. implicit val bigIntReader: ValueReader[BigInt]

    Permalink
    Definition Classes
    BigNumberReaders
  6. implicit val booleanValueReader: ValueReader[Boolean]

    Permalink
    Definition Classes
    AnyValReaders
  7. implicit val configValueReader: ValueReader[Config]

    Permalink
    Definition Classes
    ConfigReader
  8. implicit val configValueValueReader: ValueReader[ConfigValue]

    Permalink
    Definition Classes
    ConfigValueReader
  9. implicit val doubleValueReader: ValueReader[Double]

    Permalink
    Definition Classes
    AnyValReaders
  10. implicit def durationReader: ValueReader[Duration]

    Permalink
    Definition Classes
    DurationReaders
  11. implicit val ficusConfigValueReader: ValueReader[FicusConfig]

    Permalink
    Definition Classes
    ConfigReader
  12. implicit def finiteDurationReader: ValueReader[FiniteDuration]

    Permalink
    Definition Classes
    DurationReaders
  13. implicit val intValueReader: ValueReader[Int]

    Permalink
    Definition Classes
    AnyValReaders
  14. implicit val isoZonedDateTimeReader: ValueReader[ZonedDateTime]

    Permalink
    Definition Classes
    ISOZonedDateTimeReader
  15. implicit val localDateReader: ValueReader[LocalDate]

    Permalink
    Definition Classes
    LocalDateReader
  16. implicit val longValueReader: ValueReader[Long]

    Permalink
    Definition Classes
    AnyValReaders
  17. implicit def mapValueReader[A](implicit entryReader: ValueReader[A]): ValueReader[Map[String, A]]

    Permalink
    Definition Classes
    CollectionReaders
  18. implicit def optionValueReader[A](implicit valueReader: ValueReader[A]): ValueReader[Option[A]]

    Permalink
    Definition Classes
    OptionReader
  19. implicit val periodReader: ValueReader[Period]

    Permalink
    Definition Classes
    PeriodReader
  20. object required extends Serializable

    Permalink
  21. implicit val stringValueReader: ValueReader[String]

    Permalink
    Definition Classes
    StringReader
  22. implicit val symbolValueReader: ValueReader[Symbol]

    Permalink
    Definition Classes
    SymbolReader
  23. implicit def toFicusConfig(config: Config): FicusConfig

    Permalink
  24. implicit def toRefinementType[Base, Refinement](implicit reader: ValueReader[Base], witness: Validate[Base, Refinement]): ValueReader[Refined[Base, Refinement]]

    Permalink
  25. implicit def traversableReader[C[_], A](implicit entryReader: ValueReader[A], cbf: CanBuildFrom[Nothing, A, C[A]]): ValueReader[C[A]]

    Permalink
    Definition Classes
    CollectionReaders
  26. implicit def tryValueReader[A](implicit valueReader: ValueReader[A]): ValueReader[Try[A]]

    Permalink
    Definition Classes
    TryReader
  27. def unchecked[Value](path: String)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Permalink
  28. def unchecked[Value](pathSpec: PathSpec)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Permalink

    Used to read in a value of type Value.

    Used to read in a value of type Value. Other than checking the values type, no other validation is performed.

    Value

    type we expect the parsed and checked config value to have

    pathSpec

    Typesafe config path to the value we are validating

    config

    the currently in scope config object that we use

    reader

    Ficus ValueReader that we use for type checking the parsed config value

    returns

    either a ValueFailure or the parsed and *unchecked* Value instance

  29. def validate[Value](path: String, failureReason: Throwable)(check: (Value) ⇒ Boolean)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Permalink
  30. def validate[Value](pathSpec: PathSpec, failureReason: Throwable)(check: (Value) ⇒ Boolean)(implicit config: Config, reader: ValueReader[Value]): Validated[NonEmptyList[ValueFailure], Value]

    Permalink

    Used to read in a value of type Value and to then check that value using check.

    Used to read in a value of type Value and to then check that value using check. If check returns false, then we fail with failureReason.

    Value

    type we expect the parsed and checked config value to have

    pathSpec

    Typesafe config path to the value we are validating

    failureReason

    if check fails, the Throwable instance we return

    check

    predicate used to check the configuration value

    config

    the currently in scope config object that we use

    reader

    Ficus ValueReader that we use for type checking the parsed config value

    returns

    either a ValueFailure or the parsed and checked Value instance

  31. def validateConfig[ValidConfig](configFile: String)(check: (Config) ⇒ Validated[NonEmptyList[ValueError], ValidConfig]): Validated[ConfigError, ValidConfig]

    Permalink

    Loads Typesafe config file and then builds the validated case class ValidConfig

    Loads Typesafe config file and then builds the validated case class ValidConfig

    ValidConfig

    the case class type that we are to construct

    configFile

    the root Typesafe config file name

    check

    the builder and validator that we will use to construct the ValidConfig instance

    returns

    either a ConfigError throwable instance or the validated case class ValidConfig

  32. def via[ValidConfig](path: String)(inner: (Config) ⇒ Validated[NonEmptyList[ValueFailure], ValidConfig])(implicit config: Config): Validated[NonEmptyList[ValueFailure], ValidConfig]

    Permalink

    The currently in-scope implicit Config instance is restricted to a specified path

    The currently in-scope implicit Config instance is restricted to a specified path

    ValidConfig

    the case class type that we are to construct

    path

    we restrict our Typesafe config path to this path

    inner

    configuration builder that we will apply to the restricted Config object

    config

    the current in-scope Config object that we need to path restrict

    returns

    either a ValueError or the validated case class ValidConfig

Inherited from FicusInstances

Inherited from LocalDateReader

Inherited from PeriodReader

Inherited from ISOZonedDateTimeReader

Inherited from BigNumberReaders

Inherited from ConfigValueReader

Inherited from TryReader

Inherited from DurationReaders

Inherited from ConfigReader

Inherited from CollectionReaders

Inherited from OptionReader

Inherited from SymbolReader

Inherited from StringReader

Inherited from AnyValReaders

Inherited from AnyRef

Inherited from Any

Ungrouped