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))
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]
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]
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]
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]
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.
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]
Use functions in this
Configobject when you need to retrieve your instance of config in terms of zio.Layer.For example:
By using
Config.fromSystemEnv(myConfigDesc), it internally extends your description which ismyConfigDescto include theConfigSource. In the above example, it is theConfigSourcecorresponding tosys.env. It then callszio.config.readwith this new description that includes the source information.Extending an existing config description to include a
ConfigSourceis as simple asAlso, note that
Config[MyConfig]in the above example is a simple type alias toHas[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
ConfigSourcemanually.For example:
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 aLayer[ReadError[String], MyConfig]The above approach is especially useful when we have a custom
ConfigSource. For instance, we can form a customConfigSourceby composing a few existing ConfigSources.For example:
In the above example, the results returned an UIO because of the existence of ConfigSource
corresponding tosys.env.