openfact 5.7.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate.rb +1 -5
  3. data/lib/docs/template.erb +1 -1
  4. data/lib/facter/custom_facts/core/aggregate.rb +2 -4
  5. data/lib/facter/custom_facts/core/execution/base.rb +10 -6
  6. data/lib/facter/custom_facts/core/execution/posix.rb +5 -5
  7. data/lib/facter/custom_facts/core/execution/windows.rb +5 -5
  8. data/lib/facter/custom_facts/core/execution.rb +3 -1
  9. data/lib/facter/custom_facts/core/resolvable.rb +4 -6
  10. data/lib/facter/custom_facts/util/collection.rb +0 -2
  11. data/lib/facter/custom_facts/util/config.rb +1 -1
  12. data/lib/facter/custom_facts/util/directory_loader.rb +3 -7
  13. data/lib/facter/custom_facts/util/fact.rb +2 -21
  14. data/lib/facter/custom_facts/util/parser.rb +5 -5
  15. data/lib/facter/custom_facts/util/resolution.rb +15 -8
  16. data/lib/facter/facts/aix/networking/interfaces.rb +1 -1
  17. data/lib/facter/facts/freebsd/ec2_metadata.rb +1 -1
  18. data/lib/facter/facts/freebsd/ec2_userdata.rb +1 -1
  19. data/lib/facter/facts/linux/az_metadata.rb +1 -1
  20. data/lib/facter/facts/linux/dhcp_servers.rb +1 -1
  21. data/lib/facter/facts/linux/ec2_metadata.rb +1 -1
  22. data/lib/facter/facts/linux/ec2_userdata.rb +1 -1
  23. data/lib/facter/facts/macosx/dhcp_servers.rb +1 -1
  24. data/lib/facter/facts/openbsd/ec2_metadata.rb +1 -1
  25. data/lib/facter/facts/openbsd/ec2_userdata.rb +1 -1
  26. data/lib/facter/facts/solaris/dhcp_servers.rb +1 -1
  27. data/lib/facter/facts/windows/az_metadata.rb +1 -1
  28. data/lib/facter/facts/windows/dhcp_servers.rb +1 -1
  29. data/lib/facter/facts/windows/ec2_metadata.rb +1 -1
  30. data/lib/facter/facts/windows/ec2_userdata.rb +1 -1
  31. data/lib/facter/framework/cli/cli.rb +7 -7
  32. data/lib/facter/framework/config/config_reader.rb +1 -1
  33. data/lib/facter/framework/core/cache_manager.rb +3 -6
  34. data/lib/facter/framework/core/options/option_store.rb +1 -1
  35. data/lib/facter/framework/core/options.rb +1 -1
  36. data/lib/facter/framework/formatters/legacy_fact_formatter.rb +1 -1
  37. data/lib/facter/framework/logging/logger.rb +1 -1
  38. data/lib/facter/models/fact_collection.rb +1 -3
  39. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  40. data/lib/facter/resolvers/aix/mountpoints.rb +3 -3
  41. data/lib/facter/resolvers/aix/networking.rb +1 -1
  42. data/lib/facter/resolvers/az.rb +1 -1
  43. data/lib/facter/resolvers/ec2.rb +20 -8
  44. data/lib/facter/resolvers/gce.rb +1 -1
  45. data/lib/facter/resolvers/linux/docker_uptime.rb +1 -1
  46. data/lib/facter/resolvers/linux/hostname.rb +1 -1
  47. data/lib/facter/resolvers/linux/processors.rb +1 -1
  48. data/lib/facter/resolvers/macosx/mountpoints.rb +1 -0
  49. data/lib/facter/resolvers/mountpoints.rb +1 -1
  50. data/lib/facter/resolvers/networking.rb +1 -2
  51. data/lib/facter/resolvers/path.rb +1 -1
  52. data/lib/facter/resolvers/selinux.rb +1 -1
  53. data/lib/facter/resolvers/solaris/ffi/functions.rb +1 -0
  54. data/lib/facter/resolvers/solaris/ffi/structs.rb +38 -38
  55. data/lib/facter/resolvers/solaris/mountpoints.rb +1 -0
  56. data/lib/facter/resolvers/solaris/networking.rb +1 -2
  57. data/lib/facter/resolvers/solaris/os_release.rb +1 -1
  58. data/lib/facter/resolvers/solaris/processors.rb +1 -1
  59. data/lib/facter/resolvers/uname.rb +3 -3
  60. data/lib/facter/resolvers/windows/netkvm.rb +1 -2
  61. data/lib/facter/resolvers/windows/processors.rb +6 -6
  62. data/lib/facter/resolvers/windows/ssh.rb +1 -1
  63. data/lib/facter/resolvers/windows/system32.rb +1 -1
  64. data/lib/facter/resolvers/windows/timezone.rb +1 -1
  65. data/lib/facter/resolvers/windows/uptime.rb +1 -2
  66. data/lib/facter/resolvers/windows/virtualization.rb +1 -2
  67. data/lib/facter/resolvers/windows/win_os_description.rb +1 -2
  68. data/lib/facter/util/api_debugger.rb +1 -1
  69. data/lib/facter/util/facts/posix/virtual_detector.rb +2 -2
  70. data/lib/facter/util/facts/unit_converter.rb +2 -2
  71. data/lib/facter/util/facts/uptime_parser.rb +9 -9
  72. data/lib/facter/util/file_helper.rb +3 -4
  73. data/lib/facter/util/macosx/system_profile_executor.rb +1 -1
  74. data/lib/facter/util/resolvers/ffi/hostname.rb +1 -0
  75. data/lib/facter/util/resolvers/ffi/load_averages.rb +1 -0
  76. data/lib/facter/util/resolvers/http.rb +34 -5
  77. data/lib/facter/util/resolvers/networking/networking.rb +3 -3
  78. data/lib/facter/version.rb +1 -1
  79. data/lib/facter.rb +9 -9
  80. metadata +9 -21
@@ -16,7 +16,7 @@ module Facter
16
16
  end
17
17
 
18
18
  def []=(key, value)
19
- OptionStore.send("#{key}=".to_sym, value)
19
+ OptionStore.send(:"#{key}=", value)
20
20
  end
21
21
 
22
22
  def custom_dir?
@@ -69,7 +69,7 @@ module Facter
69
69
  pretty_json.gsub!(/"(.*)"\ =>/, '\1 =>')
70
70
 
71
71
  @log.debug('Remove double backslashes from paths')
72
- pretty_json.gsub(/\\\\/, '\\')
72
+ pretty_json.gsub('\\\\', '\\')
73
73
  end
74
74
 
75
75
  def remove_enclosing_accolades(pretty_fact_json)
@@ -52,7 +52,7 @@ module Facter
52
52
 
53
53
  def set_logger_format
54
54
  @@logger.formatter = proc do |severity, datetime, _progname, msg|
55
- datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ')
55
+ datetime = datetime.strftime('%Y-%m-%dT%H:%M:%S.%6N%:z')
56
56
  "[#{datetime}] #{severity} #{msg} \n"
57
57
  end
58
58
  end
@@ -79,9 +79,7 @@ module Facter
79
79
  split_fact_name = extract_fact_name(fact)
80
80
  bury(*split_fact_name << fact.value)
81
81
  rescue NoMethodError
82
- @log.error("#{fact.type.to_s.capitalize} fact `#{fact.name}` cannot be added to collection."\
83
- ' The format of this fact is incompatible with other'\
84
- " facts that belong to `#{fact.name.split('.').first}` group")
82
+ @log.error("#{fact.type.to_s.capitalize} fact `#{fact.name}` cannot be added to collection. The format of this fact is incompatible with other facts that belong to `#{fact.name.split('.').first}` group")
85
83
  end
86
84
 
87
85
  def extract_fact_name(fact)
@@ -33,7 +33,7 @@ module Facter
33
33
 
34
34
  return if Libc.getkerninfo(KINFO_READ | KINFO_GET_AVENRUN, averages, averages_size, 0).negative?
35
35
 
36
- averages.read_array_of_long_long(3).map { |x| (x / 65_536.0) }
36
+ averages.read_array_of_long_long(3).map { |x| x / 65_536.0 }
37
37
  end
38
38
 
39
39
  def self.read_interfaces
@@ -31,11 +31,11 @@ module Facter
31
31
  def add_mount_points_fact(line)
32
32
  elem = line.split("\s")
33
33
 
