Sha256: 00c97e0c6e4f4e8bc94d7251b05401b946621827b7c347e7a8a9e9bdf5e38c4a

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Windows
      class Ssh < BaseResolver
        @log = Facter::Log.new(self)
        @fact_list ||= {}
        FILE_NAMES = %w[ssh_host_rsa_key.pub ssh_host_dsa_key.pub
                        ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub].freeze
        class << self
          private

          def post_resolve(fact_name)
            @fact_list.fetch(fact_name) { retrieve_info(fact_name) }
          end

          def retrieve_info(fact_name)
            ssh_dir = determine_ssh_dir
            return unless ssh_dir && File.directory?(ssh_dir)

            ssh_list = []

            FILE_NAMES.each do |file_name|
              output = Util::FileHelper.safe_read(File.join(ssh_dir, file_name))
              next if output.empty?

              key_type, key = output.split(' ')
              ssh_list << ::Resolvers::Utils::SshHelper.create_ssh(key_type, key)
            end
            @fact_list[:ssh] = ssh_list.empty? ? nil : ssh_list
            @fact_list[fact_name]
          end

          def determine_ssh_dir
            progdata_dir = ENV['programdata']

            return if !progdata_dir || progdata_dir.empty?

            File.join(progdata_dir, 'ssh')
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/windows/ssh.rb
facter-4.0.43 lib/facter/resolvers/windows/ssh.rb
facter-4.0.42 lib/facter/resolvers/windows/ssh.rb
facter-4.0.41 lib/facter/resolvers/windows/ssh.rb
facter-4.0.40 lib/facter/resolvers/windows/ssh.rb
facter-4.0.39 lib/facter/resolvers/windows/ssh.rb
facter-4.0.38 lib/facter/resolvers/windows/ssh.rb
facter-4.0.37 lib/facter/resolvers/windows/ssh.rb