Packages

object ZConfig

Use functions in this Config object when you need to retrieve your instance of config in terms of zio.Layer.

For example:

final case class MyConfig(dburl: String, port: Int)

val myConfigDesc: ConfigDescriptor[MyConfig]             = (string("dburl") zip int("port")).to[MyConfig]
val myConfig: Layer[ReadError[String], Config[MyConfig]] = Config.fromSystemEnv(myConfigDesc)

By using Config.fromSystemEnv(myConfigDesc), it internally extends your description which is myConfigDesc to include the ConfigSource. In the above example, it is the ConfigSource corresponding to sys.env. It then calls zio.config.read with this new description that includes the source information.

Extending an existing config description to include a ConfigSource is as simple as

myConfigDesc from configSource

Also, note that Config[MyConfig] in the above example is a simple type alias to Has[MyConfig].

If you want to retrieve your config as scala.Either instead of zio.Layer, then you will have to extend your description to include the information on ConfigSource manually.

For example:

import zio.config._, ConfigDescriptor._
final case class MyConfig(dburl: String, port: Int)

val myConfig: ConfigDescriptor[MyConfig]         = (string("dburl") zip int("port")).to[MyConfig]
val constantSource: ConfigSource                 = ConfigSource.fromMap(Map("dburl" -> "xyz", "port" -> "8080"))
val result: Either[ReadError[String], MyConfig]  = read(myConfig from constantSource)

Note: With the above approach, we got a simple scala.Either instead of retrieving them in terms of ZIO. Instead of the above approach, if we use Config.fromMap(constantMap, myConfig), then we will get a Layer[ReadError[String], MyConfig]

The above approach is especially useful when we have a custom ConfigSource. For instance, we can form a custom ConfigSource by composing a few existing ConfigSources.

For example:

import zio.config._, ConfigDescriptor._

final case class MyConfig(dburl: String, port: Int)

