Sha256: 259183f96bd22590884024d469aeb7f3ceb654a08e1f9a528626d0c8ff110c2b

Contents?: true

Size: 1.66 KB

Versions: 36

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Windows
      class AioAgentVersion < BaseResolver
        REGISTRY_PATH = 'SOFTWARE\\Puppet Labs\\Puppet'
        init_resolver

        class << self
          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { read_version(fact_name) }
          end

          def read_version(fact_name)
            ::Win32::Registry::HKEY_LOCAL_MACHINE.open(REGISTRY_PATH) do |reg|
              build_fact_list(reg)
            end

            @fact_list[fact_name]
          rescue Win32::Registry::Error
            log.debug("The registry path #{REGISTRY_PATH} does not exist")
          end

          def build_fact_list(reg)
            puppet_aio_path = read_for_64_bit(reg) || read_for_32_bit(reg)

            return if puppet_aio_path.nil? || puppet_aio_path.empty?

            puppet_aio_version_path = File.join(puppet_aio_path, 'VERSION')
            aio_agent_version = Facter::Util::FileHelper.safe_read(puppet_aio_version_path, nil)&.chomp

            @fact_list[:aio_agent_version] = aio_agent_version&.match(/^\d+\.\d+\.\d+(\.\d+){0,2}/)&.to_s
          end

          def read_for_64_bit(reg)
            reg.read('RememberedInstallDir64')[1]
          rescue Win32::Registry::Error
            log.debug('Could not read Puppet AIO path from 64 bit registry')
            nil
          end

          def read_for_32_bit(reg)
            reg.read('RememberedInstallDir')[1]
          rescue Win32::Registry::Error
            log.debug('Could not read Puppet AIO path from 32 bit registry')
            nil
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.9.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.8.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.7.1 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.7.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.6.1 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.6.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.5.2 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.5.1 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.5.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.4.3 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.4.2 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.4.1 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.4.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.3.1 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.3.0 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.2.14 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.2.13 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.2.12 lib/facter/resolvers/windows/aio_agent_version.rb
facter-4.2.11 lib/facter/resolvers/windows/aio_agent_version.rb