# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/config/base_configuration' module Contrast module Config # Common Configuration settings. Those in this section pertain to the server identification functionality of the # Agent. class ServerConfiguration include Contrast::Config::BaseConfiguration include Contrast::Components::ComponentBase CANON_NAME = 'server' CONFIG_VALUES = %w[tags environment version].cs__freeze # @return [String, nil] attr_accessor :name # @return [String, nil] attr_accessor :path # @return [String, nil] attr_accessor :type attr_writer :tags # @return [String, nil] attr_accessor :environment # @return [String, nil] attr_accessor :version # @return [String] attr_reader :canon_name # @return [Array] attr_reader :config_values def initialize hsh = {} @config_values = CONFIG_VALUES @canon_name = CANON_NAME return unless hsh @path = hsh[:path] @name = hsh[:name] @type = hsh[:type] @tags = hsh[:tags] @environment = hsh[:environment] @version = hsh[:version] end # @return [String, nil] def tags stringify_array(@tags) end # Converts current configuration to effective config values class and appends them to # EffectiveConfig class. # # @param effective_config [Contrast::Config::Diagnostics::EffectiveConfig] def to_effective_config effective_config super add_single_effective_value(effective_config, 'type', Contrast::APP_CONTEXT.server_type, CANON_NAME, "#{ CONTRAST }.#{ CANON_NAME }") add_single_effective_value(effective_config, 'name', Contrast::APP_CONTEXT.server_name, CANON_NAME, "#{ CONTRAST }.#{ CANON_NAME }") add_single_effective_value(effective_config, 'path', Contrast::APP_CONTEXT.server_path, CANON_NAME, "#{ CONTRAST }.#{ CANON_NAME }") end end end end