34
- if line[0] != ' '
34
+ if line[0] == ' '
35
+ device = elem[0]
36
+ else
35
37
  server = elem.shift
36
38
  device = "#{server}:#{elem[0]}"
37
- else
38
- device = elem[0]
39
39
  end
40
40
 
41
41
  @fact_list[:mountpoints][elem[1]] = { device: device, filesystem: elem[2],
@@ -16,7 +16,7 @@ module Facter
16
16
  def read_netstat(fact_name)
17
17
  @fact_list[:interfaces] = {}
18
18
  output = Facter::Core::Execution.execute('netstat -rn', logger: log)
19
- output = output.each_line.select { |line| (line =~ /\s\s[0-9]+.[0-9]+.[0-9]+.[0-9]+|\s\s.*:[0-9a-f]+/) }
19
+ output = output.each_line.select { |line| line =~ /\s\s[0-9]+.[0-9]+.[0-9]+.[0-9]+|\s\s.*:[0-9a-f]+/ }
20
20
  @fact_list[:interfaces] = load_interfaces
21
21
 
22
22
  populate_with_mtu_and_mac!(@fact_list[:interfaces])
@@ -30,7 +30,7 @@ module Facter
30
30
  end
31
31
 
32
32
  def determine_session_timeout
33
- session_env = ENV['AZ_SESSION_TIMEOUT']
33
+ session_env = ENV.fetch('AZ_SESSION_TIMEOUT', nil)
34
34
  session_env ? session_env.to_i : AZ_SESSION_TIMEOUT
35
35
  end
36
36
  end
@@ -18,14 +18,19 @@ module Facter
18
18
  end
19
19
 
20
20
  def read_facts(fact_name)
21
- @fact_list[:metadata] = {}
22
- query_for_metadata(EC2_METADATA_ROOT_URL, @fact_list[:metadata])
23
- @fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8')
21
+ if fact_name == :metadata
22
+ metadata = {}
23
+ query_for_metadata(EC2_METADATA_ROOT_URL, metadata)
24
+ @fact_list[:metadata] = metadata
25
+ else
26
+ @fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8')
27
+ end
28
+
24
29
  @fact_list[fact_name]
25
30
  end
26
31
 
27
32
  def query_for_metadata(url, container)
28
- metadata = get_data_from(url)
33
+ metadata = get_metadata_from(url)
29
34
  metadata.each_line do |line|
30
35
  next if line.empty?
31
36
 
@@ -34,14 +39,15 @@ module Facter
34
39
 
35
40
  if http_path_component.end_with?('/')
36
41
  child = {}
37
- child[http_path_component] = query_for_metadata("#{url}#{http_path_component}", child)
38
- child.reject! { |key, _info| key == http_path_component }
42
+ query_for_metadata("#{url}#{http_path_component}", child)
39
43
  name = http_path_component.chomp('/')
40
44
  container[name] = child
41
45
  else
42
- container[http_path_component] = get_data_from("#{url}#{http_path_component}").strip
46
+ container[http_path_component] = get_metadata_from("#{url}#{http_path_component}").strip
43
47
  end
44
48
  end
49
+
50
+ container
45
51
  end
46
52
 
47
53
  def build_path_component(line)
@@ -55,8 +61,14 @@ module Facter
55
61
  Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout }, false)
56
62
  end
57
63
 
64
+ def get_metadata_from(url)
65
+ headers = {}
66
+ headers['X-aws-ec2-metadata-token'] = v2_token if v2_token
67
+ Facter::Util::Resolvers::Http.get_request!(url, headers, { session: determine_session_timeout }, false)
68
+ end
69
+
58
70
  def determine_session_timeout
59
- session_env = ENV['EC2_SESSION_TIMEOUT']
71
+ session_env = ENV.fetch('EC2_SESSION_TIMEOUT', nil)
60
72
  session_env ? session_env.to_i : EC2_SESSION_TIMEOUT
61
73
  end
62
74
 
@@ -6,7 +6,7 @@ module Facter
6
6
  init_resolver
7
7
 
8
8
  METADATA_URL = 'http://metadata.google.internal/computeMetadata/v1/?recursive=true&alt=json'
9
- HEADERS = { "Metadata-Flavor": 'Google', "Accept": 'application/json' }.freeze
9
+ HEADERS = { 'Metadata-Flavor': 'Google', Accept: 'application/json' }.freeze
10
10
 