val myConfig: ConfigDescriptor[MyConfig]     = (string("dburl") zip int("port")).to[MyConfig]
val sysEnvSource: UIO[MyConfig]              = ConfigSource.fromSystemEnv
val constantSource: ConfigSource             = ConfigSource.fromMap(Map("dburl" -> "xyz", "port" -> "8080"))
val result: IO[ReadError[String], MyConfig]  = configSource.flatMap(source => read(myConfig from sysEnvSource.orElse(constantSource))

In the above example, the results returned an UIO because of the existence of ConfigSource corresponding to sys.env.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ZConfig
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. def fromCommandLineArgs[A](args: List[String], configDescriptor: ConfigStringModule.ConfigDescriptor[A], keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None)(implicit tag: Tag[A]): Layer[ReadError[String], A]

    EXPERIMENTAL

    EXPERIMENTAL

    Forming configuration from command line arguments.

    Assumption. All keys should start with either -

    This source supports almost all standard command-line patterns including nesting/sub-config, repetition/list etc

    Example:

    Given:

    args = "-db.username=1 --db.password=hi --vault -username=3 --vault -password=10 --regions 111,122 --user k1 --user k2"
    keyDelimiter   = Some('.')
    valueDelimiter = Some(',')

    then, the following works:

    final case class Credentials(username: String, password: String)
    
    val credentials = (string("username") zip string("password")).to[Credentials]
    
    final case class Config(databaseCredentials: Credentials, vaultCredentials: Credentials, regions: List[String], users: List[String])
    
    (nested("db") { credentials } zip nested("vault") { credentials } zip list("regions")(string) zip list("user")(string)).to[Config]
    
    // res0 Config(Credentials(1, hi), Credentials(3, 10), List(111, 122), List(k1, k2))
    See also

    https://github.com/zio/zio-config/tree/master/examples/src/main/scala/zio/config/examples/commandline/CommandLineArgsExample.scala

  10. def fromMap[A](map: Map[String, String], configDescriptor: ConfigStringModule.ConfigDescriptor[A], source: String = "constant", keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): Layer[ReadError[String], A]

    Provide keyDelimiter if you need to consider flattened config as a nested config.

    Provide keyDelimiter if you need to consider flattened config as a nested config. Provide valueDelimiter if you need any value to be a list

    Example:

    Given:

    map            = Map("KAFKA_SERVERS" -> "server1, server2", "KAFKA_SERDE"  -> "confluent")
    keyDelimiter   = Some('_')
    valueDelimiter = Some(',')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]
  11. def fromMultiMap[A](map: Map[String, ::[String]], configDescriptor: ConfigStringModule.ConfigDescriptor[A], source: String, keyDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): Layer[ReadError[String], A]

    Provide keyDelimiter if you need to consider flattened config as a nested config.

    Provide keyDelimiter if you need to consider flattened config as a nested config.

    Example:

    Given:

    map = Map("KAFKA_SERVERS" -> singleton(server1), "KAFKA_SERDE"  -> singleton("confluent"))
    keyDelimiter = Some('_')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]
  12. def fromProperties[A](properties: Properties, configDescriptor: ConfigStringModule.ConfigDescriptor[A], source: String, keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): Layer[ReadError[String], A]

    Provide keyDelimiter if you need to consider flattened config as a nested config.

    Provide keyDelimiter if you need to consider flattened config as a nested config. Provide valueDelimiter if you need any value to be a list

    Example:

    Given:

    property      = "KAFKA.SERVERS" = "server1, server2" ; "KAFKA.SERDE" = "confluent"
    keyDelimiter   = Some('.')
    valueDelimiter = Some(',')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]
  13. def fromPropertiesFile[A](filePath: String, configDescriptor: ConfigStringModule.ConfigDescriptor[A], keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): Layer[ReadError[String], A]

    Provide keyDelimiter if you need to consider flattened config as a nested config.

    Provide keyDelimiter if you need to consider flattened config as a nested config. Provide valueDelimiter if you need any value to be a list

    Example:

    Given:

    properties (in file) = "KAFKA.SERVERS" = "server1, server2" ; "KAFKA.SERDE" = "confluent"
    keyDelimiter         = Some('.')
    valueDelimiter       = Some(',')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]
  14. def fromSystemEnv[K, V, A](configDescriptor: ConfigStringModule.ConfigDescriptor[A], keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): ZLayer[Any, ReadError[String], A]

    Consider providing keyDelimiter if you need to consider flattened config as a nested config.

    Consider providing keyDelimiter if you need to consider flattened config as a nested config. Consider providing valueDelimiter if you need any value to be a list

    Example:

    Given:

    vars in sys.env  = "KAFKA_SERVERS" = "server1, server2" ; "KAFKA_SERDE" = "confluent"
    keyDelimiter     = Some('_')
    valueDelimiter   = Some(',')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]

    Note: The delimiter '.' for keys doesn't work in system environment.

    Annotations
    @silent( "a type was inferred to be `Any`" )
  15. def fromSystemProperties[K, V, A](configDescriptor: ConfigStringModule.ConfigDescriptor[A], keyDelimiter: Option[Char] = None, valueDelimiter: Option[Char] = None, filterKeys: (String) ⇒ Boolean = _ => true)(implicit tag: Tag[A]): ZLayer[Any, ReadError[String], A]

    Consider providing keyDelimiter if you need to consider flattened config as a nested config.

    Consider providing keyDelimiter if you need to consider flattened config as a nested config. Consider providing valueDelimiter if you need any value to be a list

    Example:

    Given:

    vars in sys.env  = "KAFKA.SERVERS" = "server1, server2" ; "KAFKA.SERDE" = "confluent"
    keyDelimiter     = Some('.')
    valueDelimiter   = Some(',')

    then, the following works:

    final case class kafkaConfig(server: String, serde: String)
    nested("KAFKA")(string("SERVERS") zip string("SERDE")).to[KafkaConfig]
    Annotations
    @silent( "a type was inferred to be `Any`" )
  16. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String
    Definition Classes
    AnyRef → Any
  24. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped