<commit_before># frozen_string_literal: true

module Conjur
  module PuppetModule
    module Config
      CONFIG_FILE_PATH = '/etc/conjur.conf'
      REG_KEY_NAME = 'Software\CyberArk\Conjur'

      class << self
        def load
          Puppet.features.microsoft_windows? ? from_registry : from_file
        end

        def from_file
          if File.exist?(CONFIG_FILE_PATH)
            c = YAML.safe_load(File.read(CONFIG_FILE_PATH))
            c['ssl_certificate'] ||= File.read c['cert_file'] \
                if c['cert_file']
            c
          else
            {}
          end
        end

        def from_registry
          raise 'Conjur::PuppetModule::Config#from_registry is only supported on Windows' \
            unless Puppet.features.microsoft_windows?

          require 'win32/registry'

          c = {}
          begin
            Win32::Registry::HKEY_LOCAL_MACHINE.open(REG_KEY_NAME) do |reg|
              # Convert registry value names from camel case to underscores
              # e.g. ApplianceUrl => appliance_url
              c = reg.map { |name, _type, data|  [name.gsub(/(.)([A-Z])/, '\1_\2').downcase, data] }.to_h
            end
          rescue
            Puppet.warning "Agent’s registry did not contain path #{REG_KEY_NAME}. If this is the " +
              "first time using HFTs on this node, this is expected behavior."
          end

          c['ssl_certificate'] ||= File.read c['cert_file'] if c['cert_file']

          c
        end
      end
    end
  end
end<commit_msg>Fix agent's missing registry entries warning on Windows agents<commit_after># frozen_string_literal: true

module Conjur
  module PuppetModule
    module Config
      CONFIG_FILE_PATH = '/etc/conjur.conf'
      REG_KEY_NAME = 'Software\CyberArk\Conjur'

      class << self
        def load
          Puppet.features.microsoft_windows? ? from_registry : from_file
        end

        def from_file
          if File.exist?(CONFIG_FILE_PATH)
            c = YAML.safe_load(File.read(CONFIG_FILE_PATH))
            c['ssl_certificate'] ||= File.read c['cert_file'] \
                if c['cert_file']
            c
          else
            {}
          end
        end

        def from_registry
          raise 'Conjur::PuppetModule::Config#from_registry is only supported on Windows' \
            unless Puppet.features.microsoft_windows?

          require 'win32/registry'

          c = {}
          begin
            Win32::Registry::HKEY_LOCAL_MACHINE.open(REG_KEY_NAME) do |reg|
              # Convert registry value names from camel case to underscores
              # e.g. ApplianceUrl => appliance_url
              c = reg.map { |name, _type, data|  [name.gsub(/(.)([A-Z])/, '\1_\2').downcase, data] }.to_h
            end
          rescue
            Puppet.notice "Windows Registry on the agent did not contain path '#{REG_KEY_NAME}'. If " +
              "this is the first time using server-provided credentials, this is expected behavior."
          end

          c['ssl_certificate'] ||= File.read c['cert_file'] if c['cert_file']

          c
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09340133885878228, 'fraction_numerical': 0.003825310806503028, 'mean_word_length': 1.8501362397820162, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3726937', 'n_tokens_mistral': 950, 'n_tokens_neox': 906, 'n_words': 232}