facter 4.0.50 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate_cli.rb +7 -0
  3. data/lib/facter.rb +90 -56
  4. data/lib/facter/config.rb +2 -0
  5. data/lib/facter/custom_facts/core/aggregate.rb +9 -0
  6. data/lib/facter/custom_facts/core/execution/base.rb +7 -3
  7. data/lib/facter/custom_facts/core/execution/popen3.rb +13 -1
  8. data/lib/facter/custom_facts/core/execution/posix.rb +2 -2
  9. data/lib/facter/custom_facts/core/execution/windows.rb +1 -1
  10. data/lib/facter/custom_facts/core/resolvable.rb +11 -0
  11. data/lib/facter/custom_facts/util/collection.rb +5 -0
  12. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  13. data/lib/facter/custom_facts/util/normalization.rb +7 -2
  14. data/lib/facter/custom_facts/util/resolution.rb +2 -0
  15. data/lib/facter/custom_facts/util/windows_root.rb +2 -1
  16. data/lib/facter/facts/aix/processors/cores.rb +16 -0
  17. data/lib/facter/facts/aix/processors/threads.rb +16 -0
  18. data/lib/facter/facts/amzn/lsbdistcodename.rb +16 -0
  19. data/lib/facter/facts/amzn/lsbdistdescription.rb +16 -0
  20. data/lib/facter/facts/amzn/lsbdistid.rb +16 -0
  21. data/lib/facter/facts/amzn/os/distro/codename.rb +24 -0
  22. data/lib/facter/facts/amzn/os/distro/description.rb +21 -0
  23. data/lib/facter/facts/amzn/os/distro/id.rb +21 -0
  24. data/lib/facter/facts/amzn/os/distro/release.rb +32 -0
  25. data/lib/facter/facts/freebsd/is_virtual.rb +1 -5
  26. data/lib/facter/facts/freebsd/virtual.rb +1 -2
  27. data/lib/facter/facts/linux/az_metadata.rb +23 -0
  28. data/lib/facter/facts/linux/cloud/provider.rb +20 -0
  29. data/lib/facter/facts/linux/dhcp_servers.rb +2 -2
  30. data/lib/facter/facts/linux/ec2_metadata.rb +1 -5
  31. data/lib/facter/facts/linux/ec2_userdata.rb +1 -5
  32. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -4
  33. data/lib/facter/facts/linux/interfaces.rb +1 -1
  34. data/lib/facter/facts/linux/ipaddress6_interfaces.rb +1 -1
  35. data/lib/facter/facts/linux/ipaddress_interfaces.rb +1 -1
  36. data/lib/facter/facts/linux/is_virtual.rb +1 -5
  37. data/lib/facter/facts/linux/macaddress_interfaces.rb +1 -1
  38. data/lib/facter/facts/linux/mtu_interfaces.rb +1 -1
  39. data/lib/facter/facts/linux/netmask6_interfaces.rb +1 -1
  40. data/lib/facter/facts/linux/netmask_interfaces.rb +1 -1
  41. data/lib/facter/facts/linux/network6_interfaces.rb +1 -1
  42. data/lib/facter/facts/linux/network_interfaces.rb +1 -1
  43. data/lib/facter/facts/linux/networking/dhcp.rb +1 -1
  44. data/lib/facter/facts/linux/networking/domain.rb +1 -1
  45. data/lib/facter/facts/linux/networking/fqdn.rb +1 -1
  46. data/lib/facter/facts/linux/networking/hostname.rb +1 -1
  47. data/lib/facter/facts/linux/networking/interfaces.rb +1 -1
  48. data/lib/facter/facts/linux/networking/ip.rb +1 -1
  49. data/lib/facter/facts/linux/networking/ip6.rb +1 -1
  50. data/lib/facter/facts/linux/networking/mac.rb +1 -1
  51. data/lib/facter/facts/linux/networking/mtu.rb +1 -1
  52. data/lib/facter/facts/linux/networking/netmask.rb +1 -1
  53. data/lib/facter/facts/linux/networking/netmask6.rb +1 -1
  54. data/lib/facter/facts/linux/networking/network.rb +1 -1
  55. data/lib/facter/facts/linux/networking/network6.rb +1 -1
  56. data/lib/facter/facts/linux/networking/primary.rb +1 -1
  57. data/lib/facter/facts/linux/networking/scope6.rb +1 -1
  58. data/lib/facter/facts/linux/processors/cores.rb +16 -0
  59. data/lib/facter/facts/linux/processors/threads.rb +16 -0
  60. data/lib/facter/facts/linux/scope6_interfaces.rb +1 -1
  61. data/lib/facter/facts/linux/virtual.rb +1 -2
  62. data/lib/facter/facts/macosx/os/macosx/version.rb +15 -4
  63. data/lib/facter/facts/macosx/processors/cores.rb +16 -0
  64. data/lib/facter/facts/macosx/processors/threads.rb +16 -0
  65. data/lib/facter/facts/rhel/lsbdistcodename.rb +16 -0
  66. data/lib/facter/facts/rhel/lsbdistdescription.rb +16 -0
  67. data/lib/facter/facts/rhel/lsbdistid.rb +16 -0
  68. data/lib/facter/facts/rhel/os/distro/codename.rb +2 -4
  69. data/lib/facter/facts/rhel/os/distro/description.rb +2 -4
  70. data/lib/facter/facts/rhel/os/distro/id.rb +2 -4
  71. data/lib/facter/facts/rhel/os/distro/release.rb +13 -12
  72. data/lib/facter/facts/sles/lsbdistcodename.rb +16 -0
  73. data/lib/facter/facts/sles/lsbdistdescription.rb +16 -0
  74. data/lib/facter/facts/sles/lsbdistid.rb +16 -0
  75. data/lib/facter/facts/sles/os/distro/codename.rb +3 -4
  76. data/lib/facter/facts/sles/os/distro/description.rb +2 -5
  77. data/lib/facter/facts/sles/os/distro/id.rb +6 -5
  78. data/lib/facter/facts/sles/os/distro/release.rb +17 -12
  79. data/lib/facter/facts/solaris/hypervisors/ldom.rb +1 -1
  80. data/lib/facter/facts/solaris/hypervisors/zone.rb +1 -1
  81. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  82. data/lib/facter/facts/solaris/processors/cores.rb +16 -0
  83. data/lib/facter/facts/solaris/processors/threads.rb +16 -0
  84. data/lib/facter/facts/ubuntu/lsbdistrelease.rb +2 -2
  85. data/lib/facter/facts/windows/az_metadata.rb +23 -0
  86. data/lib/facter/facts/windows/cloud/provider.rb +21 -0
  87. data/lib/facter/facts/windows/ec2_metadata.rb +1 -1
  88. data/lib/facter/facts/windows/ec2_userdata.rb +1 -1
  89. data/lib/facter/facts/windows/gce.rb +1 -1
  90. data/lib/facter/facts/windows/hypervisors/hyperv.rb +1 -1
  91. data/lib/facter/facts/windows/hypervisors/kvm.rb +2 -1
  92. data/lib/facter/facts/windows/hypervisors/virtualbox.rb +2 -2
  93. data/lib/facter/facts/windows/hypervisors/vmware.rb +1 -1
  94. data/lib/facter/facts/windows/hypervisors/xen.rb +3 -1
  95. data/lib/facter/facts/windows/is_virtual.rb +15 -0
  96. data/lib/facter/facts/windows/{virtualization/is_virtual.rb → processors/cores.rb} +4 -4
  97. data/lib/facter/facts/windows/{virtualization/virtual.rb → processors/threads.rb} +4 -4
  98. data/lib/facter/facts/windows/virtual.rb +15 -0
  99. data/lib/facter/framework/cli/cli.rb +6 -8
  100. data/lib/facter/framework/config/config_reader.rb +2 -0
  101. data/lib/facter/framework/config/fact_groups.rb +25 -2
  102. data/lib/facter/framework/core/cache_manager.rb +7 -3
  103. data/lib/facter/framework/core/fact/external/external_fact_manager.rb +0 -1
  104. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +41 -39
  105. data/lib/facter/framework/core/fact_filter.rb +5 -15
  106. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +9 -6
  107. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +39 -37
  108. data/lib/facter/framework/core/fact_manager.rb +84 -14
  109. data/lib/facter/framework/core/file_loader.rb +1 -1
  110. data/lib/facter/framework/core/options.rb +1 -2
  111. data/lib/facter/framework/core/options/config_file_options.rb +7 -0
  112. data/lib/facter/framework/core/options/option_store.rb +12 -6
  113. data/lib/facter/framework/formatters/formatter_helper.rb +3 -5
  114. data/lib/facter/framework/logging/logger.rb +4 -4
  115. data/lib/facter/framework/parsers/query_parser.rb +5 -12
  116. data/lib/facter/models/fact_collection.rb +48 -5
  117. data/lib/facter/models/resolved_fact.rb +2 -3
  118. data/lib/facter/models/searched_fact.rb +2 -3
  119. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  120. data/lib/facter/resolvers/aix/processors.rb +4 -0
  121. data/lib/facter/resolvers/az.rb +39 -0
  122. data/lib/facter/resolvers/base_resolver.rb +2 -2
  123. data/lib/facter/resolvers/dmi_decode.rb +0 -1
  124. data/lib/facter/resolvers/linux/hostname.rb +126 -0
  125. data/lib/facter/resolvers/linux/networking.rb +124 -0
  126. data/lib/facter/resolvers/macosx/mountpoints.rb +14 -1
  127. data/lib/facter/resolvers/macosx/processor.rb +16 -1
  128. data/lib/facter/resolvers/mountpoints.rb +16 -8
  129. data/lib/facter/resolvers/networking.rb +3 -2
  130. data/lib/facter/resolvers/partitions.rb +1 -1
  131. data/lib/facter/resolvers/processors_lscpu.rb +44 -0
  132. data/lib/facter/resolvers/redhat_release.rb +28 -12
  133. data/lib/facter/resolvers/ruby.rb +1 -1
  134. data/lib/facter/resolvers/selinux.rb +5 -7
  135. data/lib/facter/resolvers/solaris/ffi/functions.rb +1 -1
  136. data/lib/facter/resolvers/solaris/ffi/structs.rb +12 -0
  137. data/lib/facter/resolvers/solaris/mountpoints.rb +22 -16
  138. data/lib/facter/resolvers/solaris/networking.rb +20 -5
  139. data/lib/facter/resolvers/solaris/processors.rb +7 -0
  140. data/lib/facter/resolvers/solaris/zone.rb +0 -1
  141. data/lib/facter/resolvers/windows/ffi/identity_ffi.rb +5 -0
  142. data/lib/facter/resolvers/windows/identity.rb +1 -6
  143. data/lib/facter/resolvers/windows/processors.rb +41 -4
  144. data/lib/facter/resolvers/windows/uptime.rb +3 -22
  145. data/lib/facter/resolvers/windows/virtualization.rb +46 -44
  146. data/lib/facter/resolvers/xen.rb +6 -1
  147. data/lib/facter/templates/man.erb +13 -5
  148. data/lib/facter/util/facts/posix/virtual_detector.rb +74 -0
  149. data/lib/facter/util/facts/unit_converter.rb +2 -2
  150. data/lib/facter/util/linux/dhcp.rb +86 -0
  151. data/lib/facter/util/linux/if_inet6.rb +73 -0
  152. data/lib/facter/util/linux/routing_table.rb +60 -0
  153. data/lib/facter/util/linux/socket_parser.rb +114 -0
  154. data/lib/facter/util/resolvers/ffi/hostname.rb +70 -0
  155. data/lib/facter/util/resolvers/http.rb +7 -1
  156. data/lib/facter/util/resolvers/networking/primary_interface.rb +11 -5
  157. data/lib/facter/util/utils.rb +18 -1
  158. data/lib/facter/version.rb +1 -1
  159. metadata +63 -13
  160. data/lib/facter/facts/linux/cloud.rb +0 -15
  161. data/lib/facter/framework/core/fact_augmenter.rb +0 -37
  162. data/lib/facter/resolvers/cloud.rb +0 -39
  163. data/lib/facter/resolvers/networking_linux.rb +0 -296
  164. data/lib/facter/util/facts/virtual_detector.rb +0 -90
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c40ef2043f777620f54c82fc1ee3e746a9b881b74771b3e6ed693773e2ae2e57
4
- data.tar.gz: d6f1f89339c820f37f0a37b07ae42085a231468ce759c9d1a92b0fc7963e7f9e
3
+ metadata.gz: 9921e9c05d22c7fe9c84a9061a374dd9b31b2f7a28bfa292a62fd0e33ec7eb16
4
+ data.tar.gz: 44606e1ec31a336cb71971be5b6c21138f0d33b88d023bb71955526550a54fd2
5
5
  SHA512:
