facter 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +1 -1
  3. data/lib/docs/generate.rb +1 -6
  4. data/lib/facter/custom_facts/core/directed_graph.rb +2 -4
  5. data/lib/facter/custom_facts/core/execution/base.rb +1 -1
  6. data/lib/facter/custom_facts/core/execution/posix.rb +6 -2
  7. data/lib/facter/custom_facts/core/execution/windows.rb +4 -1
  8. data/lib/facter/custom_facts/core/execution.rb +1 -1
  9. data/lib/facter/custom_facts/core/file_loader.rb +0 -4
  10. data/lib/facter/custom_facts/core/suitable.rb +1 -1
  11. data/lib/facter/custom_facts/util/collection.rb +2 -4
  12. data/lib/facter/custom_facts/util/confine.rb +4 -1
  13. data/lib/facter/custom_facts/util/fact.rb +1 -1
  14. data/lib/facter/custom_facts/util/loader.rb +2 -2
  15. data/lib/facter/custom_facts/util/resolution.rb +8 -4
  16. data/lib/facter/custom_facts/util/values.rb +1 -1
  17. data/lib/facter/facts/amzn/os/distro/release.rb +6 -1
  18. data/lib/facter/facts/amzn/os/release.rb +5 -0
  19. data/lib/facter/facts/linux/dmi/product/version.rb +19 -0
  20. data/lib/facter/facts/linux/kernelmajversion.rb +1 -1
  21. data/lib/facter/facts/macosx/is_virtual.rb +1 -1
  22. data/lib/facter/facts/macosx/virtual.rb +3 -3
  23. data/lib/facter/facts/mariner/os/release.rb +1 -1
  24. data/lib/facter/facts/photon/os/release.rb +1 -1
  25. data/lib/facter/facts/solaris/kernelmajversion.rb +1 -1
  26. data/lib/facter/facts/solaris/ldom.rb +1 -1
  27. data/lib/facter/facts/windows/hypervisors/kvm.rb +1 -1
  28. data/lib/facter/facts/windows/interfaces.rb +1 -1
  29. data/lib/facter/framework/benchmarking/timer.rb +2 -2
  30. data/lib/facter/framework/cli/cli.rb +6 -8
  31. data/lib/facter/framework/cli/cli_launcher.rb +1 -1
  32. data/lib/facter/framework/config/fact_groups.rb +1 -1
  33. data/lib/facter/framework/core/cache_manager.rb +5 -6
  34. data/lib/facter/framework/core/fact_loaders/class_discoverer.rb +4 -3
  35. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +1 -3
  36. data/lib/facter/framework/core/fact_manager.rb +4 -4
  37. data/lib/facter/framework/core/file_loader.rb +736 -733
  38. data/lib/facter/framework/core/options/config_file_options.rb +4 -6
  39. data/lib/facter/framework/formatters/hocon_fact_formatter.rb +3 -2
  40. data/lib/facter/framework/formatters/legacy_fact_formatter.rb +4 -4
  41. data/lib/facter/framework/logging/logger.rb +6 -6
  42. data/lib/facter/framework/logging/logger_helper.rb +10 -11
  43. data/lib/facter/framework/parsers/query_parser.rb +24 -20
  44. data/lib/facter/resolvers/aix/disks.rb +1 -1
  45. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  46. data/lib/facter/resolvers/aix/networking.rb +1 -1
  47. data/lib/facter/resolvers/aix/partitions.rb +2 -2
  48. data/lib/facter/resolvers/aix/serialnumber.rb +1 -1
  49. data/lib/facter/resolvers/amzn/os_release_rpm.rb +40 -0
  50. data/lib/facter/resolvers/dmi.rb +2 -1
  51. data/lib/facter/resolvers/fips_enabled.rb +1 -1
  52. data/lib/facter/resolvers/freebsd/dmi.rb +1 -1
  53. data/lib/facter/resolvers/freebsd/swap_memory.rb +1 -1
  54. data/lib/facter/resolvers/freebsd/system_memory.rb +15 -7
  55. data/lib/facter/resolvers/freebsd/virtual.rb +1 -1
  56. data/lib/facter/resolvers/linux/hostname.rb +1 -1
  57. data/lib/facter/resolvers/macosx/dmi.rb +1 -1
  58. data/lib/facter/resolvers/macosx/filesystems.rb +1 -1
  59. data/lib/facter/resolvers/memory.rb +1 -1
  60. data/lib/facter/resolvers/networking.rb +3 -3
  61. data/lib/facter/resolvers/os_release.rb +1 -1
  62. data/lib/facter/resolvers/partitions.rb +2 -2
  63. data/lib/facter/resolvers/processors_lscpu.rb +2 -2
  64. data/lib/facter/resolvers/solaris/ffi/ffi.rb +2 -2
  65. data/lib/facter/resolvers/solaris/ffi/functions.rb +2 -2
  66. data/lib/facter/resolvers/solaris/mountpoints.rb +1 -1
  67. data/lib/facter/resolvers/solaris/networking.rb +2 -2
  68. data/lib/facter/resolvers/solaris/os_release.rb +2 -2
  69. data/lib/facter/resolvers/uname.rb +10 -6
  70. data/lib/facter/resolvers/virt_what.rb +2 -1
  71. data/lib/facter/resolvers/windows/memory.rb +3 -2
  72. data/lib/facter/resolvers/windows/product_release.rb +7 -7
  73. data/lib/facter/resolvers/xen.rb +3 -1
  74. data/lib/facter/util/aix/info_extractor.rb +1 -1
  75. data/lib/facter/util/aix/odm_query.rb +1 -1
  76. data/lib/facter/util/api_debugger.rb +2 -2
  77. data/lib/facter/util/facts/facts_utils.rb +2 -1
  78. data/lib/facter/util/facts/posix/virtual_detector.rb +8 -5
  79. data/lib/facter/util/facts/unit_converter.rb +2 -2
  80. data/lib/facter/util/file_helper.rb +1 -2
  81. data/lib/facter/util/macosx/system_profile_executor.rb +3 -3
  82. data/lib/facter/util/resolvers/fingerprint.rb +1 -7
  83. data/lib/facter/util/resolvers/networking/networking.rb +4 -3
  84. data/lib/facter/util/resolvers/networking/primary_interface.rb +2 -0
  85. data/lib/facter/util/resolvers/ssh.rb +1 -9
  86. data/lib/facter/util/resolvers/ssh_helper.rb +2 -0
  87. data/lib/facter/util/utils.rb +2 -2
  88. data/lib/facter/version.rb +1 -1
  89. data/lib/facter.rb +7 -0
  90. metadata +11 -9
