From 3c6bb425d089929ac3300d541202a394acae1304 Mon Sep 17 00:00:00 2001 From: Matias Bertani Date: Wed, 17 May 2023 11:59:27 -0300 Subject: [PATCH] defaults: add support for token_file env --- lib/vault/defaults.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/vault/defaults.rb b/lib/vault/defaults.rb index 89f9465..5594a48 100644 --- a/lib/vault/defaults.rb +++ b/lib/vault/defaults.rb @@ -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