6
- metadata.gz: 91d8d74575aeff6e4b31445a362019fd8f2200f888478b3e2c019a5ccf740b1f9a8590f3edde89f69a66af3bca778d3ab6b73b658c04853122507633221066e3
7
- data.tar.gz: e6cf614befcb67eea1ac89c35a22532c04e40225a87b1d81a6dbf00d227ff55f29630a8637239daf44e4f4ab5de13cb5c9c29b4b612358a8063ee36985d243f8
6
+ metadata.gz: c01cbeb07ac105bbcfcd41598a818962dae3634a72b24f5e850c9dd8b0410c31d52eef1553d9fcc2f3111166d24cba5cb8ae129c3470a1c67a9fc8be12a669cf
7
+ data.tar.gz: d53fe66fd09af1c5d73a3789160a38c236eacf45e43a5096357ab5eb719dcff38d251e8e29dab09a1763d0e2056909977758453e9fb0a272a229f30d70d85ba1
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'facter/framework/cli/cli_launcher'
4
+
5
+ cli = Facter::Cli.new([])
6
+
7
+ puts cli.man
data/lib/facter.rb CHANGED
@@ -27,21 +27,51 @@ module Facter
27
27
  require 'facter/framework/cli/cli_launcher'
28
28
 
29
29
  args = args_as_string.split(' ')
