Sha256: d2c0dc834e1b1d114a9d21ac29ef9ac2d8f4bed77a0ee9c353f8014b44a5b2f0

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class SshResolver < 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
      FILE_PATHS = %w[/etc/ssh /usr/local/etc/ssh /etc /usr/local/etc /etc/opt/ssh].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_list = []
          FILE_PATHS.each do |file_path|
            next unless File.directory?(file_path)

            FILE_NAMES.each do |file_name|
              file_content = Util::FileHelper.safe_read(File.join(file_path, file_name), nil)
              next unless file_content

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/ssh_resolver.rb