facter 4.7.0 → 4.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/facter/custom_facts/core/aggregate.rb +5 -1
  3. data/lib/facter/custom_facts/util/confine.rb +4 -2
  4. data/lib/facter/framework/logging/logger.rb +3 -2
  5. data/lib/facter/resolvers/az.rb +1 -1
  6. data/lib/facter/resolvers/base_resolver.rb +3 -2
  7. data/lib/facter/resolvers/bsd/processors.rb +0 -1
  8. data/lib/facter/resolvers/disks.rb +0 -2
  9. data/lib/facter/resolvers/dmi.rb +0 -2
  10. data/lib/facter/resolvers/ec2.rb +1 -1
  11. data/lib/facter/resolvers/filesystems.rb +0 -2
  12. data/lib/facter/resolvers/fips_enabled.rb +0 -2
  13. data/lib/facter/resolvers/freebsd/processors.rb +0 -1
  14. data/lib/facter/resolvers/gce.rb +1 -1
  15. data/lib/facter/resolvers/hostname.rb +5 -0
  16. data/lib/facter/resolvers/identity.rb +0 -2
  17. data/lib/facter/resolvers/macosx/mountpoints.rb +0 -2
  18. data/lib/facter/resolvers/memory.rb +0 -2
  19. data/lib/facter/resolvers/mountpoints.rb +0 -2
  20. data/lib/facter/resolvers/processors.rb +0 -2
  21. data/lib/facter/resolvers/solaris/mountpoints.rb +0 -2
  22. data/lib/facter/resolvers/solaris/networking.rb +0 -1
  23. data/lib/facter/resolvers/ssh.rb +0 -2
  24. data/lib/facter/resolvers/windows/dmi_bios.rb +0 -1
  25. data/lib/facter/resolvers/windows/dmi_computersystem.rb +0 -1
  26. data/lib/facter/resolvers/windows/hardware_architecture.rb +0 -1
  27. data/lib/facter/resolvers/windows/identity.rb +0 -1
  28. data/lib/facter/resolvers/windows/kernel.rb +0 -2
  29. data/lib/facter/resolvers/windows/memory.rb +0 -2
  30. data/lib/facter/resolvers/windows/networking.rb +0 -1
  31. data/lib/facter/resolvers/windows/ssh.rb +0 -2
  32. data/lib/facter/resolvers/windows/system32.rb +0 -2
  33. data/lib/facter/resolvers/windows/timezone.rb +0 -1
  34. data/lib/facter/resolvers/windows/uptime.rb +0 -2
  35. data/lib/facter/resolvers/windows/virtualization.rb +9 -4
  36. data/lib/facter/resolvers/windows/win_os_description.rb +0 -2
  37. data/lib/facter/resolvers/xen.rb +2 -0
  38. data/lib/facter/templates/man.erb +5 -2
  39. data/lib/facter/util/resolvers/http.rb +31 -20
  40. data/lib/facter/version.rb +1 -1
  41. metadata +28 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 101e10975c853baea839c1f0b5afc9d409f85df720a581d2987cf61cb50101af
4
- data.tar.gz: 828a50d3cf221d2bec58e90400684d25c9adff0b3fe93c39535e1136dc628e34
3
+ metadata.gz: 512cdd220f22069dbf686592dfc08d3b4ecccf97702313117b333d5e568ebe8e
4
+ data.tar.gz: 373406fac7fe5ec363b13e6afa26acabfb6bb62716d9f0b977b1f2e768e6381d
5
5
  SHA512:
6
- metadata.gz: 4d367e6d5b5b248767d77464e02f99951219bdd99108990fb2b4af0724c769f9dba18073e382ba244b81413d486547a284ae949779f31a2a0a5299d1b7a448cf
7
- data.tar.gz: af8d6958c1cc05eb883fc5479c863c6613fb49737ea38c251cb7facd3c05ab6c57990334f419604b3102a05736182756daed55492c5644c849c3f71e1d7acd76
6
+ metadata.gz: ed2f2ac6dcec58364ba37df4acee50fb44f90f46f6de28f8f2524aa89d8d5634e7499be547234e65e4930126e59652b0d6b56f2d602e74598227d7808c504bf7
7
+ data.tar.gz: ef408018f71cd5884a56cf0dc3aab243fe119978e45c99e4b8069242d4ecf27011a3c106b53f12960665729bc0209aee452a02138e6642749f2c2b51e46a67bc
@@ -109,7 +109,7 @@ module Facter
109
109
  # @api private