30
-
31
30
  Facter::OptionsValidator.validate(args)
32
31
  processed_arguments = CliLauncher.prepare_arguments(args, nil)
33
-
34
32
  cli = Facter::Cli.new([], processed_arguments)
33
+ cli_options = cli.options.dup
34
+
35
+ # config file options
36
+ config_file = cli_options.delete(:config)
37
+ if config_file
38
+ Facter::OptionStore.set(:config, config_file)
39
+ Facter::ConfigFileOptions.init(config_file)
40
+ Facter::Options.store(ConfigFileOptions.get)
41
+ end
35
42
 
36
- if cli.args.include?(:version)
37
- cli.invoke(:version, [])
38
- elsif cli.args.include?('--list-cache-groups')
39
- cli.invoke(:list_cache_groups, [])
40
- elsif cli.args.include?('--list-block-groups')
41
- cli.invoke(:list_block_groups, [])
43
+ # user provided options
44
+ cli_options[:show_legacy] ||= false
45
+ Facter::Options.store(cli_options)
46
+
47
+ queried_facts(cli.args)
48
+ end
49
+
50
+ # Method used by cli to set puppet paths
51
+ # in order to retrieve puppet custom and external facts
52
+ #
53
+ # @return nil
54
+ #
55
+ # @api private
56
+ def puppet_facts
57
+ require 'puppet'
58
+
59
+ # don't allow puppet logger to be injected in Facter
60
+ Options[:allow_external_loggers] = false
61
+
62
+ Puppet.initialize_settings
63
+ $LOAD_PATH << Puppet[:libdir] unless $LOAD_PATH.include?(Puppet[:libdir])
64
+ Facter.reset
65
+ Facter.search_external([Puppet[:pluginfactdest]])
66
+ if Puppet.respond_to? :initialize_facts
67
+ Puppet.initialize_facts
42
68
  else
