# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Config # Certificate Configuration class CertificationConfiguration < BaseConfiguration # @return [String] path to CA Cert file attr_reader :ca_file # @return [String] path to Certification file attr_reader :cert_file # @return [String] path to Certification Key file attr_reader :key_file def initialize hsh = {} @enable = traverse_config(hsh, :enable) @ca_file = traverse_config(hsh, :ca_file) @cert_file = traverse_config(hsh, :cert_file) @key_file = traverse_config(hsh, :key_file) @configuration_map = {} build_configuration_map end # GETTERS # @return [Boolean] def enable return false if @enable.nil? @enable end # SETTERS def enable= value self['enable'] = value end def ca_file= value self['ca_file'] = value end def cert_file= value self['cert_file'] = value end def key_file= value self['key_file'] = value end # TODO: RUBY-1493 MOVE TO BASE CONFIG def []= key, value instance_variable_set("@#{ key }".to_sym, value) @configuration_map[key] = value end def [] key send(key.to_sym) end # Traverse the given entity to build out the configuration graph. # # The values will be either a hash, indicating internal nodes to # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a # leaf node. # # The spec_key are the Contrast defined keys based on the instance variables of # a given configuration. def traverse_config values, spec_key internal_nodes = values.cs__respond_to?(:has_key?) val = internal_nodes ? value_from_key_config(spec_key, values) : nil val == EMPTY_VALUE ? nil : val end def build_configuration_map instance_variables.each do |key| str_key = key.to_s.tr('@', '') next if str_key == 'configuration_map' @configuration_map[str_key] = send(str_key.to_sym) end end end end end