facter 4.4.1 → 4.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74662429c9115d4eb8feca42d49031fa3be3ff42c200a8c6ee58c664f8afa9da
4
- data.tar.gz: e1c21ea94af446c6700c27db8c24f150671f7ee8410b8e070436e709ff85fc87
3
+ metadata.gz: c01a91258966862aa3d5b43fca18899206b64cefa3fd42446ac1c012132e90ea
4
+ data.tar.gz: 3e1c32c10e166a3dcb8ed55d709b4ce8cbe9c56b9238ed42964519caf48b82be
5
5
  SHA512:
6
- metadata.gz: 9a1a2529c0fe5df5da517bbcc8b76b2a53c5c138af5d83ebf8dc25b051d28861816ed4b8ab6c1e167ec4c6bcef50df7d68a34abd22f04442f44eaebd499f3bef
7
- data.tar.gz: 6c31e966940c2d1a525c5fb1f416b5af15e2b8c57516c92eab6e74be361d198bd6494e26b85316758e7e42ff1eecc6fc3480c3f718b8de2e7d452bcde39911f0
6
+ metadata.gz: a9f7a49e2297d1dd06b1544118e58a5cba75aa04a5991e61e3450039ff86caa934c30d1d7b584d4432a081d010be6f978f6bc6fef8cfdfa38367ec858f0a2754
7
+ data.tar.gz: c7793db89e1fd72269eba0b1f195942020a60d699374b661cd87f418be2aff38cb128ab45d0959696e696601c0bb70b7715d85c5c6404bb1aa77e9727e5f659b
@@ -32,7 +32,7 @@ module LegacyFacter
32
32
 
33
33
  fact
34
34
  rescue StandardError => e
35
- log.log_exception("Unable to add fact #{name}: #{e}")
35
+ log.log_exception(e)
36
36
  end
37
37
 
38
38
  # Add a resolution mechanism for a named fact. This does not distinguish
@@ -48,6 +48,8 @@ module LegacyFacter
48
48
  fact.add(options, &block)
49
49
 
50
50
  fact
51
+ rescue StandardError => e
52
+ log.log_exception(e)
51
53
  end
52
54
 
53
55
  include Enumerable
@@ -35,7 +35,7 @@ module Facter
35
35
  #
36
36
  # @api private
37
37
  def initialize(name, options = {})
38
- @name = name.to_s.downcase.intern
38
+ @name = LegacyFacter::Util::Normalization.normalize(name.to_s.downcase).intern
39
39
 
40
40
  @options = options.dup
41
41
  extract_ldapname_option!(options)
@@ -54,6 +54,10 @@ module LegacyFacter
54
54
  raise NormalizationError, "String #{value.inspect} doesn't match the reported encoding #{value.encoding}"
55
55
  end
56
56
 
57
+ if value.codepoints.include?(0)
58
+ raise NormalizationError, "String #{value.inspect} contains a null byte reference; unsupported for all facts."
59
+ end
60
+
57
61
  value
58
62
  rescue EncodingError
59
63
  raise NormalizationError, "String encoding #{value.encoding} is not UTF-8 and could not be converted to UTF-8"
@@ -17,6 +17,9 @@ module Facter
17
17
  @fact_list[:augeas_version] ||= read_augeas_from_gem
18
18
 
19
19
  @fact_list[fact_name]
20
+ rescue LoadError => e
21
+ log.debug("Resolving fact #{fact_name}, but got #{e} at #{e.backtrace[0]}")
22
+ @fact_list[:augeas_version] = nil
20
23
  end
21
24
 
22
25
  def read_augeas_from_cli
@@ -27,11 +27,8 @@ module Facter
27
27
 
28
28
  cache_nil_for_unresolved_facts(fact_name)
29
29
  end
30
- rescue NoMethodError => e
31
- log.debug("Could not resolve #{fact_name}, got #{e} at #{e.backtrace[0]}")
32
- @fact_list[fact_name] = nil
33
30
  rescue LoadError, NameError => e
34
- log.debug("Resolving fact #{fact_name}, but got #{e} at #{e.backtrace[0]}")
31
+ log.error("Resolving fact #{fact_name}, but got #{e} at #{e.backtrace[0]}")
35
32
  @fact_list[fact_name] = nil
36
33
  end
37
34
 
@@ -36,7 +36,7 @@ module Facter
36
36
  return unless File.directory?('/sys/class/dmi')
37
37
 
38
38
  file_content = Facter::Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
39
- .encode('UTF-8', invalid: :replace)
39
+ file_content = file_content.encode('UTF-8', invalid: :replace) if file_content
40
40
  if files.include?(fact_name.to_s) && file_content
41
41
  file_content = file_content.strip
42
42
  @fact_list[fact_name] = file_content unless file_content.empty?
@@ -69,17 +69,28 @@ module Facter
69
69
  def process_id
70
70
  return unless @fact_list[:id]
71
71
 
72
+ @fact_list[:id] = 'sles' if /sles_sap/i.match?(@fact_list[:id])
72
73
  @fact_list[:id] = 'opensuse' if /opensuse/i.match?(@fact_list[:id])
73
74
  end
74
75
 
