cover/Elixir.WalletAuth.Secrets.EnvSecretProvider.html

1 defmodule WalletAuth.Secrets.EnvSecretProvider do
2 @moduledoc """
3 Default secret provider that reads from application config / environment.
4
5 Suitable for development and test environments.
6 Production deployments should replace this with a Vault/Cloud-KMS backed provider.
7
8 Configure via:
9 config :wallet_auth, :secrets, %{
10 "jwt_signing_key" => System.get_env("JWT_SIGNING_KEY")
11 }
12 """
13 @behaviour WalletAuth.Secrets.SecretProvider
14
15 @impl true
16 def get(name) do
17 26 secrets = Application.get_env(:wallet_auth, :secrets, %{})
18
19 26 case Map.fetch(secrets, name) do
20
:-(
{:ok, nil} -> {:error, :not_found}
21
:-(
{:ok, ""} -> {:error, :not_found}
22 26 {:ok, value} -> {:ok, value}
23
:-(
:error -> {:error, :not_found}
24 end
25 end
26
27 @impl true
28 def get!(name) do
29 18 case get(name) do
30 {:ok, value} ->
31 18 value
32
33 {:error, reason} ->
34
:-(
raise RuntimeError,
35
:-(
"Required secret '#{name}' is unavailable (#{reason}). " <>
36 "Check :wallet_auth secrets configuration."
37 end
38 end
39 end
Line Hits Source