110
110
  def evaluate(&block)
111
111
  if @last_evaluated
112
- msg = "Already evaluated #{@name}"
112
+ msg = +"Already evaluated #{@name}"
113
113
  msg << " at #{@last_evaluated}" if msg.is_a? String
114
114
  msg << ', reevaluating anyways'
115
115
  log.warn msg
@@ -197,6 +197,10 @@ module Facter
197
197
 
198
198
  private
199
199
 
200
+ def log
201
+ @log ||= Facter::Log.new(self)
202
+ end
203
+
200
204
  def evaluate_params(name)
201
205
  raise ArgumentError, "#{self.class.name}#chunk requires a block" unless block_given?
202
206
  raise ArgumentError, "#{self.class.name}#expected chunk name to be a Symbol" unless name.is_a? Symbol
@@ -35,7 +35,7 @@ module LegacyFacter
35
35
  end
36
36
 
37
37
  # Evaluate the fact, returning true or false.
38
- # if we have a block paramter then we only evaluate that instead
38
+ # if we have a block parameter then we only evaluate that instead
39
39
  def true?
40
40
  if @block && !@fact
41
41
  begin
@@ -54,9 +54,11 @@ module LegacyFacter
54
54
 
55
55
  return false if value.nil?
56
56
 
57
+ # We call the block with both the downcased and raw fact value for
58
+ # backwards-compatibility.
57
59
  if @block
58
60
  begin
59
- return !!@block.call(value)
61
+ return !!@block.call(value) || !!@block.call(fact.value) # rubocop:disable Style/DoubleNegation
60
62
  rescue StandardError => e
61
63
  log.debug "Confine raised #{e.class} #{e}"
62
64
  return false
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'logger'
4
+ require 'set'
4
5
 
5
6
  module Facter
6
7
  RED = "\e[31m"
@@ -15,8 +16,8 @@ module Facter
15
16
  @@logger = nil
16
17
  @@message_callback = nil
17
18
  @@has_errors = false
18
- @@debug_messages = []
19
- @@warn_messages = []
19
+ @@debug_messages = Set.new
20
+ @@warn_messages = Set.new
20
21
  @@timing = false
21
22
 
22
23
  class << self
@@ -26,7 +26,7 @@ module Facter
26
26
 
27
27
  def get_data_from(url)
28
28
  headers = { Metadata: 'true' }
29
- Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout })
29
+ Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout }, false)
30
30
  end
31
31
 
32
32
  def determine_session_timeout
@@ -3,8 +3,8 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class BaseResolver
6
- def self.log
7
- @log ||= Log.new(self)
6
+ class << self
7
+ attr_reader :log
8
8
  end
9
9
 
10
10
  def self.invalidate_cache
@@ -14,6 +14,7 @@ module Facter
14
14
  def self.init_resolver
15
15
  @fact_list = {}
16
16
  @semaphore = Mutex.new
17
+ @log = Log.new(self)
17
18
  end
18
19
 
19
20
  def self.subscribe_to_manager
@@ -5,7 +5,6 @@ module Facter
5
5
  module Bsd
6
6
  class Processors < BaseResolver
7
7
  init_resolver
8
- @log = Facter::Log.new(self)
9
8
 
10
9
  class << self
11
10
  private
@@ -4,8 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  module Linux
6
6
  class Disks < BaseResolver
7
- @log = Facter::Log.new(self)
8
-
9
7
  init_resolver
10
8
 
11
9
  DIR = '/sys/block'
@@ -4,8 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  module Linux
6
6
  class DmiBios < BaseResolver
7
- @log = Facter::Log.new(self)
8
-
9
7
  init_resolver
10
8
 
11
9
  class << self
@@ -52,7 +52,7 @@ module Facter
52
52
  def get_data_from(url)
53
53
  headers = {}
54
54
  headers['X-aws-ec2-metadata-token'] = v2_token if v2_token
55
- Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout })
55
+ Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout }, false)
56
56
  end
57
57
 
58
58
  def determine_session_timeout
@@ -8,8 +8,6 @@ module Facter
8
8
 
9
9
  init_resolver
10
10
 
11
- @log = Facter::Log.new(self)
12
-
13
11
  class << self
14
12
  private
15
13
 
@@ -8,8 +8,6 @@ module Facter
8
8
 
9
9
  init_resolver
10
10
 
11
- @log = Facter::Log.new(self)
12
-
13
11
  class << self
14
12
  private
15
13
 
@@ -7,7 +7,6 @@ module Facter
7
7
  module Freebsd
8
8
  class Processors < BaseResolver
9
9
  init_resolver
10
- @log = Facter::Log.new(self)
11
10
 
12
11
  class << self
13
12
  private
@@ -22,7 +22,7 @@ module Facter
22
22
  end
23
23
 
24
24
  def query_for_metadata
25
- gce_data = extract_to_hash(Facter::Util::Resolvers::Http.get_request(METADATA_URL, HEADERS))
25
+ gce_data = extract_to_hash(Facter::Util::Resolvers::Http.get_request(METADATA_URL, HEADERS, false))
26
26
  parse_instance(gce_data)
27
27
 
28
28
  gce_data.empty? ? nil : gce_data
@@ -19,6 +19,11 @@ module Facter
19
19
  def retrieve_info(fact_name)
20
20
  require 'socket'
21
21
  output = Socket.gethostname
22
+ unless output
23
+ log.debug('Socket.gethostname failed to return hostname')
24
+ return
25
+ end
26
+
22
27
  hostname, domain = retrieve_from_fqdn(output)
23
28
 
24
29
  fqdn = retrieve_with_addrinfo(hostname) if hostname_and_no_domain?(hostname, domain)
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class PosxIdentity < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  class << self
@@ -7,8 +7,6 @@ module Facter
7
7
  include Facter::Util::Resolvers::FilesystemHelper
8
8
  init_resolver
9
9
 
10
- @log = Facter::Log.new(self)
11
-
12
10
  class << self
13
11
  private
14
12
 
@@ -6,8 +6,6 @@ module Facter
6
6
  class Memory < BaseResolver
7
7
  init_resolver
8
8
 
9
- @log = Facter::Log.new(self)
10
-
11
9
  class << self
12
10
  private
13
11
 
@@ -7,8 +7,6 @@ module Facter
7
7
 
8
8
  init_resolver
9
9
 
10
- @log = Facter::Log.new(self)
11
-
12
10
  class << self
13
11
  private
14
12
 
@@ -4,8 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  module Linux
6
6
  class Processors < BaseResolver
7
- @log = Facter::Log.new(self)
8
-
9
7
  init_resolver
10
8
 
11
9
  MHZ_TO_HZ = 1_000_000
@@ -7,8 +7,6 @@ module Facter
7
7
  include Facter::Util::Resolvers::FilesystemHelper
8
8
  init_resolver
9
9
 
10
- @log = Facter::Log.new(self)
11
-
12
10
  class << self
13
11
  private
14
12
 
@@ -6,7 +6,6 @@ module Facter
6
6
  module Solaris
7
7
  class Networking < BaseResolver
8
8
  init_resolver
9
- @log = Facter::Log.new(self)
10
9
 
11
10
  class << self
12
11
  private
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class Ssh < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  FILE_NAMES = %w[ssh_host_rsa_key.pub ssh_host_dsa_key.pub ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub].freeze
@@ -3,7 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class DMIBios < BaseResolver
6
- @log = Facter::Log.new(self)
7
6
  init_resolver
8
7
 
9
8
  class << self
@@ -3,7 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class DMIComputerSystem < BaseResolver
6
- @log = Facter::Log.new(self)
7
6
  init_resolver
8
7
 
9
8
  class << self
@@ -24,7 +24,6 @@ module Facter
24
24
  build_facts_list(hardware: hard, architecture: arch)
25
25
  @fact_list[fact_name]
26
26
  rescue LoadError => e
27
- log = Facter::Log.new(self)
28
27
  log.debug("The ffi gem has not been installed: #{e}")
29
28
  end
30
29
 
@@ -4,7 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  class Identity < BaseResolver
6
6
  NAME_SAM_COMPATIBLE = 2
