# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/components/base' require 'contrast/components/config' module Contrast module Components module Api # A wrapper build around the Common Agent Configuration project to allow # for Api keys to be mapped with their values contained in their # parent_configuration_spec.yaml. class Interface include Contrast::Components::ComponentBase def api_url @_api_url ||= begin tmp = ::Contrast::CONFIG.root.api.url tmp += '/Contrast' unless tmp.end_with?('/Contrast') tmp end end def api_key @_api_key ||= ::Contrast::CONFIG.root.api.api_key end def service_key @_service_key ||= ::Contrast::CONFIG.root.api.service_key end def username @_username ||= ::Contrast::CONFIG.root.api.user_name end def proxy_enabled? return @_proxy_enabled unless @_proxy_enabled.nil? @_proxy_enabled = true?(::Contrast::CONFIG.root.api.proxy.enable) end def proxy_url @_proxy_url ||= ::Contrast::CONFIG.root.api.proxy.url end def request_audit_enable? return @_request_audit_enable unless @_request_audit_enable.nil? @_request_audit_enable = true?(::Contrast::CONFIG.root.api.request_audit.enable) end def request_audit_requests? return @_request_audit_requests unless @_request_audit_requests.nil? @_request_audit_requests = true?(::Contrast::CONFIG.root.api.request_audit.requests) end def request_audit_responses? return @_request_audit_responses unless @_request_audit_responses.nil? @_request_audit_responses = true?(::Contrast::CONFIG.root.api.request_audit.responses) end def request_audit_path @_request_audit_path ||= ::Contrast::CONFIG.root.api.request_audit.path.to_s end def certification_enabled? return @_certification_enabled unless @_certification_enabled.nil? @_certification_enabled = certification_truly_enabled?(::Contrast::CONFIG.root.api.certificate) end def certification_ca_file @_certification_ca_file ||= ::Contrast::CONFIG.root.api.certificate.ca_file end def certification_cert_file @_certification_cert_file ||= ::Contrast::CONFIG.root.api.certificate.cert_file end def certification_key_file @_certification_key_file ||= ::Contrast::CONFIG.root.api.certificate.key_file end private def certification_truly_enabled? config_path return false unless true?(config_path.enable) return true if file_exists?(certification_ca_file) && valid_cert?(certification_ca_file) return true if file_exists?(certification_cert_file) && valid_cert?(certification_cert_file) return true if file_exists?(certification_key_file) && valid_cert?(certification_key_file) false end end end end end