Skip to content

Commit

Permalink
Fix loading of mounted secret files to env variables (#14)
Browse files Browse the repository at this point in the history
* Don't require `SECRETS_PATH` to end with a slash

* Recurse over the secret files directory to find files [Closes #13]
  • Loading branch information
vovimayhem authored Feb 23, 2021
1 parent 4159422 commit 3b2a1dd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/on_container/load_env_secrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

# Process only a known list of env vars that can filled by reading a file (i.e.
# a docker secret):
Dir["#{ENV.fetch('SECRETS_PATH', '/run/secrets/')}*"].each do |secret_filepath|
next unless File.file?(secret_filepath)

secret_envvarname = File.basename(secret_filepath, '.*').upcase
Dir["#{ENV.fetch('SECRETS_PATH', '/run/secrets')}/**/*"].map do |path|
Pathname.new(path)
end.select(&:file?).each do |secret_filepath|
secret_envvarname = secret_filepath.basename('.*').to_s.upcase

# Skip if variable is already set - already-set variables have precedence over
# the secret files:
Expand Down Expand Up @@ -55,4 +55,4 @@
ENV[url_key] = uri.to_s
end

# STDERR.puts ENV.inspect
# STDERR.puts ENV.inspect

0 comments on commit 3b2a1dd

Please sign in to comment.