Package

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, ISOZonedDateTimeReader, BigNumberReaders, ConfigValueReader, TryReader, DurationReaders, ConfigReader, CollectionReaders, OptionReader, StringReader, AnyValReaders, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. config
  2. FicusInstances
  3. ISOZonedDateTimeReader
  4. BigNumberReaders
  5. ConfigValueReader
  6. TryReader
  7. DurationReaders
  8. ConfigReader
  9. CollectionReaders
  10. OptionReader
  11. StringReader
  12. AnyValReaders
  13. AnyRef
  14. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final case class ConfigError(errors: ValueError*) extends Exception with Product with Serializable

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

    Permalink
  3. final case class NestedConfigError(config: ConfigError) extends ValueError with Product with Serializable

    Permalink
  4. sealed trait ValueError extends AnyRef

    Permalink

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

  5. final case class ValueFailure[Value](path: String, reason: Throwable) extends ValueError with Product with Serializable

    Permalink

Value Members

  1. object MissingValue extends Exception with Product with Serializable

    Permalink

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

  2. object NullValue extends Exception with Product with Serializable

    Permalink
  3. implicit val bigDecimalReader: ValueReader[BigDecimal]

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

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

    Permalink
    Definition Classes
    AnyValReaders
  6. def build[ValidConfig](validatedParams: Either[ValueError, Any]*)(implicit gen: Generic[ValidConfig]): Either[ConfigError, ValidConfig]

    Permalink

    Constructs and instance of the case class ValidConfig from a list of validated parameter values.

    Constructs and instance of the case class ValidConfig from a list of validated parameter values.

    ValidConfig

    the case class type that we are to construct

    validatedParams

    list of validated case class parameters (listed in the order they are declared in the case class)

    returns

    either a list of ValueErrors (wrapped in a ConfigError) or the validated case class ValidConfig

  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 val ficusConfigValueReader: ValueReader[FicusConfig]

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

    Permalink
    Definition Classes
    DurationReaders
  12. implicit def innerConfigValue[ConfigValue](config: Either[ConfigError, ConfigValue]): Either[ValueError, ConfigValue]

    Permalink
  13. implicit val intValueReader: ValueReader[Int]

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

    Permalink
    Definition Classes
    ISOZonedDateTimeReader
  15. implicit val longValueReader: ValueReader[Long]

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

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

    Permalink
    Definition Classes
    OptionReader
  18. implicit val stringValueReader: ValueReader[String]

    Permalink
    Definition Classes
    StringReader
  19. implicit def toFicusConfig(config: Config): FicusConfig

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

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

    Permalink
    Definition Classes
    TryReader
  22. def unchecked[Value](path: String)(implicit config: Config, reader: ValueReader[Value]): Either[ValueFailure[Value], 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

    path

    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

  23. def validate[Value](path: String, failureReason: Throwable)(check: (Value) ⇒ Boolean)(implicit config: Config, reader: ValueReader[Value]): Either[ValueFailure[Value], 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

    path

    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

  24. def validateConfig[ValidConfig](configFile: String)(check: (Config) ⇒ Either[ConfigError, ValidConfig]): Try[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

  25. def via[ValidConfig](path: String)(inner: (Config) ⇒ Either[ConfigError, ValidConfig])(implicit config: Config): Either[ValueError, 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 ISOZonedDateTimeReader

Inherited from BigNumberReaders

Inherited from ConfigValueReader

Inherited from TryReader

Inherited from DurationReaders

Inherited from ConfigReader

Inherited from CollectionReaders

Inherited from OptionReader

Inherited from StringReader

Inherited from AnyValReaders

Inherited from AnyRef

Inherited from Any

Ungrouped