7
- @log = Facter::Log.new(self)
8
7
 
9
8
  init_resolver
10
9
 
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class Kernel < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  class << self
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class Memory < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  class << self
@@ -4,7 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  module Windows
6
6
  class Networking < BaseResolver
7
- @log = Facter::Log.new(self)
8
7
  init_resolver
9
8
 
10
9
  class << self
@@ -4,8 +4,6 @@ module Facter
4
4
  module Resolvers
5
5
  module Windows
6
6
  class Ssh < BaseResolver
7
- @log = Facter::Log.new(self)
8
-
9
7
  init_resolver
10
8
 
11
9
  FILE_NAMES = %w[ssh_host_rsa_key.pub ssh_host_dsa_key.pub
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class System32 < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  class << self
@@ -34,7 +34,6 @@ module Facter
34
34
  require_relative '../../../facter/resolvers/windows/ffi/winnls_ffi'
35
35
  WinnlsFFI.GetACP.to_s
36
36
  rescue LoadError => e
37
- log = Facter::Log.new(self)
38
37
  log.debug("Could not retrieve codepage: #{e}")
39
38
  end
40
39
  end
@@ -6,8 +6,6 @@ module Facter
6
6
  module Resolvers
7
7
  module Windows
8
8
  class Uptime < BaseResolver
9
- @log = Facter::Log.new(self)
10
-
11
9
  init_resolver
12
10
 
13
11
  class << self
@@ -4,16 +4,21 @@ module Facter
4
4
  module Resolvers
5
5
  module Windows
6
6
  class Virtualization < BaseResolver
7
- @log = Facter::Log.new(self)
8
-
9
7
  init_resolver
10
8
 
11
9
  class << self
12
10
  # Virtual
13
11
  # Is_Virtual
14
12
 
15
- MODEL_HASH = { 'VirtualBox' => 'virtualbox', 'VMware' => 'vmware', 'KVM' => 'kvm',
16
- 'Bochs' => 'bochs', 'Google' => 'gce', 'OpenStack' => 'openstack' }.freeze
13
+ MODEL_HASH = {
14
+ 'VirtualBox' => 'virtualbox',
15
+ 'VMware' => 'vmware',
16
+ 'KVM' => 'kvm',
17
+ 'Bochs' => 'bochs',
18
+ 'Google' => 'gce',
19
+ 'OpenStack' => 'openstack',
20
+ 'AHV' => 'ahv'
21
+ }.freeze
17
22
 
18
23
  private
19
24
 
@@ -3,8 +3,6 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class WinOsDescription < BaseResolver
6
- @log = Facter::Log.new(self)
7
-
8
6
  init_resolver
9
7
 
10
8
  class << self
@@ -66,6 +66,8 @@ module Facter
66
66
  return XEN_TOOLSTACK if num_stacks > 1 && File.exist?(XEN_TOOLSTACK)
67
67
 
68
68
  XEN_COMMANDS.each { |command| return command if File.exist?(command) }
69
+
70
+ nil
69
71
  end
70
72
  end
71
73
  end
@@ -1,11 +1,14 @@
1
1
  <%# encoding: UTF-8%>
2
+ facter - collect and display facts about the current system
3
+ ===========================================================
4
+
2
5
  SYNOPSIS
3
6
  --------
4
- facter [options] [query] [query] [...]
7
+ <b>facter</b> [options] [query] [query] [...]
5
8
 
6
9
  DESCRIPTION
7
10
  -----------
8
- Collect and display facts about the current system. The library behind Facter is easy to extend, making Facter an easy way to collect information about a system.
11
+ <b>facter</b> is a command-line tool that gathers basic facts about nodes (systems) such as hardware details, network settings, OS type and version, and more. These facts are made available as variables in your Puppet manifests and can be used to inform conditional expressions in Puppet.
9
12
 
10
13
  If no queries are given, then all facts will be returned.
11
14
 
@@ -10,34 +10,37 @@ module Facter
10
10
  CONNECTION_TIMEOUT = 0.6
11
11
  SESSION_TIMEOUT = 5
12
12
 
13
- # Makes a GET http request and returns its response.
13
+ # Makes a GET HTTP request and returns its response.
14
14
  #
15
- # Params:
16
- # url: String which contains the address to which the request will be made
17
- # headers: Hash which contains the headers you need to add to your request.
18
- # Default headers is an empty hash
19
- # Example: { "Accept": 'application/json' }
20
- # timeouts: Hash that includes the values for the session and connection timeouts.
21
- # Example: { session: 2.4. connection: 5 }
22
- #
23
- # Return value:
24
- # is a string with the response body if the response code is 200.
25
- # If the response code is not 200, an empty string is returned.
26
- def get_request(url, headers = {}, timeouts = {})
27
- make_request(url, headers, timeouts, 'GET')
15
+ # @param url [String] the address to which the request will be made.
16
+ # @param headers [Hash] the headers you need to add to your request.
17
+ # Defaults to an empty hash.
18
+ # @param timeouts [Hash] Values for the session and connection
19
+ # timeouts.
20
+ # @param proxy [Boolean] Whether to use proxy settings when calling
21
+ # Net::HTTP.new. Defaults to true.
22
+ # @returns [String] the response body if the response code is 200.
23
+ # If the response code is not 200, an empty string is returned.
24
+ # @example
25
+ # get_request('https://example.com', { "Accept": 'application/json' }, { session: 2.4, connection: 5 })
26
+ def get_request(url, headers = {}, timeouts = {}, proxy = true)
27
+ make_request(url, headers, timeouts, 'GET', proxy)
28
28
  end
29
29
 
30
- def put_request(url, headers = {}, timeouts = {})
31
- make_request(url, headers, timeouts, 'PUT')
30
+ # Makes a PUT HTTP request and returns its response
31
+ # @param (see #get_request)
32
+ # @return (see #get_request)
33
+ def put_request(url, headers = {}, timeouts = {}, proxy = true)
34
+ make_request(url, headers, timeouts, 'PUT', proxy)
32
35
  end
33
36
 
34
37
  private
35
38
 
36
- def make_request(url, headers, timeouts, request_type)
39
+ def make_request(url, headers, timeouts, request_type, proxy)
37
40
  require 'net/http'
38
41
 
39
42
  uri = URI.parse(url)
40
- http = http_obj(uri, timeouts)
43
+ http = http_obj(uri, timeouts, proxy)
41
44
  request = request_obj(headers, uri, request_type)
42
45
 
43
46
  # The Windows implementation of sockets does not respect net/http
@@ -56,8 +59,16 @@ module Facter
56
59
  ''
57
60
  end
58
61
 
59
- def http_obj(parsed_url, timeouts)
60
- http = Net::HTTP.new(parsed_url.host)
62
+ def http_obj(parsed_url, timeouts, proxy)
63
+ # If get_request or put_request are called and set proxy to false,
64
+ # manually set Net::HTTP.new's p_addr (proxy address) positional
65
+ # argument to nil to override anywhere else a proxy may be set
66
+ # (e.g. the http_proxy environment variable).
67
+ http = if proxy
68
+ Net::HTTP.new(parsed_url.host)
69
+ else
70
+ Net::HTTP.new(parsed_url.host, 80, nil)
71
+ end
61
72
  http.read_timeout = timeouts[:session] || SESSION_TIMEOUT
62
73
  http.open_timeout = timeouts[:connection] || CONNECTION_TIMEOUT
63
74
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.7.0' unless defined?(VERSION)
4
+ VERSION = '4.7.1' unless defined?(VERSION)
5
5
  end
metadata CHANGED
@@ -1,29 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-09 00:00:00.000000000 Z
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.15.5
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.17.0
23
+ - - "!="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.16.0
26
+ - - "!="
27
+ - !ruby/object:Gem::Version
28
+ version: 1.16.1
29
+ - - "!="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.16.2
20
32
  type: :development
21
33
  prerelease: false
22
34
  version_requirements: !ruby/object:Gem::Requirement
23
35
  requirements:
24
- - - '='
36
+ - - ">="
25
37
  - !ruby/object:Gem::Version
26
38
  version: 1.15.5
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.17.0
42
+ - - "!="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.16.0
45
+ - - "!="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.16.1
48
+ - - "!="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.16.2
27
51
  - !ruby/object:Gem::Dependency
28
52
  name: rake
29
53
  requirement: !ruby/object:Gem::Requirement