43
- cli.invoke(:arg_parser)
69
+ Facter.add(:puppetversion) do
70
+ setcode { Puppet.version.to_s }
71
+ end
44
72
  end
73
+ rescue LoadError => e
74
+ logger.error("Could not load puppet gem, got #{e}")
45
75
  end
46
76
 
47
77
  # Alias method for Facter.fact()
@@ -89,10 +119,10 @@ module Facter
89
119
  nil
90
120
  end
91
121
 
92
- # Gets the value for a core fact, external or custom facts are
93
- # not returned with this call. Returns `nil` if no such fact exists.
122
+ # Retrieves the value of a core fact. External or custom facts are
123
+ # not returned with this call. Returns `nil` if no such fact exists.
94
124
  #
95
- # @return [FactCollection] hash with fact names and values
125
+ # @return [FactCollection] A hash with fact names and values
96
126
  #
97
127
  # @api private
98
128
  def core_value(user_query)
@@ -177,14 +207,29 @@ module Facter
177
207
  Facter::Options[:debug] = debug_bool
178
208
  end
179
209
 
210
+ # Enable sequential resolving of facts
211
+ #
212
+ # @return [bool]
213
+ #
214
+ # @api public
180
215
  def enable_sequential
181
216
  Facter::Options[:sequential] = true
182
217
  end
183
218
 
219
+ # Disable sequential resolving of facts
220
+ #
221
+ # @return [bool]
222
+ #
223
+ # @api public
184
224
  def disable_sequential
185
225
  Facter::Options[:sequential] = false
186
226
  end
187
227
 
228
+ # Check if facts are resolved sequentially or not
229
+ #
230
+ # @return [bool]
231
+ #
232
+ # @api public
188
233
  def sequential?
189
234
  Facter::Options[:sequential]
190
235
  end
@@ -208,23 +253,6 @@ module Facter
208
253
  self
209
254
  end
210
255
 
211
- # Returns a fact object by name. If you use this, you still have to
212
- # call {Facter::Util::Fact#value `value`} on it to retrieve the actual
213
- # value.
214
- #
215
- # @param user_query [String] the name of the fact
216
- #
217
- # @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
218
- # is found.
219
- #
220
- # @api public
221
- def fact(user_query)
222
- user_query = user_query.to_s
223
- resolve_fact(user_query)
224
-
225
- @already_searched[user_query]
226
- end
227
-
228
256
  # Reset search paths for custom and external facts
229
257
  # If config file is set custom and external facts will be reloaded
230
258
  #
@@ -322,10 +350,10 @@ module Facter
322
350
  Options.custom_dir
323
351
  end
324
352
 
325
- # Gets a hash mapping fact names to their values
326
- # The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
353
+ # Retrieves a fact's value. Returns `nil` if no such fact exists.
327
354
  #
328
- # @return [FactCollection] hash with fact names and values
355
+ # @param user_query [String] the fact name
356
+ # @return [String] the value of the fact, or nil if no fact is found
329
357
  #
330
358
  # @api public
331
359
  def to_hash
@@ -366,30 +394,25 @@ module Facter
366
394
  def value(user_query)
367
395
  user_query = user_query.to_s
368
396
  resolve_fact(user_query)
397
+
369
398
  @already_searched[user_query]&.value
370
399
  end
371
400
 
372
- # Gets the values for multiple facts.
401
+ # Returns a fact object by name. If you use this, you still have to
402
+ # call {Facter::Util::Fact#value `value`} on it to retrieve the actual
403
+ # value.
373
404
  #
374
- # @param options [Hash] parameters for the fact - attributes
375
- # of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
376
- # supplied here
377
- # @param user_queries [Array] the fact names
405
+ # @param user_query [String] the name of the fact
378
406
  #
379
- # @return [FactCollection] hash with fact names and values
407
+ # @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
408
+ # is found.
380
409
  #
381
410
  # @api public
382
- def values(options, user_queries)
383
- init_cli_options(options, user_queries)
384
- log_blocked_facts
385
- resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
386
- resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
411
+ def fact(user_query)
412
+ user_query = user_query.to_s
413
+ resolve_fact(user_query)
387
414
 
388
- if user_queries.count.zero?
389
- Facter::FactCollection.new.build_fact_collection!(resolved_facts)
390
- else
391
- FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
392
- end
415
+ @already_searched[user_query]
393
416
  end
394
417
 
395
418
  # Returns Facter version
@@ -407,7 +430,7 @@ module Facter
407
430
  #
408
431
  # @api private
409
432
  def to_user_output(cli_options, *args)
410
- init_cli_options(cli_options, args)
433
+ init_cli_options(cli_options)
411
434
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
412
435
  logger.debug("Facter version: #{Facter::VERSION}")
413
436
  log_blocked_facts
@@ -433,7 +456,7 @@ module Facter
433
456
  nil
434
457
  end
435
458
 
436
- # Returns a list with the names of all solved facts
459
+ # Returns a list with the names of all resolved facts
437
460
  # @return [Array] the list with all the fact names
438
461
  #
439
462
  # @api public
@@ -469,6 +492,18 @@ module Facter
469
492
 
470
493
  private
471
494
 
495
+ def queried_facts(user_query)
496
+ log_blocked_facts
497
+ resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
498
+ resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
499
+
500
+ if user_query.count.zero?
501
+ Facter::FactCollection.new.build_fact_collection!(resolved_facts)
502
+ else
503
+ FormatterHelper.retrieve_facts_to_display_for_user_query(user_query, resolved_facts)
504
+ end
505
+ end
506
+
472
507
  def resolve_facts_for_user_query(user_query)
473
508
  resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
474
509
  user_querie = resolved_facts.uniq(&:user_query).map(&:user_query).first
