ConfigValue

ciris.ConfigValue
See theConfigValue companion object
sealed abstract class ConfigValue[+F[_], A]

Represents a configuration value or a composition of multiple values.

If a configuration value is missing, we can use ConfigValue#or to try and load the value from elsewhere. ConfigValue#default can be used to set a default value if all other values are missing. If the value is optional, ConfigValue#option can be used to default to None if all values are missing.

Values can be converted to a different type using ConfigValue#as. If the value might contain sensitive details, ConfigValue#secret can be used to redact sensitive details from error messages while also wrapping the value in Secret, preventing the value from being shown.

Sometimes, we first need to load a configuration value to determine how to continue loading the remaining values. In such cases, it's suitable to use ConfigValue#flatMap. When loading values in sequence using flatMap, errors are not accumulated, and so only the first error will be available.

Parallel composition lets us achieve error accumulation. Functions like parMapN and parTupled on tuples of ConfigValues loads several values while also accumulating errors. It is often helpful to see all errors when loading configurations, so prefer options which accumulate errors.

Configuration values can be loaded using ConfigValue#load, which loads the value using a specified effect type. If a ConfigValue contains Resources for loading the configuration, there is also the option to return a Resource with ConfigValue#resource.

Attributes

Example

scala> import cats.effect.IO
import cats.effect.IO
scala> import cats.effect.unsafe.implicits.global
import cats.effect.unsafe.implicits.global
scala> import cats.syntax.all._
import cats.syntax.all._
scala> case class Config(maxRetries: Int, apiKey: Option[Secret[String]])
class Config
scala> val maxRetries = env("MAX_RETRIES").or(prop("max.retries")).as[Int].default(5)
val maxRetries: ConfigValue[[x]Effect[x],Int] = ConfigValue$$88354410
scala> val apiKey = env("API_KEY").or(prop("api.key")).secret.option
val apiKey: ConfigValue[[x]Effect[x],Option[Secret[String]]] = ConfigValue$$2109306667
scala> val config = (maxRetries, apiKey).parMapN(Config(_, _))
val config: ConfigValue[[x]Effect[x],Config] = ConfigValue$$1463229407
scala> config.load[IO].unsafeRunSync()
res0: Config = Config(5,None)
Companion
object
Source
ConfigValue.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

final def alt[G[x]](value: => ConfigValue[G, A]): ConfigValue[G, A]

Returns a new ConfigValue which uses the specified configuration if the value is missing.

Returns a new ConfigValue which uses the specified configuration if the value is missing.

If the value is a compound value, an attempt to use the specified configuration will be attempted if all of its parts are either missing or successful.

If the value is a default value, an attempt is made to use the specified configuration, and if that is also missing, the default value remains. If that is a compound value, the default value only remains if all of its parts are either missing or successful.

Defaults in the specified configuration will override any previous defaults.

Errors from both the value and the specified configuration are accumulated.

Attributes

Source
ConfigValue.scala
final def as[B](implicit decoder: ConfigDecoder[A, B]): ConfigValue[F, B]

Returns a new ConfigValue which attempts to decode the value to the specified type.

Returns a new ConfigValue which attempts to decode the value to the specified type.

Attributes

Source
ConfigValue.scala
final def attempt[G[x]](implicit G: Async[G]): G[Either[ConfigError, A]]

Returns an effect of the specified type which attempts to load the configuration value.

Returns an effect of the specified type which attempts to load the configuration value.

Note that if the ConfigValue contains any resources, from using ConfigValue.resource, these will be used (acquired and released) as part of the returned effect. If this behaviour is not desired, we can instead use ConfigValue#resource to return a Resource.

Attributes

Source
ConfigValue.scala
final def base64(implicit decoderString: ConfigDecoder[A, String], decoderA: ConfigDecoder[String, A]): ConfigValue[F, A]

Returns a new ConfigValue which base64 decodes the value.

Returns a new ConfigValue which base64 decodes the value.

The value has to be String-like in the sense that we can decode it to String and then back again after base64 decoding. This is the case for both String and Secret[String], for example.

The base64 decoded bytes have to be valid UTF-8. If they are not, for example when the value is binary data like a key, decoding fails with an error instead.

Attributes

Source
ConfigValue.scala
final def covary[G[x]]: ConfigValue[G, A]

Returns the same ConfigValue but lifted to the specified effect type.

Returns the same ConfigValue but lifted to the specified effect type.

Attributes

Source
ConfigValue.scala
final def default(value: => A): ConfigValue[F, A]

Returns a new ConfigValue which uses the specified default if the value is missing.

Returns a new ConfigValue which uses the specified default if the value is missing.