11
11
  class << self
12
12
  private
@@ -36,7 +36,7 @@ module Facter
36
36
  end
37
37
 
38
38
  def convert_to_seconds(days, hours, minutes, seconds)
39
- days * 24 * 3600 + hours * 3600 + minutes * 60 + seconds
39
+ (days * 24 * 3600) + (hours * 3600) + (minutes * 60) + seconds
40
40
  end
41
41
  end
42
42
  end
@@ -50,7 +50,7 @@ module Facter
50
50
  end
51
51
 
52
52
  log.debug("Tried to retrieve hostname and got: #{output}")
53
- output unless output&.empty?
53
+ output unless output && output.empty?
54
54
  end
55
55
 
56
56
  def parse_fqdn(output)
@@ -70,7 +70,7 @@ module Facter
70
70
  .select { |dir| dir =~ /cpu[0-9]+$/ }
71
71
  .select { |dir| File.exist?("/sys/devices/system/cpu/#{dir}/topology/physical_package_id") }
72
72
  .map do |dir|
73
- Facter::Util::FileHelper.safe_read("/sys/devices/system/cpu/#{dir}/topology/physical_package_id").strip
73
+ Facter::Util::FileHelper.safe_read("/sys/devices/system/cpu/#{dir}/topology/physical_package_id").strip
74
74
  end
75
75
  .uniq.count
76
76
  end
@@ -5,6 +5,7 @@ module Facter
5
5
  module Macosx
6
6
  class Mountpoints < BaseResolver
7
7
  include Facter::Util::Resolvers::FilesystemHelper
8
+
8
9
  init_resolver
9
10
 
10
11
  class << self
@@ -48,7 +48,7 @@ module Facter
48
48
  mount = {}
49
49
  get_mount_data(file_system, mount)
50
50
 
51
- if mount[:path] =~ %r{^/(proc|sys)} && mount[:filesystem] != 'tmpfs' || mount[:filesystem] == 'autofs'
51
+ if (mount[:path] =~ %r{^/(proc|sys)} && mount[:filesystem] != 'tmpfs') || mount[:filesystem] == 'autofs'
52
52
  next
53
53
  end
54
54
 
@@ -97,8 +97,7 @@ module Facter
97
97
  def extract_dhcp(interface_name, raw_data, parsed_interface_data)
98
98
  return unless /status:\s+active/.match?(raw_data)
99
99
 
100
- result = Facter::Core::Execution.execute("ipconfig getoption #{interface_name} " \
101
- 'server_identifier', logger: log)
100
+ result = Facter::Core::Execution.execute("ipconfig getoption #{interface_name} server_identifier", logger: log)
102
101
 
103
102
  parsed_interface_data[:dhcp] = result.match(/^[\d.a-f:\s]+$/)&.to_s&.strip unless result.empty?
104
103
  end
@@ -13,7 +13,7 @@ module Facter
13
13
  end
14
14
 
15
15
  def read_path_from_env
16
- @fact_list[:path] = ENV['PATH']
16
+ @fact_list[:path] = ENV.fetch('PATH', nil)
17
17
  end
18
18
  end
19
19
  end
@@ -58,7 +58,7 @@ module Facter
58
58
  @fact_list[:config_policy] = line.split('=').last.strip if /^SELINUXTYPE=/.match?(line)
59
59
  end
60
60
 
61
- !file_lines.empty? ? true : false
61
+ file_lines.empty? ? false : true
62
62
  end
63
63
  end
64
64
  end
@@ -6,6 +6,7 @@ module Facter
6
6
  module FFI
7
7
  module Ioctl
8
8
  extend ::FFI::Library
9
+
9
10
  ffi_lib ::FFI::Library::LIBC, 'socket'
10
11
 
11
12
  attach_function :ioctl_base, :ioctl, %i[int int pointer], :int
@@ -10,20 +10,20 @@ module Facter
10
10
  end
11
11
 
12
12
  class Sockaddr < ::FFI::Struct
13
- layout :sa_family, :sa_family_t,
14
- :sa_data, [:uchar, 14]
13
+ layout :sa_family, :sa_family_t,
14
+ :sa_data, [:uchar, 14]
15
15
  end
16
16
 
