class OnContainer::Secrets::MountedFiles::EnvLoader
Public Instance Methods
perform!()
click to toggle source
# File lib/on_container/secrets/mounted_files/env_loader.rb, line 13 def perform! setup_secrets_path scan_secrets_path_for_files load_secret_files_to_env_vars end
secret_mounted_file_paths()
click to toggle source
# File lib/on_container/secrets/mounted_files/env_loader.rb, line 23 def secret_mounted_file_paths @secret_mounted_file_paths ||= Dir["#{secrets_path}/**/*"] .map { |path| Pathname.new(path) } .select(&:file?) end
Also aliased as: scan_secrets_path_for_files
secrets_path()
click to toggle source
# File lib/on_container/secrets/mounted_files/env_loader.rb, line 19 def secrets_path @secrets_path ||= ENV.fetch('SECRETS_PATH', '/run/secrets') end
Also aliased as: setup_secrets_path
Private Instance Methods
load_secret_file_to_env_var(file_path)
click to toggle source
# File lib/on_container/secrets/mounted_files/env_loader.rb, line 43 def load_secret_file_to_env_var(file_path) env_var_name = file_path.basename('.*').to_s.upcase # Skip if variable is already set - already-set variables have # precedence over the secret files: return if ENV.key?(env_var_name) && ENV[env_var_name].present? contents = file_path.read.strip # TODO: Do not load if content has null bytes ENV[env_var_name] = file_path.read.strip end
load_secret_files_to_env_vars()
click to toggle source
# File lib/on_container/secrets/mounted_files/env_loader.rb, line 34 def load_secret_files_to_env_vars return if @already_loaded secret_mounted_file_paths .each { |file_path| load_secret_file_to_env_var(file_path) } @already_loaded = true end