ExSecrets (ex_secrets v0.3.0)

This module functions to access secrets in an Elixir application.

Link to this section Summary

Functions

Get secret value. You can pass two options

Get secret value with provider name and default value

Internal function for fetching secret with provide for catching and rate limiting. Do not rely on this function.

Resets cache and reloads all providers.

Set secret value.

Link to this section Functions

Link to this function

get(key, opts \\ [])

@spec get(String.t(), provider: atom(), default_value: any()) :: String.t() | nil

Get secret value. You can pass two options:

  • provider: Name of the provider to use. Default is :system_env
  • default_value: Default value to return if secret is not found. Default is nil

examples

Examples

iex> ExSecrets.get("FOO")
nil
iex> Application.put_env(:ex_secrets, :default_provider, :dot_env)
:ok
iex> ExSecrets.get("FOO")
nil
iex> System.put_env "FOO", "BAR"
:ok
iex> ExSecrets.get("FOO")
"BAR"
iex> System.delete_env "FOO"
:ok
iex> ExSecrets.get("FOO")
"BAR"
iex> ExSecrets.reset()
:ok
iex> ExSecrets.get("FOO")
nil
iex> Application.delete_env(:ex_secrets, :default_provider)
:ok
iex> Application.put_env(:ex_secrets, :providers, %{dot_env: %{path: "test/support/fixtures/dot_env_test.env"}})
:ok
iex> ExSecrets.get("ERL", provider: :dot_env)
nil
iex> ExSecrets.get("ERL", provider: :dot_env, default_value: "ANG")
"ANG"
iex> Application.delete_env(:ex_secrets, :providers)
:ok
iex> Application.put_env(:ex_secrets, :providers, %{dot_env: %{path: "test/support/fixtures/dot_env_test.env"}})
:ok
iex> ExSecrets.get("DEVS", provider: :dot_env)
"ROCKS"
iex> Application.delete_env(:ex_secrets, :providers)
:ok
Link to this function

get(key, provider, default)

This function is deprecated. This function is deprecated. Use get/2 instead..

Get secret value with provider name and default value

Link to this function

get_using_provider(key, provider)

Internal function for fetching secret with provide for catching and rate limiting. Do not rely on this function.

Resets cache and reloads all providers.

Link to this function

set(key, value, opts \\ [])

@spec set(String.t(), String.t(), Keyword.t()) :: :ok | :error

Set secret value.

Supported for providers:

  • :system_env
  • :azure_key_vault
  • :azure_managed_identity
  • :google_secret_manager

Calling this function requires the provider to be configured with credentials that allow create secrets like Secret Admionistrator in Azure Key Vault.