17
17
  class Lifnum < ::FFI::Struct
18
- layout :lifn_family, :sa_family_t,
19
- :lifn_flags, :int,
20
- :lifn_count, :int
18
+ layout :lifn_family, :sa_family_t,
19
+ :lifn_flags, :int,
20
+ :lifn_count, :int
21
21
  end
22
22
 
23
23
  class Arpreq < ::FFI::Struct
24
- layout :arp_pa, Sockaddr,
25
- :arp_ha, Sockaddr,
26
- :arp_flags, :int
24
+ layout :arp_pa, Sockaddr,
25
+ :arp_ha, Sockaddr,
26
+ :arp_flags, :int
27
27
 
28
28
  def sa_data_to_mac
29
29
  self[:arp_ha][:sa_data].entries[0, 6].map do |s|
@@ -41,27 +41,27 @@ module Facter
41
41
  end
42
42
 
43
43
  class Lifru1 < ::FFI::Union
44
- layout :lifru_addrlen, :int,
45
- :lifru_ppa, :uint_t
44
+ layout :lifru_addrlen, :int,
45
+ :lifru_ppa, :uint_t
46
46
  end
47
47
 
48
48
  class Lifru < ::FFI::Union
49
- layout :lifru_addr, SockaddrStorage,
50
- :lifru_dstaddr, SockaddrStorage,
51
- :lifru_broadaddr, SockaddrStorage,
52
- :lifru_token, SockaddrStorage,
53
- :lifru_subnet, SockaddrStorage,
54
- :lifru_flags, :uint64,
55
- :lifru_metric, :int,
56
- :pad, [:char, 80]
49
+ layout :lifru_addr, SockaddrStorage,
50
+ :lifru_dstaddr, SockaddrStorage,
51
+ :lifru_broadaddr, SockaddrStorage,
52
+ :lifru_token, SockaddrStorage,
53
+ :lifru_subnet, SockaddrStorage,
54
+ :lifru_flags, :uint64,
55
+ :lifru_metric, :int,
56
+ :pad, [:char, 80]
57
57
  end
58
58
 
59
59
  class Lifreq < ::FFI::Struct
60
- layout :lifr_name, [:char, 32],
61
- :lifr_lifru1, Lifru1,
62
- :lifr_movetoindex, :int,
63
- :lifr_lifru, Lifru,
64
- :pad, [:char, 80]
60
+ layout :lifr_name, [:char, 32],
61
+ :lifr_lifru1, Lifru1,
62
+ :lifr_movetoindex, :int,
63
+ :lifr_lifru, Lifru,
64
+ :pad, [:char, 80]
65
65
 
66
66
  def name
67
67
  self[:lifr_name].to_s
@@ -77,10 +77,10 @@ module Facter
77
77
  end
78
78
 
79
79
  class Lifconf < ::FFI::Struct
80
- layout :lifc_family, :uint,
81
- :lifc_flags, :int,
82
- :lifc_len, :int,
83
- :lifc_buf, :pointer
80
+ layout :lifc_family, :uint,
81
+ :lifc_flags, :int,
82
+ :lifc_len, :int,
83
+ :lifc_buf, :pointer
84
84
 
85
85
  def self.new_for_ioctl(interface_count)
86
86
  lifconf = new
@@ -93,8 +93,8 @@ module Facter
93
93
  end
94
94
 
95
95
  class Lifcu < ::FFI::Union
96
- layout :lifcu_buf, :caddr_t,
97
- :lifcu_req, Lifreq
96
+ layout :lifcu_buf, :caddr_t,
97
+ :lifcu_req, Lifreq
98
98
  end
99
99
 
100
100
  class InAddr < ::FFI::Struct
@@ -102,10 +102,10 @@ module Facter
102
102
  end
103
103
 
104
104
  class SockaddrIn < ::FFI::Struct
105
- layout :sin_family, :sa_family_t,
106
- :sin_port, :in_port_t,
107
- :sin_addr, InAddr,
108
- :sin_zero, [:char, 8]
105
+ layout :sin_family, :sa_family_t,
106
+ :sin_port, :in_port_t,
107
+ :sin_addr, InAddr,
108
+ :sin_zero, [:char, 8]
109
109
 
110
110
  def s_addr
111
111
  self[:sin_addr][:s_addr]