If a previous default value has been specified, a later default will override the earlier. If a default value is specified for a composition of values, the default will be used in case all values are either missing or are default values themselves.

Using .default(a) is equivalent to using .or(default(a)).

Attributes

Source
ConfigValue.scala
final def evalAttemptTap[G[x], B](f: (Either[ConfigError, A]) => G[B]): ConfigValue[G, A]

Return a new ConfigValue which applies the specified effectful function on the value or error, and discards the result

Return a new ConfigValue which applies the specified effectful function on the value or error, and discards the result

Attributes

Source
ConfigValue.scala
final def evalFlatMap[G[x], B](f: A => G[ConfigValue[G, B]]): ConfigValue[G, B]

Alias for evalMap(f).flatten.

Alias for evalMap(f).flatten.

Attributes

Source
ConfigValue.scala
final def evalMap[G[x], B](f: A => G[B]): ConfigValue[G, B]

Returns a new ConfigValue which applies the specified effectful function on the value.

Returns a new ConfigValue which applies the specified effectful function on the value.

Attributes

Source
ConfigValue.scala
final def evalTap[G[x], B](f: A => G[B]): ConfigValue[G, A]

Return a new ConfigValue which applies the specified effectful function on the value, and discards the result

Return a new ConfigValue which applies the specified effectful function on the value, and discards the result

Attributes

Source
ConfigValue.scala
final def flatMap[G[x], B](f: A => ConfigValue[G, B]): ConfigValue[G, B]

Returns a new ConfigValue which loads the specified configuration using the value.

Returns a new ConfigValue which loads the specified configuration using the value.

Attributes

Source
ConfigValue.scala
final def load[G[x]](implicit G: Async[G]): G[A]

Returns an effect of the specified type which loads the configuration value.

Returns an effect of the specified type which loads the configuration value.

Note that if the ConfigValue contains any resources, from using ConfigValue.resource, these will be used (acquired and released) as part of the returned effect. If this behaviour is not desired, we can instead use ConfigValue#resource to return a Resource.

Attributes

Source
ConfigValue.scala
final def map[B](f: A => B): ConfigValue[F, B]

Returns a new ConfigValue which applies the specified function on the value.

Returns a new ConfigValue which applies the specified function on the value.

Attributes

Source
ConfigValue.scala
final def option: ConfigValue[F, Option[A]]

Returns a new ConfigValue which uses None as the default if the value is missing.

Returns a new ConfigValue which uses None as the default if the value is missing.

Using .option is equivalent to using .map(_.some).default(None).

Attributes

Source
ConfigValue.scala
final def or[G[x]](value: => ConfigValue[G, A]): ConfigValue[G, A]

Returns a new ConfigValue which uses the specified configuration if the value is missing.

Returns a new ConfigValue which uses the specified configuration if the value is missing.

If the value is a compound value, an attempt to use the specified configuration will only be attempted if all of its parts are missing.

If the value is a default value, an attempt is made to use the specified configuration, and if that is also missing, the default value remains. If that is a compound value, the default value only remains if all of its parts are missing.

Defaults in the specified configuration will override any previous defaults.

Errors from both the value and the specified configuration are accumulated.

Attributes

Source
ConfigValue.scala
final def redacted: ConfigValue[F, A]

Returns a new ConfigValue with sensitive details redacted from error messages.

Returns a new ConfigValue with sensitive details redacted from error messages.

Using .redacted is equivalent to using .secret.map(_.value), except without requiring a Show instance.

Attributes

Source
ConfigValue.scala
final def resource[G[x]](implicit G: Async[G]): Resource[G, A]

Returns a Resource with the specified effect type which loads the configuration value.

Returns a Resource with the specified effect type which loads the configuration value.

Attributes

Source
ConfigValue.scala
final def secret(implicit show: Show[A]): ConfigValue[F, Secret[A]]

Returns a new ConfigValue which treats the value like it might contain sensitive details.

Returns a new ConfigValue which treats the value like it might contain sensitive details.

Sensitive details are redacted from error messages. The value is wrapped in Secret, which prevents the value from being shown.

Using .secret is equivalent to using .redacted.map(Secret(_)).

Attributes

Source
ConfigValue.scala
final def useOnceSecret(implicit ev: A <:< Array[Char]): ConfigValue[F, UseOnceSecret]

Returns a new ConfigValue which treats the value as a secret which can only be used once.

Returns a new ConfigValue which treats the value as a secret which can only be used once.

Sensitive details are redacted from error messages. The value is wrapped in UseOnceSecret which prevents multiple accesses to the secret and which nullifies the secret once it has been used.

Attributes

Source
ConfigValue.scala