lib/chamber/settings.rb in chamber-2.10.2 vs lib/chamber/settings.rb in chamber-2.11.0
- old
+ new
@@ -1,41 +1,46 @@
# frozen_string_literal: true
+
require 'hashie/mash'
require 'chamber/namespace_set'
require 'chamber/filters/namespace_filter'
require 'chamber/filters/encryption_filter'
require 'chamber/filters/decryption_filter'
require 'chamber/filters/environment_filter'
-require 'chamber/filters/boolean_conversion_filter'
require 'chamber/filters/secure_filter'
require 'chamber/filters/translate_secure_keys_filter'
require 'chamber/filters/insecure_filter'
require 'chamber/filters/failed_decryption_filter'
###
# Internal: Represents the base settings storage needed for Chamber.
#
module Chamber
class Settings
- attr_reader :namespaces
+ attr_accessor :pre_filters,
+ :post_filters,
+ :encryption_keys,
+ :decryption_keys
+ attr_reader :namespaces
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/LineLength
def initialize(options = {})
- self.namespaces = options[:namespaces] || []
- self.raw_data = options[:settings] || {}
- self.decryption_key = options[:decryption_key]
- self.encryption_key = options[:encryption_key]
- self.pre_filters = options[:pre_filters] || [
- Filters::NamespaceFilter,
- ]
- self.post_filters = options[:post_filters] || [
- Filters::DecryptionFilter,
- Filters::EnvironmentFilter,
- Filters::FailedDecryptionFilter,
- Filters::BooleanConversionFilter,
- Filters::TranslateSecureKeysFilter,
- ]
+ self.namespaces = options[:namespaces] || []
+ self.raw_data = options[:settings] || {}
+ self.decryption_keys = options[:decryption_keys] || {}
+ self.encryption_keys = options[:encryption_keys] || {}
+ self.pre_filters = options[:pre_filters] || [
+ Filters::NamespaceFilter,
+ ]
+ self.post_filters = options[:post_filters] || [
+ Filters::DecryptionFilter,
+ Filters::EnvironmentFilter,
+ Filters::FailedDecryptionFilter,
+ Filters::TranslateSecureKeysFilter,
+ ]
end
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/LineLength
###
# Internal: Converts a Settings object into a hash that is compatible as an
# environment variable hash.
#
@@ -181,16 +186,18 @@
other
elsif other.is_a? Hash
Settings.new(settings: other)
end
+ # rubocop:disable Metrics/LineLength
Settings.new(
- encryption_key: encryption_key || other_settings.encryption_key,
- decryption_key: decryption_key || other_settings.decryption_key,
- namespaces: (namespaces + other_settings.namespaces),
- settings: raw_data.merge(other_settings.raw_data),
+ encryption_keys: encryption_keys.any? ? encryption_keys : other_settings.encryption_keys,
+ decryption_keys: decryption_keys.any? ? decryption_keys : other_settings.decryption_keys,
+ namespaces: (namespaces + other_settings.namespaces),
+ settings: raw_data.merge(other_settings.raw_data),
)
+ # rubocop:enable Metrics/LineLength
end
###
# Internal: Determines whether a Settings is equal to another hash-like
# object.
@@ -233,18 +240,22 @@
pre_filters: [Filters::InsecureFilter],
post_filters: [Filters::TranslateSecureKeysFilter],
))
end
- protected
+ def method_missing(name, *args)
+ return data.public_send(name, *args) if data.respond_to?(name)
- attr_accessor :pre_filters,
- :post_filters,
- :encryption_key,
- :decryption_key,
- :raw_data
+ super
+ end
+ def respond_to_missing?(name, include_private = false)
+ data.respond_to?(name, include_private)
+ end
+
+ protected
+
def raw_data=(new_raw_data)
@raw_data = Hashie::Mash.new(new_raw_data)
end
def namespaces=(raw_namespaces)
@@ -263,26 +274,19 @@
filter.execute({ data: filtered_data }.
merge(metadata))
end
end
+ def secure_key_prefix
+ '_secure_'
+ end
+
def metadata
{
- namespaces: namespaces,
- decryption_key: decryption_key,
- encryption_key: encryption_key,
+ decryption_keys: decryption_keys,
+ encryption_keys: encryption_keys,
+ namespaces: namespaces,
+ secure_key_prefix: secure_key_prefix,
}
- end
-
- public
-
- def method_missing(name, *args)
- return data.public_send(name, *args) if data.respond_to?(name)
-
- super
- end
-
- def respond_to_missing?(name, include_private = false)
- data.respond_to?(name, include_private)
end
end
end