@@ -117,11 +117,11 @@ module Facter
117
117
  end
118
118
 
119
119
  class SockaddrIn6 < ::FFI::Struct
120
- layout :sin6_family, :sa_family_t,
121
- :sin6_port, :in_port_t,
122
- :sin6_flowinfo, :uint32_t,
123
- :sin6_addr, In6Addr,
124
- :sin6_scope_id, :uint32_t
120
+ layout :sin6_family, :sa_family_t,
121
+ :sin6_port, :in_port_t,
122
+ :sin6_flowinfo, :uint32_t,
123
+ :sin6_addr, In6Addr,
124
+ :sin6_scope_id, :uint32_t
125
125
  end
126
126
  end
127
127
  end
@@ -5,6 +5,7 @@ module Facter
5
5
  module Solaris
6
6
  class Mountpoints < BaseResolver
7
7
  include Facter::Util::Resolvers::FilesystemHelper
8
+
8
9
  init_resolver
9
10
 
10
11
  class << self
@@ -55,8 +55,7 @@ module Facter
55
55
  ioctl = FFI::Ioctl.ioctl(FFI::SIOCGARP, arp, lifreq.ss_family)
56
56
 
57
57
  if ioctl == -1
58
- @log.debug("Could not read MAC address for interface #{lifreq.name} "\
59
- "error code is: #{::FFI::LastError.error}")
58
+ @log.debug("Could not read MAC address for interface #{lifreq.name} error code is: #{::FFI::LastError.error}")
60
59
  end
61
60
 
62
61
  mac = arp.sa_data_to_mac
@@ -35,7 +35,7 @@ module Facter
35
35
  def search_for_os_version(regex_pattern, text)
36
36
  result = text.match(regex_pattern)
37
37
  major, minor = result.captures if result
38
- minor = regex_pattern == /Solaris (\d+)/ ? '0' : minor
38
+ minor = '0' if regex_pattern == /Solaris (\d+)/
39
39
  [major, minor] if major && minor
40
40
  end
41
41
  end
@@ -24,7 +24,7 @@ module Facter
24
24
  end
25
25
 
26
26
  def parse_output(output)
27
- @fact_list[:logical_count] = output.scan(/module/).size
27
+ @fact_list[:logical_count] = output.scan('module').size
28
28
  @fact_list[:physical_count] = output.scan(/chip_id .*/).uniq.size
29
29
  # .scan(//current_clock_Hz\s+(\d+)/) returns [['123']] (or [['123'], ['456']] if there are more matches)
30
30
  @fact_list[:speed] = output.scan(/current_clock_Hz\s+(\d+)/).first&.first&.to_i
@@ -28,7 +28,9 @@ module Facter
28
28
  def build_fact_list(output)
29
29
  uname_results = output.split("\n")
30
30
 
31
- if !uname_results.empty?
31
+ if uname_results.empty?
32
+ log.warn('Request to uname returned no output. Uname related facts are not populated.')
33
+ else
32
34
  @fact_list[:machine],
33
35
  @fact_list[:nodename],
34
36
  @fact_list[:processor],
@@ -39,8 +41,6 @@ module Facter
39
41
  # Fall back to -m (machine), which is the procedure suggested by the
40
42
  # uutils/coreutils developers.
41
43
  @fact_list[:processor] = @fact_list[:machine] if @fact_list[:processor] == 'unknown'
42
- else
43
- log.warn('Request to uname returned no output. Uname related facts are not populated.')
44
44
  end
45
45
  end
46
46
  end
@@ -23,9 +23,8 @@ module Facter
23
23
  end
24
24
 
25
25
  def build_fact_list(reg)
26
- # rubocop:disable Performance/InefficientHashSearch
26
+ # rubocop:disable-next Performance/InefficientHashSearch
27
27
  @fact_list[:kvm] = reg.keys.include?('netkvm')
28
- # rubocop:enable Performance/InefficientHashSearch
29
28
  end
30
29
  end
31
30
  end
@@ -19,14 +19,14 @@ module Facter
19
19
 
20
20
  def read_fact_from_win32_processor(fact_name)
21
21
  win = Facter::Util::Windows::Win32Ole.new