@@ -495,9 +530,9 @@ module Facter
495
530
  @logger ||= Log.new(self)
496
531
  end
497
532
 
498
- def init_cli_options(options, args)
533
+ def init_cli_options(options)
499
534
  options = options.map { |(k, v)| [k.to_sym, v] }.to_h
500
- Facter::Options.init_from_cli(options, args)
535
+ Facter::Options.init_from_cli(options)
501
536
  end
502
537
 
503
538
  def add_fact_to_searched_facts(user_query, value)
@@ -511,17 +546,16 @@ module Facter
511
546
  # @return [ResolvedFact]
512
547
  def resolve_fact(user_query)
513
548
  user_query = user_query.to_s
514
- resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
549
+ resolved_facts = Facter::FactManager.instance.resolve_fact(user_query)
515
550
  # we must make a distinction between custom facts that return nil and nil facts
516
551
  # Nil facts should not be packaged as ResolvedFacts! (add_fact_to_searched_facts packages facts)
517
552
  resolved_facts = resolved_facts.reject { |fact| fact.type == :nil }
518
553
  fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
519
- splitted_user_query = Facter::Utils.split_user_query(user_query)
520
554
 
521
555
  begin
522
- value = fact_collection.value(*splitted_user_query)
556
+ value = fact_collection.value(user_query)
523
557
  add_fact_to_searched_facts(user_query, value)
524
- rescue KeyError
558
+ rescue KeyError, TypeError
525
559
  nil
526
560
  end
527
561
  end
data/lib/facter/config.rb CHANGED
@@ -166,6 +166,7 @@ module Facter
166
166
  macosx_productversion
167
167
  macosx_productversion_major
168
168
  macosx_productversion_minor
169
+ macosx_productversion_patch
169
170
  windows_edition_id
170
171
  windows_installation_type
171
172
  windows_product_name
@@ -301,6 +302,7 @@ module Facter
301
302
  'macosx_productversion',
302
303
  'macosx_productversion_major',
303
304
  'macosx_productversion_minor',
305
+ 'macosx_productversion_patch',
304
306
  'manufacturer',
305
307
  'memoryfree',
306
308
  'memoryfree_mb',
@@ -53,6 +53,15 @@ module Facter
53
53
  # @api private
54
54
  attr_reader :fact
55
55
 
56
+ # Create a new aggregated resolution mechanism.
57
+ #
58
+ # @param name [String] The name of the resolution.
59
+ # @param fact [Facter::Fact] The fact to which this
60
+ # resolution will be added.
61
+ #
62
+ # @return [Facter::Util::Resolution] The created resolution
63
+ #
64
+ # @api private
56
65
  def initialize(name, fact)
57
66
  @name = name
58
67
  @fact = fact
@@ -94,11 +94,15 @@ module Facter
94
94
  end
95
95
  log_stderr(stderr, command, logger)
96
96
  rescue StandardError => e
97
- return '' if logger
97
+ message = "Failed while executing '#{command}': #{e.message}"
98
+ if logger
99
+ @log.debug(message)
100
+ return ''
101
+ end
102
+
98
103
  return on_fail unless on_fail == :raise
99
104
 
100
- raise Facter::Core::Execution::ExecutionFailure.new,
101
- "Failed while executing '#{command}': #{e.message}"
105
+ raise Facter::Core::Execution::ExecutionFailure.new, message
102
106
  end
103
107
 
104
108
  [out.strip, stderr]
@@ -11,6 +11,8 @@ module Facter
11
11
  module Core
12
12
  module Execution
13
13
  class Popen3
14
+ @log ||= Log.new(self)
15
+
14
16
  def self.popen_rune(cmd, opts, child_io, parent_io) # :nodoc:
15
17
  pid = spawn(*cmd, opts)
16
18
  child_io.each(&:close)
@@ -20,7 +22,17 @@ module Facter
20
22
  return yield(*result)
21
23
  ensure
22
24
  parent_io.each(&:close)
23
- Process.wait(pid)
25
+ begin
26
+ Process.wait(pid)
27
+ rescue Errno::ENOENT
28
+ # For some reason, the first Process.wait executed in JRuby
29
+ # always fails with ENOENT. However, the command output is
30
+ # filled in so we just need to silently continue.
31
+ # https://github.com/jruby/jruby/issues/5971
32
+ raise unless RUBY_PLATFORM == 'java'
33
+
34
+ @log.debug('Caught ENOENT during Process.wait on JRuby, continuing...')
35
+ end
24
36
  end
