lib/service_skeleton/config.rb in service_skeleton-0.0.0.34.g4f6fdb0 vs lib/service_skeleton/config.rb in service_skeleton-0.0.0.41.g9507cda
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require "to_regexp"
require_relative "./filtering_logger"
require "loggerstash"
@@ -9,41 +11,44 @@
attr_reader :logger, :env
def initialize(env, svc)
@svc = svc
- parse_registered_variables(env)
+ # Parsing registered variables will redact the environment, so we want
+ # to take a private unredacted copy before that happens
@env = env.to_hash.dup.freeze
+
+ parse_registered_variables(env)
+
+ # Sadly, we can't setup the logger until we know *how* to setup the
+ # logger, which requires parsing config variables
setup_logger
end
def [](k)
@env[k]
end
private
def parse_registered_variables(env)
- @svc.registered_variables.each do |var|
- val = var.value(env)
+ (@svc.registered_variables || []).map do |var|
+ var[:class].new(var[:name], env, **var[:opts])
+ end.each do |var|
+ val = var.value
+ method_name = var.method_name(@svc.service_name).to_sym
- define_singleton_method(var.method_name(@svc.service_name)) do
+ define_singleton_method(method_name) do
val
end
- define_singleton_method(var.method_name(@svc.service_name) + "=") do |v|
- val = v
+ define_singleton_method(:"#{method_name}=") do |new_value|
+ val = new_value
end
-
- if var.sensitive?
- if env.object_id != ENV.object_id
- raise ServiceSkeleton::Error::CannotSanitizeEnvironmentError,
- "Attempted to sanitize sensitive variable #{var.name}, but was not passed the ENV object"
- end
-
- var.env_keys(env).each do |k|
- env[k] = "*SENSITIVE*"
- end
+ end.each do |var|
+ if var.redact!(env) && env.object_id != ENV.object_id
+ raise ServiceSkeleton::Error::CannotSanitizeEnvironmentError,
+ "Attempted to sanitize sensitive variable #{var.name}, but we're not operating on the process' environment"
end
end
end
def setup_logger