Skip to content

Commit

Permalink
defaults: add support for token_file env
Browse files Browse the repository at this point in the history
  • Loading branch information
Matias Bertani committed May 17, 2023
1 parent 6945343 commit 3c6bb42
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/vault/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ def address
# The vault token to use for authentiation.
# @return [String, nil]
def token
if !ENV["VAULT_TOKEN"].nil?
return ENV["VAULT_TOKEN"]
end
ENV["VAULT_TOKEN"] || fetch_from_disk("VAULT_TOKEN_FILE", VAULT_DISK_TOKEN)
end

if VAULT_DISK_TOKEN.exist? && VAULT_DISK_TOKEN.readable?
return VAULT_DISK_TOKEN.read.chomp
def fetch_from_disk(env_var, default_path)
path = ENV[env_var] ? Pathname.new(ENV[env_var]) : default_path
if path&.exist? && path.readable?
return path.read.chomp
end

nil
end


# Vault Namespace, if any.
# @return [String, nil]
def namespace
Expand Down

0 comments on commit 3c6bb42

Please sign in to comment.