25
37
  end
26
38
  result
@@ -29,8 +29,8 @@ module Facter
29
29
  !!(path =~ ABSOLUTE_PATH_REGEX)
30
30
  end
31
31
 
32
- DOUBLE_QUOTED_COMMAND = /^"(.+?)"(?:\s+(.*))?/.freeze
33
- SINGLE_QUOTED_COMMAND = /^'(.+?)'(?:\s+(.*))?/.freeze
32
+ DOUBLE_QUOTED_COMMAND = /\A"(.+?)"(?:\s+(.*))?/.freeze
33
+ SINGLE_QUOTED_COMMAND = /\A'(.+?)'(?:\s+(.*))?/.freeze
34
34
 
35
35
  def expand_command(command)
36
36
  exe = nil
@@ -38,7 +38,7 @@ module Facter
38
38
  !!(path =~ ABSOLUTE_PATH_REGEX)
39
39
  end
40
40
 
41
- DOUBLE_QUOTED_COMMAND = /^"(.+?)"(?:\s+(.*))?/.freeze
41
+ DOUBLE_QUOTED_COMMAND = /\A"(.+?)"(?:\s+(.*))?/.freeze
42
42
 
43
43
  def expand_command(command)
44
44
  exe = nil
@@ -59,6 +59,17 @@ module LegacyFacter
59
59
  @on_flush_block&.call
60
60
  end
61
61
 
62
+ # Resolves the fact's value or loggs an error if the value
63
+ # couldn't be resolved.
64
+ #
65
+ # @raise Facter::ResolveCustomFactError if an error was raised
66
+ # (except Timeout::Error or Narmalization::NarmalizationError
67
+ # in which case an error message is logged and the execution
68
+ # isn't suspended).
69
+ #
70
+ # @return value (hash, string, int, array, etc) or nil
71
+ #
72
+ # @api private
62
73
  def value
63
74
  result = nil
64
75
 
@@ -106,6 +106,11 @@ module LegacyFacter
106
106
  @loaded = false
107
107
  end
108
108
 
109
+ def custom_fact(fact_name)
110
+ internal_loader.load(fact_name)
111
+ @custom_facts = @facts.select { |_k, v| v.options[:fact_type] == :custom }
112
+ end
113
+
109
114
  # Builds a hash of custom facts
110
115
  def custom_facts
111
116
  return @custom_facts if @valid_custom_facts
@@ -63,7 +63,7 @@ module LegacyFacter
63
63
  Facter.log_exception(Exception.new("Caching is enabled for group \"#{basename}\" while "\
64
64
  'there are at least two external facts files with the same filename'))
65
65
  else
66
- searched_fact = Facter::SearchedFact.new(basename, nil, [], nil, :file)
66
+ searched_fact = Facter::SearchedFact.new(basename, nil, nil, :file)
67
67
  searched_fact.file = file
68
68
  facts << searched_fact
69
69
  end
@@ -5,7 +5,10 @@ module LegacyFacter
5
5
  module Normalization
6
6
  class NormalizationError < StandardError; end
7
7
 
8
- VALID_TYPES = [Integer, Float, TrueClass, FalseClass, NilClass, Symbol, String, Array, Hash].freeze
8
+ # load Date and Time classes
9
+ require 'time'
10
+
11
+ VALID_TYPES = [Integer, Float, TrueClass, FalseClass, NilClass, Symbol, String, Array, Hash, Date, Time].freeze
9
12
 
10
13
  module_function
11
14
 
@@ -16,8 +19,10 @@ module LegacyFacter
16
19
  # @return [void]
17
20
  def normalize(value)
18
21
  case value
19
- when Integer, Float, TrueClass, FalseClass, NilClass, Symbol, Date
22
+ when Integer, Float, TrueClass, FalseClass, NilClass, Symbol
20
23
  value
24
+ when Date, Time
25
+ value.iso8601
21
26
  when String
22
27
  normalize_string(value)
23
28
  when Array
@@ -56,6 +56,8 @@ module Facter
56
56
  # Create a new resolution mechanism.
57
57
  #
58
58
  # @param name [String] The name of the resolution.
59
+ # @param fact [Facter::Fact] The fact to which this
60
+ # resolution will be added.
59
61
  #
60
62
  # @return [Facter::Util::Resolution] The created resolution
61
63
  #