22
- query_string = 'SELECT Name,'\
23
- 'Architecture,'\
24
- 'NumberOfLogicalProcessors,'\
25
- 'NumberOfCores FROM Win32_Processor'
22
+ query_string = 'SELECT Name,' \
23
+ 'Architecture,' \
24
+ 'NumberOfLogicalProcessors,' \
25
+ 'NumberOfCores FROM Win32_Processor'
26
26
  proc = win.exec_query(query_string)
27
27
  unless proc
28
- log.debug 'WMI query returned no results'\
29
- 'for Win32_Processor with values Name, Architecture and NumberOfLogicalProcessors.'
28
+ log.debug 'WMI query returned no results' \
29
+ 'for Win32_Processor with values Name, Architecture and NumberOfLogicalProcessors.'
30
30
  return
31
31
  end
32
32
  result = iterate_proc(proc)
@@ -33,7 +33,7 @@ module Facter
33
33
  end
34
34
 
35
35
  def determine_ssh_dir
36
- progdata_dir = ENV['programdata']
36
+ progdata_dir = ENV['programdata'] # rubocop:disable Style/FetchEnvVar
37
37
 
38
38
  return if !progdata_dir || progdata_dir.empty?
39
39
 
@@ -15,7 +15,7 @@ module Facter
15
15
  def retrieve_windows_binaries_path
16
16
  require_relative '../../../facter/resolvers/windows/ffi/system32_ffi'
17
17
 
18
- windows_path = ENV['SystemRoot']
18
+ windows_path = ENV['SystemRoot'] # rubocop:disable Style/FetchEnvVar
19
19
 
20
20
  if !windows_path || windows_path.empty?
21
21
  @log.debug 'Unable to find correct value for SystemRoot enviroment variable'
@@ -22,7 +22,7 @@ module Facter
22
22
 
23
23
  def codepage
24
24
  result = codepage_from_api
25
- result&.empty? ? codepage_from_registry : result
25
+ result && result.empty? ? codepage_from_registry : result
26
26
  end
27
27
 
28
28
  def codepage_from_registry
@@ -19,8 +19,7 @@ module Facter
19
19
  win = Facter::Util::Windows::Win32Ole.new
20
20
  opsystem = win.return_first('SELECT LocalDateTime,LastBootUpTime FROM Win32_OperatingSystem')
21
21
  unless opsystem
22
- @log.debug 'WMI query returned no results'\
23
- 'for Win32_OperatingSystem with values LocalDateTime and LastBootUpTime.'
22
+ @log.debug 'WMI query returned no results for Win32_OperatingSystem with values LocalDateTime and LastBootUpTime.'
24
23
  return
25
24
  end
26
25
 
@@ -30,8 +30,7 @@ module Facter
30
30
  win = Facter::Util::Windows::Win32Ole.new
31
31
  comp = win.exec_query('SELECT Manufacturer,Model,OEMStringArray FROM Win32_ComputerSystem')
32
32
  unless comp
33
- @log.debug 'WMI query returned no results for Win32_ComputerSystem with values'\
34
- ' Manufacturer, Model and OEMStringArray.'
33
+ @log.debug 'WMI query returned no results for Win32_ComputerSystem with values Manufacturer, Model and OEMStringArray.'
35
34
  return
36
35
  end
37
36
 
@@ -16,8 +16,7 @@ module Facter
16
16
  win = Facter::Util::Windows::Win32Ole.new
17
17
  op_sys = win.return_first('SELECT ProductType,OtherTypeDescription FROM Win32_OperatingSystem')
18
18
  unless op_sys
19
- @log.debug 'WMI query returned no results for Win32_OperatingSystem'\
20
- 'with values ProductType and OtherTypeDescription.'
19
+ @log.debug 'WMI query returned no results for Win32_OperatingSystem with values ProductType and OtherTypeDescription.'
21
20
  return
22
21
  end
23
22
  @fact_list[:consumerrel] = (op_sys.ProductType == 1)
@@ -4,7 +4,7 @@ module Facter
4
4
  module Util
5
5
  module ApiDebugger
6
6
  def self.prepended(receiver)
7
- exclude, print_caller = parse_options(ENV['API_DEBUG'])
7
+ exclude, print_caller = parse_options(ENV.fetch('API_DEBUG', nil))
8
8
 
9
9
  receiver_methods = receiver.instance_methods - Object.methods
10
10
  receiver_methods.each do |meth|
