SecretsWatcher
An Elixir library to watch secrets changes in a given directory.
Installation
def deps do
[
{:secrets_watcher, "~> 0.6"}
]
end
Usage
-
Establish the list of secrets you want to watch in a directory:
secrets =["aws-credentials.json",{"secret.txt", fn wrapped_secret-> do_something_with_secret(wrapped_secret) end}]ℹ️ Note that you actually use the filename of the secret to watch in a directory.
ℹ️ The form
{"secret_filename", callback}registers a callback which is called each time a secret has changed on disk. -
Configure and add
secrets_watcherto your supervision tree:children =[{SecretsWatcher,[name: :secrets,secrets_watcher_config: [directory: path_to_secrets_directory, secrets: secrets]]}]opts = [strategy: :one_for_one, name: MyApp.Supervisor]Supervisor.start_link(children, opts)ℹ️ If you don't specify the
:nameoption,SecretsWatcherwill be used by default.👉 By default,
secrets_watchertrim secrets withString.trim/1. You can deactivate this behavior with the optiontrim_secretsset tofalse. -
Whenever you want to retrieve a secret, use
SecretsWatcher.get_wrapped_secret/2:{:ok, wrapped_credentials} =SecretsWatcher.get_wrapped_secret(:secrets, "aws-credentials.json")secret = wrapped_credentials.()