# `Malla.Util`
[🔗](https://github.com/netkubes/malla/blob/v0.1.0/lib/malla/util.ex#L21)

Helpers for applications built with Malla.

* `validate_app!/2` validates an application's environment against a
  `NimbleOptions` schema (only when the application depends on
  `:nimble_options`).
* `keyword_merge/2` and `map_merge/2` are the deep merges that Malla uses for
  service configuration.
* `redact/1`, `redact_args/2` and `secret_name?/1` hide secrets in terms
  before they are logged.

The other functions of this module are used by Malla itself and are not part
of its public API.

# `keyword_merge`

```elixir
@spec keyword_merge(keyword(), keyword()) :: keyword()
```

Deep merge of two keyword lists: when both values of a key are keyword lists
they are merged, any other value of `update` (maps and plain lists included)
replaces the one in `base`.

# `map_merge`

```elixir
@spec map_merge(map(), map()) :: map()
```

Deep merge of two maps: nested maps are merged, any other value of `update`
replaces the one in `base`.

# `redact`

```elixir
@spec redact(term()) :: term()
```

  Hides the values of secret-looking keys (`password`, `secret`, `token`,
  `credential`, `api_key`, `hmac_key`, `enc_key`, …) anywhere inside maps, keyword lists, lists
  and tuples, and the password of any URL (`ecto://user:pass@host`), so
  the term can be logged. Structs are kept as they are.

# `redact_args`

```elixir
@spec redact_args(atom() | String.t(), term()) :: term()
```

  The arguments of a call `fun`, ready to be logged: all of them hidden when
  the name of the function says it handles a secret (`set_password`,
  `check_password`, `login`, `verify_token`, …), since the secret is
  then a positional argument with no key to recognise it by;
  `redact/1` otherwise.

# `secret_name?`

```elixir
@spec secret_name?(term()) :: boolean()
```

Whether a key or function name looks like it holds a secret.

# `validate_app!`

```elixir
@spec validate_app!(NimbleOptions.schema() | NimbleOptions.t(), atom()) :: :ok
```

Validates the environment of application `app` against a `NimbleOptions`
`schema` and writes the validated values back (defaults included), so the
rest of the application reads them with `Application.get_env/3`.

Raises if the configuration is not valid. Meant for `c:Application.start/2`.
Available only when the application depends on `:nimble_options`, an optional
dependency of Malla.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
