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
|
class Kamal::Configuration::Env
|
||||||
include Kamal::Configuration::Validation
|
include Kamal::Configuration::Validation
|
||||||
|
|
||||||
attr_reader :context
|
attr_reader :context, :clear, :secret_keys
|
||||||
attr_reader :clear, :secret_keys
|
|
||||||
delegate :argumentize, to: Kamal::Utils
|
delegate :argumentize, to: Kamal::Utils
|
||||||
|
|
||||||
def initialize(config:, secrets:, context: "env")
|
def initialize(config:, secrets:, context: "env")
|
||||||
@@ -11,19 +10,14 @@ class Kamal::Configuration::Env
|
|||||||
@secret_keys = config.fetch("secret", [])
|
@secret_keys = config.fetch("secret", [])
|
||||||
@context = context
|
@context = context
|
||||||
validate! config, context: context, with: Kamal::Configuration::Validator::Env
|
validate! config, context: context, with: Kamal::Configuration::Validator::Env
|
||||||
@secret_map = build_secret_map(@secret_keys)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_args
|
def clear_args
|
||||||
argumentize("--env", clear)
|
argumentize("--env", clear)
|
||||||
end
|
end
|
||||||
|
|
||||||
def secrets
|
|
||||||
@resolved_secrets ||= resolve_secrets
|
|
||||||
end
|
|
||||||
|
|
||||||
def secrets_io
|
def secrets_io
|
||||||
Kamal::EnvFile.new(secrets).to_io
|
Kamal::EnvFile.new(aliased_secrets).to_io
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge(other)
|
def merge(other)
|
||||||
@@ -33,15 +27,12 @@ class Kamal::Configuration::Env
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def build_secret_map(secret_keys)
|
def aliased_secrets
|
||||||
Array(secret_keys).to_h do |key|
|
secret_keys.to_h { |key| extract_alias(key) }.transform_values { |secret_key| @secrets[secret_key] }
|
||||||
key_name, key_aliased_to = key.split(":", 2)
|
|
||||||
key_aliased_to ||= key_name
|
|
||||||
[ key_name, key_aliased_to ]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_secrets
|
def extract_alias(key)
|
||||||
@secret_map.transform_values { |secret_key| @secrets[secret_key] }
|
key_name, key_aliased_to = key.split(":", 2)
|
||||||
|
[ key_name, key_aliased_to || key_name ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
4
test/configuration/env/tags_test.rb
vendored
4
test/configuration/env/tags_test.rb
vendored
@@ -92,7 +92,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
config = Kamal::Configuration.new(deploy)
|
config = Kamal::Configuration.new(deploy)
|
||||||
assert_equal "hello", config.role("web").env("1.1.1.1").secrets["PASSWORD"]
|
assert_equal "PASSWORD=hello\n", config.role("web").env("1.1.1.1").secrets_io.string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
config = Kamal::Configuration.new(deploy)
|
config = Kamal::Configuration.new(deploy)
|
||||||
assert_equal "aliased_hello", config.role("web").env("1.1.1.1").secrets["PASSWORD"]
|
assert_equal "PASSWORD=aliased_hello\n", config.role("web").env("1.1.1.1").secrets_io.string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user