@@ -30,7 +30,8 @@ module Facter
30
30
  xen_info = xen_info.to_s
31
31
  return 'xenu' if /xen-domu/.match?(xen_info)
32
32
  return 'xenhvm' if /xen-hvm/.match?(xen_info)
33
- return 'xen0' if /xen-dom0/.match?(xen_info)
33
+
34
+ 'xen0' if /xen-dom0/.match?(xen_info)
34
35
  end
35
36
 
36
37
  def determine_other(output)
@@ -58,8 +58,9 @@ module Facter
58
58
  @fact_list[:total_bytes] = result[:total_bytes]
59
59
  @fact_list[:available_bytes] = result[:available_bytes]
60
60
  @fact_list[:used_bytes] = result[:used_bytes]
61
- @fact_list[:capacity] = format('%<capacity>.2f',
62
- capacity: (result[:used_bytes] / result[:total_bytes].to_f * 100)) + '%'
61
+ @fact_list[:capacity] = format(
62
+ '%<capacity>.2f%%', capacity: (result[:used_bytes] / result[:total_bytes].to_f * 100)
63
+ )
63
64
  end
64
65
  end
65
66
  end
@@ -23,19 +23,19 @@ module Facter
23
23
  end
24
24
 
25
25
  def build_fact_list(reg)
26
- reg.each do |name, _value|
26
+ reg.each do |name, value|
27
27
  case name
28
28
  when 'EditionID'
29
- @fact_list[:edition_id] = reg[name]
29
+ @fact_list[:edition_id] = value
30
30
  when 'InstallationType'
31
- @fact_list[:installation_type] = reg[name]
31
+ @fact_list[:installation_type] = value
32
32
  when 'ProductName'
33
- @fact_list[:product_name] = reg[name]
33
+ @fact_list[:product_name] = value
34
34
  when 'DisplayVersion'
