vaultex v0.6.2 Vaultex.Client

Provides a functionality to authenticate and read from a vault endpoint.

Link to this section Summary

Functions

Authenticates with vault using a tuple. This can be executed before attempting to read secrets from vault

Reads a secret from vault given a path

Writes a secret to Vault given a path

Link to this section Functions

Link to this function auth(method, credentials)
auth(method :: :token, credentials :: {token :: String.t()}) :: {:ok, :authenticated}
auth(method :: :github, credentials :: {github_token :: String.t()}) :: {:ok | :error, any()}
auth(method :: :userpass, credentials :: {username :: String.t(), password :: String.t()}) :: {:ok | :error, any()}
auth(method :: :app_id, credentials :: {app_id :: String.t(), user_id :: String.t()}) :: {:ok | :error, any()}
auth(method :: :approle, credentials :: {role_id :: String.t(), secret_id :: String.t()}) :: {:ok | :error, any()}

Authenticates with vault using a tuple. This can be executed before attempting to read secrets from vault.

Parameters

  • method: Auth backend to use for authenticating, can be one of :approle, :app_id, :userpass, :github, :token
  • credentials: A tuple used for authentication depending on the method, {role_id, secret_id} for :approle, {app_id, user_id} for :app_id, {username, password} for :userpass, {github_token} for :github, {token} for :token

Examples

iex> Vaultex.Client.auth(:app_id, {app_id, user_id})
{:ok, :authenticated}

iex> Vaultex.Client.auth(:userpass, {username, password})
{:error, ["Something didn't work"]}

iex> Vaultex.Client.auth(:github, {github_token})
{:ok, :authenticated}
Link to this function read(key, auth_method, credentials)

Reads a secret from vault given a path.

Parameters

  • key: A String path to be used for querying vault.
  • auth_method and credentials: See Vaultex.Client.auth

Examples

iex> Vaultex.Client.read "secret/foo", :app_id, {app_id, user_id}
{:ok, %{"value" => "bar"}}

iex> Vaultex.Client.read "secret/baz", :userpass, {username, password}
{:error, ["Key not found"]}

iex> Vaultex.Client.read "secret/bar", :github, {github_token}
{:ok, %{"value" => "bar"}}
Link to this function write(key, value, auth_method, credentials)

Writes a secret to Vault given a path.

Parameters

  • key: A String path where the secret will be written.
  • value: A String => String map that will be stored in Vault
  • auth_method and credentials: See Vaultex.Client.auth

Examples

iex> Vaultex.Client.write "secret/foo", %{"value" => "bar"}, :app_id, {app_id, user_id}
:ok