One file, no destination env
This commit is contained in:
committed by
Donal McBreen
parent
fcdef5fa06
commit
7daaabd4d4
@@ -1,29 +1,18 @@
|
|||||||
class Kamal::Configuration::Secrets
|
class Kamal::Configuration::Secrets
|
||||||
attr_reader :secret_file, :destination
|
attr_reader :secrets_file
|
||||||
|
|
||||||
def initialize(destination: nil)
|
def initialize(destination: nil)
|
||||||
@destination = destination
|
@secrets_file = [ *(".kamal/secrets.#{destination}" if destination), ".kamal/secrets" ].find { |f| File.exist?(f) }
|
||||||
@secret_file = (destination ? [ ".kamal/secrets.#{destination}", ".kamal/secrets" ] : [ ".kamal/secrets" ])
|
|
||||||
.find { |file| File.exist?(file) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](key)
|
def [](key)
|
||||||
@secrets ||= load
|
@secrets ||= secrets_file ? Dotenv.parse(*secrets_file) : {}
|
||||||
@secrets.fetch(key)
|
@secrets.fetch(key)
|
||||||
rescue KeyError
|
rescue KeyError
|
||||||
if secret_file
|
if secrets_file
|
||||||
raise Kamal::ConfigurationError, "Secret '#{key}' not found in #{secret_file}"
|
raise Kamal::ConfigurationError, "Secret '#{key}' not found in #{secrets_file}"
|
||||||
else
|
else
|
||||||
raise Kamal::ConfigurationError, "Secret '#{key}' not found, no secret file provided"
|
raise Kamal::ConfigurationError, "Secret '#{key}' not found, no secret files provided"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def load
|
|
||||||
original_env = ENV.to_hash
|
|
||||||
ENV["KAMAL_DESTINATION"] = destination if destination
|
|
||||||
secret_file ? Dotenv.parse(*secret_file) : {}
|
|
||||||
ensure
|
|
||||||
ENV.replace(original_env)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user