35
- @fact_list[:release_id] = reg[name]
36
- @fact_list[:display_version] = reg[name]
35
+ @fact_list[:release_id] = value
36
+ @fact_list[:display_version] = value
37
37
  when 'ReleaseId'
38
- @fact_list[:release_id] = reg[name] unless @fact_list[:release_id]
38
+ @fact_list[:release_id] = value unless @fact_list[:release_id]
39
39
  end
40
40
  end
41
41
  end
@@ -26,7 +26,9 @@ module Facter
26
26
 
27
27
  def detect_xen_type
28
28
  xen_type = 'xen0' if File.exist?('/dev/xen/evtchn')
29
- xen_type = 'xenu' if !xen_type && (File.exist?('/proc/xen') || File.exist?('/dev/xvda1'))
29
+ if !xen_type && (File.exist?('/proc/xen') || (File.exist?('/dev/xvda1') && !File.symlink?('/dev/xvda1')))
30
+ xen_type = 'xenu'
31
+ end
30
32
 
31
33
  xen_type
32
34
  end
@@ -61,7 +61,7 @@ module Facter
61
61
  properties = PROPERTIES[cmd]
62
62
  properties.each do |property|
63
63
  str = (properties - [property]).join('|')
64
- matcher = content.match(/#{Regexp.escape(property)}([^\n]*?)(#{str}|\n|$)/s)
64
+ matcher = content.match(/(?:^|^[^:]+:[^:]+)#{Regexp.escape(property)}([^\n]*?)(#{str}|\n|$)/s)
65
65
  if matcher
66
66
  value = matcher[1].strip
67
67
  property_hash[property.split(':').first] = value
@@ -38,7 +38,7 @@ module Facter
38
38
  end
39
39
 
40
40
  def query
41
- 'odmget -q "' + @conditions.join(' AND ') + '"'
41
+ "odmget -q \"#{@conditions.join(' AND ')}\""
42
42
  end
43
43
  end
44
44
  end
@@ -34,9 +34,9 @@ module Facter
34
34
 
35
35
  options.split(',').each do |option|
36
36
  if option.start_with?('-')
37
- exclude << option[1..-1].to_sym
37
+ exclude << option[1..].to_sym
38
38
  elsif option.start_with?('+')
39
- print_caller << option[1..-1].to_sym
39
+ print_caller << option[1..].to_sym
40
40
  end
41
41
  end
42
42
 
@@ -25,7 +25,7 @@ module Facter
25
25
  os
26
26
  end
27
27
 
28
- def release_hash_from_string(output)
28
+ def release_hash_from_string(output, include_patch: false)
29
29
  return unless output
30
30
 
31
31
  versions = output.split('.')
@@ -33,6 +33,7 @@ module Facter
33
33
  release['full'] = output
34
34
  release['major'] = versions[0]
35
35
  release['minor'] = versions[1] if versions[1]
36
+ release['patch'] = versions[2] if versions[2] && include_patch
36
37
  end
37
38
  end
38
39
 
@@ -7,11 +7,10 @@ module Facter
7
7
  module VirtualDetector
8
8
  class << self
9
9
  def platform
10
- @@fact_value ||= check_docker_lxc || check_freebsd || check_gce || retrieve_from_virt_what
11
- @@fact_value ||= check_vmware || check_open_vz || check_vserver || check_xen || check_other_facts
12
- @@fact_value ||= check_lspci || 'physical'
13
-
14
- @@fact_value
10
+ @fact_value ||= # rubocop:disable Naming/MemoizedInstanceVariableName
11
+ check_docker_lxc || check_freebsd || check_gce || check_illumos_lx || \
12
+ retrieve_from_virt_what || check_vmware || check_open_vz || check_vserver || \
13
+ check_xen || check_other_facts || check_lspci || 'physical'
15
14
  end
16
15
 
17
16
  private
@@ -25,6 +24,10 @@ module Facter
25
24
  'gce' if bios_vendor&.include?('Google')
26
25
  end
27
26
 
27
+ def check_illumos_lx
28
+ 'illumos-lx' if Facter::Resolvers::Uname.resolve(:kernelversion) == 'BrandZ virtual linux'
29
+ end
30
+
28
31
  def check_vmware
29
32
  Facter::Resolvers::Vmware.resolve(:vm)
30
33
  end
@@ -19,12 +19,12 @@ module Facter
19
19
 
20
20
  validated_speed, metric_prefix = determine_metric_prefix(speed)
21
21
 
22
- format('%<displayed_speed>.2f', displayed_speed: validated_speed.round(2)).to_s + ' ' + metric_prefix + 'Hz'
22
+ "#{format('%<displayed_speed>.2f', displayed_speed: validated_speed.round(2))} #{metric_prefix}Hz"
23
23
  end
24
24
 
25
25
  def bytes_to_human_readable(bytes)
26
26
  return unless bytes
27
- return bytes.to_s + ' bytes' if bytes < 1024
27
+ return "#{bytes} bytes" if bytes < 1024
28
28
 
29
29
  number, multiple = determine_exponent(bytes)
30
30
 
@@ -27,8 +27,7 @@ module Facter
27
27
  # method, we can't remove it entirely until the next major Facter
28
28
  # release (presumably Facter 5).
29
29
  def dir_children(path)
30
- children = Dir.children(path)
31
- children
30
+ Dir.children(path)
32
31
  end
33
32
 
34
33
  private
@@ -23,12 +23,12 @@ module Facter
23
23
  private
24
24
 
25
25
  def output_to_hash(output)
26
- output.scan(/.*:[ ].*$/).map { |e| e.strip.match(/(.*?): (.*)/).captures }.to_h
26
+ output.scan(/.*: .*$/).map { |e| e.strip.match(/(.*?): (.*)/).captures }.to_h
27
27
  end
28
28
 
29
29
  def normalize_keys(system_profiler_hash)
30
- system_profiler_hash.map do |k, v|
31
- [k.downcase.tr(' ', '_').delete("\(\)").to_sym, v]
30
+ system_profiler_hash.transform_keys do |k|
31
+ k.downcase.tr(' ', '_').delete("\(\)").to_sym
32
32
  end.to_h
33
33
  end
34
34
  end
@@ -3,13 +3,7 @@
3
3
  module Facter
4
4
  module Util
5
5
  module Resolvers
6
- class FingerPrint
7
- attr_accessor :sha1, :sha256
8
- def initialize(sha1, sha256)
9
- @sha1 = sha1
10
- @sha256 = sha256
11
- end
12
- end
6
+ FingerPrint = Struct.new(:sha1, :sha256)
13
7
  end
14
8
  end
15
9
  end
@@ -54,7 +54,8 @@ module Facter
54
54
  'site'
55
55
  elsif addrinfo.ipv6_loopback?
56
56
  'host'
57
- else 'global'
57
+ else
58
+ 'global'
58
59
  end
59
60
  scope6.join
60
61
  end
@@ -102,7 +103,7 @@ module Facter
102
103
  def expand_interfaces(interfaces)
103
104
  interfaces.each_value do |values|
104
105
  expand_binding(values, values[:bindings]) if values[:bindings]
105
- expand_binding(values, values[:bindings6], false) if values[:bindings6]
106
+ expand_binding(values, values[:bindings6], ipv4_type: false) if values[:bindings6]
106
107
  end
107
108
  end
108
109
 
@@ -112,7 +113,7 @@ module Facter
112
113
  end
113
114
  end
114
115
 
115
- def expand_binding(values, bindings, ipv4_type = true)
116
+ def expand_binding(values, bindings, ipv4_type: true)
116
117
  binding = find_valid_binding(bindings)
117
118
  ip_protocol_type = ipv4_type ? '' : '6'
118
119
 
@@ -57,6 +57,8 @@ module Facter
57
57
  end
58
58
 
59
59
  def find_in_interfaces(interfaces)
60
+ return if interfaces.nil?
61
+
60
62
  interfaces.each do |iface_name, interface|
61
63
  interface[:bindings]&.each do |binding|
62
64
  return iface_name unless Facter::Util::Resolvers::Networking.ignored_ip_address(binding[:address])
@@ -3,15 +3,7 @@
3
3
  module Facter
4
4
  module Util
5
5
  module Resolvers
6
- class Ssh
7
- attr_accessor :fingerprint, :type, :key, :name
8
- def initialize(fingerprint, type, key, name)
9
- @fingerprint = fingerprint
10
- @type = type
11
- @key = key
12
- @name = name
13
- end
14
- end
6
+ Ssh = Struct.new(:fingerprint, :type, :key, :name)
15
7
  end
16
8
  end
17
9
  end
@@ -9,6 +9,7 @@ module Facter
9
9
  class SshHelper
10
10
  class << self
11
11
  SSH_NAME = { 'ssh-dss' => 'dsa', 'ecdsa-sha2-nistp256' => 'ecdsa',
12
+ 'ecdsa-sha2-nistp384' => 'ecdsa', 'ecdsa-sha2-nistp521' => 'ecdsa',
12
13
  'ssh-ed25519' => 'ed25519', 'ssh-rsa' => 'rsa' }.freeze
13
14
  SSH_FINGERPRINT = { 'rsa' => 1, 'dsa' => 2, 'ecdsa' => 3, 'ed25519' => 4 }.freeze
14
15
 
@@ -16,6 +17,7 @@ module Facter
16
17
  key_name = SSH_NAME[key_type]
17
18
  return unless key_name
18
19
 
20
+ # decode64 ignores non-base64 characters including newlines
19
21
  decoded_key = Base64.decode64(key)
20
22
  ssh_fp = SSH_FINGERPRINT[key_name]
21
23
  sha1 = "SSHFP #{ssh_fp} 1 #{Digest::SHA1.new.update(decoded_key)}"
@@ -3,10 +3,10 @@
3
3
  module Facter
4
4
  module Utils
5
5
  # Sort nested hash.
6
- def self.sort_hash_by_key(hash, recursive = true, &block)
6
+ def self.sort_hash_by_key(hash, recursive: true, &block)
7
7
  hash.keys.sort(&block).each_with_object(hash.class.new) do |key, seed|
8
8
  seed[key] = hash[key]
9
- seed[key] = sort_hash_by_key(seed[key], true, &block) if recursive && seed[key].is_a?(Hash)
9
+ seed[key] = sort_hash_by_key(seed[key], recursive: true, &block) if recursive && seed[key].is_a?(Hash)
10
10
 
11
11
  seed
12
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.5.1' unless defined?(VERSION)
4
+ VERSION = '4.6.0' unless defined?(VERSION)
5
5
  end
data/lib/facter.rb CHANGED
@@ -653,6 +653,13 @@ module Facter
653
653
  nil
654
654
  end
655
655
 
656
+ # We don't respond to any missing methods
657
+ #
658
+ # @api private
659
+ def respond_to_missing?(_method, *)
660
+ false
661
+ end
662
+
656
663
  prepend ApiDebugger if ENV['API_DEBUG']
657
664
  end
658
665
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.1
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -64,42 +64,42 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.81.0
67
+ version: '1.50'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.81.0
74
+ version: '1.50'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rubocop-performance
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 1.5.2
81
+ version: '1.17'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 1.5.2
88
+ version: '1.17'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rubocop-rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.38'
95
+ version: '2.20'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.38'
102
+ version: '2.20'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -444,6 +444,7 @@ files:
444
444
  - lib/facter/facts/linux/dmi/product/name.rb
445
445
  - lib/facter/facts/linux/dmi/product/serial_number.rb
446
446
  - lib/facter/facts/linux/dmi/product/uuid.rb
447
+ - lib/facter/facts/linux/dmi/product/version.rb
447
448
  - lib/facter/facts/linux/ec2_metadata.rb
448
449
  - lib/facter/facts/linux/ec2_userdata.rb
449
450
  - lib/facter/facts/linux/facterversion.rb
@@ -934,6 +935,7 @@ files:
934
935
  - lib/facter/resolvers/aix/partitions.rb
935
936
  - lib/facter/resolvers/aix/processors.rb
936
937
  - lib/facter/resolvers/aix/serialnumber.rb
938
+ - lib/facter/resolvers/amzn/os_release_rpm.rb
937
939
  - lib/facter/resolvers/augeas.rb
938
940
  - lib/facter/resolvers/az.rb
939
941
  - lib/facter/resolvers/base_resolver.rb
@@ -1091,7 +1093,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1091
1093
  requirements:
1092
1094
  - - ">="
1093
1095
  - !ruby/object:Gem::Version
1094
- version: '2.5'
1096
+ version: '2.6'
1095
1097
  - - "<"
1096
1098
  - !ruby/object:Gem::Version
1097
1099
  version: '4.0'