@@ -8,8 +8,8 @@ module Facter
8
8
  class << self
9
9
  def platform
10
10
  @fact_value ||= # rubocop:disable Naming/MemoizedInstanceVariableName
11
- check_docker_lxc || check_freebsd || check_openbsd || check_gce || check_illumos_lx || \
12
- retrieve_from_virt_what || check_vmware || check_open_vz || check_vserver || \
11
+ check_docker_lxc || check_freebsd || check_openbsd || check_gce || check_illumos_lx ||
12
+ retrieve_from_virt_what || check_vmware || check_open_vz || check_vserver ||
13
13
  check_xen || check_other_facts || check_lspci || 'physical'
14
14
  end
15
15
 
@@ -42,7 +42,7 @@ module Facter
42
42
  def determine_exponent(bytes)
43
43
  prefix = %w[KiB MiB GiB TiB PiB EiB]
44
44
  exp = (Math.log2(bytes) / 10.0).floor
45
- converted_number = (100.0 * (bytes / 1024.0**exp)).round / 100.0
45
+ converted_number = (100.0 * (bytes / (1024.0**exp))).round / 100.0
46
46
 
47
47
  if (converted_number - 1024.0).abs < Float::EPSILON
48
48
  exp += 1
@@ -57,7 +57,7 @@ module Facter
57
57
  def determine_metric_prefix(num)
58
58
  metric_prefix = { 0 => '', 3 => 'k', 6 => 'M', 9 => 'G', 12 => 'T' }
59
59
  power = Math.log10(num).floor
60
- display_exponent = power - power % 3
60
+ display_exponent = power - (power % 3)
61
61
  coefficient = power.zero? ? num.to_f : num.fdiv(10**display_exponent)
62
62
  [coefficient, metric_prefix[display_exponent]]
63
63
  end
@@ -75,23 +75,23 @@ module Facter
75
75
  def calculate_days_hours_minutes(output)
76
76
  return unless output =~ /(\d+) day(?:s|\(s\))?,?\s+(\d+):-?(\d+)/
77
77
 
78
- SECS_IN_A_DAY * Regexp.last_match(1).to_i +
79
- SECS_IN_AN_HOUR * Regexp.last_match(2).to_i +
80
- SECS_IN_A_MINUTE * Regexp.last_match(3).to_i
78
+ (SECS_IN_A_DAY * Regexp.last_match(1).to_i) +
79
+ (SECS_IN_AN_HOUR * Regexp.last_match(2).to_i) +
80
+ (SECS_IN_A_MINUTE * Regexp.last_match(3).to_i)
81
81
  end
82
82
 
83
83
  def calculate_days_hours(output)
84
84
  return unless output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) hr(?:s|\(s\))?,/
85
85
 
86
- SECS_IN_A_DAY * Regexp.last_match(1).to_i +
87
- SECS_IN_AN_HOUR * Regexp.last_match(2).to_i
86
+ (SECS_IN_A_DAY * Regexp.last_match(1).to_i) +
87
+ (SECS_IN_AN_HOUR * Regexp.last_match(2).to_i)
88
88
  end
89
89
 
90
90
  def calculate_days_minutes(output)
91
91
  return unless output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) min(?:s|\(s\))?,/
92
92
 
93
- SECS_IN_A_DAY * Regexp.last_match(1).to_i +
94
- SECS_IN_A_MINUTE * Regexp.last_match(2).to_i
93
+ (SECS_IN_A_DAY * Regexp.last_match(1).to_i) +
94
+ (SECS_IN_A_MINUTE * Regexp.last_match(2).to_i)
95
95
  end
96
96
 
97
97
  def calculate_days(output)
@@ -106,8 +106,8 @@ module Facter
106
106
  def calculate_hours_minutes(output)
107
107
  return unless output =~ /up\s+(\d+):-?(\d+),/
108
108
 
109
- SECS_IN_AN_HOUR * Regexp.last_match(1).to_i +
110
- SECS_IN_A_MINUTE * Regexp.last_match(2).to_i
109
+ (SECS_IN_AN_HOUR * Regexp.last_match(1).to_i) +
110
+ (SECS_IN_A_MINUTE * Regexp.last_match(2).to_i)
111
111
  end
112
112
 
113
113
  def calculate_hours(output)