75
76
  def process_name
76
77
  return unless @fact_list[:name]
77
78
 
79
+ normalize_os_name
78
80
  join_os_name
79
81
  capitalize_os_name
80
82
  append_linux_to_os_name
81
83
  end
82
84
 
85
+ def normalize_os_name
86
+ os_name = @fact_list[:name]
87
+ @fact_list[:name] = if os_name.downcase.start_with?('sles')
88
+ 'SLES'
89
+ else
90
+ os_name
91
+ end
92
+ end
93
+
83
94
  def join_os_name
84
95
  os_name = @fact_list[:name]
85
96
  @fact_list[:name] = if os_name.downcase.start_with?('red', 'oracle', 'arch', 'manjaro')
@@ -25,7 +25,7 @@ module Facter
25
25
  @mounts = []
26
26
  @auto_home_paths = []
27
27
 
28
- Facter::Util::Resolvers::FilesystemHelper.read_mountpoints.each do |fs|
28
+ Facter::Util::Resolvers::FilesystemHelper.read_mountpoints&.each do |fs|
29
29
  if fs.name == 'auto_home'
30
30
  @auto_home_paths << fs.mount_point
31
31
  next
@@ -33,26 +33,22 @@ module Facter
33
33
 
34
34
  next if fs.mount_type == 'autofs'
35
35
 
36
+ mounts = {}
36
37
  device = fs.name
37
38
  filesystem = fs.mount_type
38
39
  path = fs.mount_point
39
40
  options = fs.options.split(',').map(&:strip)
40
41
 
41
- stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(path)
42
- size_bytes = stats.bytes_total.abs
43
- available_bytes = stats.bytes_available.abs
44
-
45
- used_bytes = stats.bytes_used.abs
46
- total_bytes = used_bytes + available_bytes
47
- capacity = Facter::Util::Resolvers::FilesystemHelper.compute_capacity(used_bytes, total_bytes)
48
-
49
- size = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes)
50
- available = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes)
51
- used = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
42
+ mounts = read_stats(path).tap do |hash|
43
+ hash[:device] = device
44
+ hash[:filesystem] = filesystem
45
+ hash[:path] = path
46
+ hash[:options] = options if options.any?
47
+ end
52
48
 
53
49
  @mounts << Hash[Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
54
50
  .zip(Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
55
- .map { |v| binding.local_variable_get(v) })]
51
+ .map { |v| mounts[v] })]
56
52
  end
57
53
 
58
54
  exclude_auto_home_mounts!
@@ -60,6 +56,29 @@ module Facter
60
56
  @fact_list[:mountpoints] = @mounts
61
57
  @fact_list[fact_name]
62
58
  end
59
+
60
+ def read_stats(path)
61
+ begin
62
+ stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(path)
63
+ size_bytes = stats.bytes_total.abs
64
+ available_bytes = stats.bytes_available.abs
65
+ used_bytes = stats.bytes_used.abs
66
+ total_bytes = used_bytes + available_bytes
67
+ rescue Sys::Filesystem::Error
68
+ size_bytes = used_bytes = available_bytes = 0
69
+ end
70
+
71
+ {
72
+ size_bytes: size_bytes,
73
+ available_bytes: available_bytes,
74
+ used_bytes: used_bytes,
75
+ total_bytes: total_bytes,
76
+ capacity: Facter::Util::Resolvers::FilesystemHelper.compute_capacity(used_bytes, total_bytes),
77
+ size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes),
78
+ available: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes),
79
+ used: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
80
+ }
81
+ end
63
82
  end
64
83
  end
65
84
  end
@@ -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&.empty? ? codepage_from_registry : result
26
26
  end
27
27
 
28
28
  def codepage_from_registry
@@ -33,7 +33,7 @@ module Facter
33
33
  private
34
34
 
35
35
  def force_utf(mounts)
36
- mounts.each do |mount|
36
+ mounts&.each do |mount|
37
37
  mount.name.force_encoding('UTF-8')
38
38
  mount.mount_type.force_encoding('UTF-8')
39
39
  mount.mount_point.force_encoding('UTF-8')
@@ -36,7 +36,9 @@ module Facter
36
36
  interfaces = networking_facts[:interfaces]
37
37
 
38
38
  expand_interfaces(interfaces) unless interfaces.nil?
39
- expand_primary_interface(networking_facts, primary) unless primary.nil? || interfaces.nil?
39
+ return if primary.nil? || interfaces.nil? || networking_facts.nil?
40
+
41
+ expand_primary_interface(networking_facts, primary)
40
42
  end
41
43
 
42
44
  def get_scope(ip)
@@ -105,7 +107,7 @@ module Facter
105
107
  end
106
108
 
107
109
  def expand_primary_interface(networking_facts, primary)
108
- networking_facts[:interfaces][primary].each do |key, value|
110
+ networking_facts[:interfaces][primary]&.each do |key, value|
109
111
  networking_facts[key] = value unless %i[bindings bindings6].include?(key)
110
112
  end
111
113
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.4.1' unless defined?(VERSION)
4
+ VERSION = '4.4.2' unless defined?(VERSION)
5
5
  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.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-12 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake