View Source SecretVault.Storage (SecretVault v1.2.2)

Module with helpers to store secrets in various storages.

Transform function

All functions in this module accept an optional argument: transform which is a function to transform secret values. This may be helpful if your storage doesn't support string keys (or may be you don't want to deal with them) or if you just want to transform the data somehow.

Summary

Types

A function that transforms values fetched from the secret vault.

Types

@type transform_function() :: (String.t(), String.t() -> {a :: term(), b :: term()})

A function that transforms values fetched from the secret vault.

Functions

Link to this function

to_application_env(config, application_name, env_key \\ :secret_storage, transform \\ &no_transform/2)

View Source

Stores secrets in a Application env using Application.put_env/4.

Stored secrets can be accessed with Application.fetch_env!(application_name, :secret_storage)[name].

Example

iex> config = SecretVault.Config.test_config()
iex> SecretVault.put(config, "name", "value")
iex> to_application_env(config, :secret_vault)
iex> Application.fetch_env!(:secret_vault, :secret_storage)["name"]
"value"
Link to this function

to_ets(config, table, transform \\ &no_transform/2)

View Source

Stores secrets in a :ets table using :ets.insert.

Stored secrets can be accessed with :ets.lookup(table, name) or other :ets functions.

Example

iex> config = SecretVault.Config.test_config()
iex> SecretVault.put(config, "name", "value")
iex> table = :ets.new(:example_table, [:set, :protected])
iex> to_ets(config, table)
iex> :ets.lookup(table, "name")
[{"name", "value"}]
Link to this function

to_persistent_term(config, transform \\ &no_transform/2)

View Source

Stores secrets in a :persistent_term.

Stored secrets can be accessed with :persistent_term.get(name)

Example

iex> config = SecretVault.Config.test_config()
iex> SecretVault.put(config, "name", "value")
iex> to_persistent_term(config)
iex> :persistent_term.get("name")
"value"
Link to this function

to_proccess_dictionary(config, transform \\ &no_transform/2)

View Source

Stores secrets in a Application env using Process.put/2.

Stored secrets can be accessed with Process.get(name)

Example

iex> config = SecretVault.Config.test_config()
iex> SecretVault.put(config, "name", "value")
iex> to_proccess_dictionary(config)
iex> Process.get("name")
"value"