Tidy up the env secrets handling
The secrets accessor was only used in the tests so remove it. Skip the memoization, it makes things slightly harder to follow and it's not needed.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
class Kamal::Configuration::Env
|
||||
include Kamal::Configuration::Validation
|
||||
|
||||
attr_reader :context
|
||||
attr_reader :clear, :secret_keys
|
||||
attr_reader :context, :clear, :secret_keys
|
||||
delegate :argumentize, to: Kamal::Utils
|
||||
|
||||
def initialize(config:, secrets:, context: "env")
|
||||
@@ -11,19 +10,14 @@ class Kamal::Configuration::Env
|
||||
@secret_keys = config.fetch("secret", [])
|
||||
@context = context
|
||||
validate! config, context: context, with: Kamal::Configuration::Validator::Env
|
||||
@secret_map = build_secret_map(@secret_keys)
|
||||
end
|
||||
|
||||
def clear_args
|
||||
argumentize("--env", clear)
|
||||
end
|
||||
|
||||
def secrets
|
||||
@resolved_secrets ||= resolve_secrets
|
||||
end
|
||||
|
||||
def secrets_io
|
||||
Kamal::EnvFile.new(secrets).to_io
|
||||
Kamal::EnvFile.new(aliased_secrets).to_io
|
||||
end
|
||||
|
||||
def merge(other)
|
||||
@@ -33,15 +27,12 @@ class Kamal::Configuration::Env
|
||||
end
|
||||
|
||||
private
|
||||
def build_secret_map(secret_keys)
|
||||
Array(secret_keys).to_h do |key|
|
||||
key_name, key_aliased_to = key.split(":", 2)
|
||||
key_aliased_to ||= key_name
|
||||
[ key_name, key_aliased_to ]
|
||||
end
|
||||
def aliased_secrets
|
||||
secret_keys.to_h { |key| extract_alias(key) }.transform_values { |secret_key| @secrets[secret_key] }
|
||||
end
|
||||
|
||||
def resolve_secrets
|
||||
@secret_map.transform_values { |secret_key| @secrets[secret_key] }
|
||||
def extract_alias(key)
|
||||
key_name, key_aliased_to = key.split(":", 2)
|
||||
[ key_name, key_aliased_to || key_name ]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user