facter 4.0.51 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate_cli.rb +7 -0
  3. data/lib/facter.rb +71 -58
  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 +17 -19
  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 +4 -4
  113. data/lib/facter/framework/formatters/formatter_helper.rb +3 -5
  114. data/lib/facter/framework/parsers/query_parser.rb +5 -12
  115. data/lib/facter/models/fact_collection.rb +48 -5
  116. data/lib/facter/models/resolved_fact.rb +2 -3
  117. data/lib/facter/models/searched_fact.rb +2 -3
  118. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  119. data/lib/facter/resolvers/aix/processors.rb +4 -0
  120. data/lib/facter/resolvers/az.rb +39 -0
  121. data/lib/facter/resolvers/base_resolver.rb +2 -2
  122. data/lib/facter/resolvers/dmi_decode.rb +0 -1
  123. data/lib/facter/resolvers/ec2.rb +8 -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/ffi/kernel_ffi.rb +1 -1
  143. data/lib/facter/resolvers/windows/identity.rb +1 -6
  144. data/lib/facter/resolvers/windows/processors.rb +41 -4
  145. data/lib/facter/resolvers/windows/uptime.rb +3 -22
  146. data/lib/facter/resolvers/windows/virtualization.rb +46 -44
  147. data/lib/facter/resolvers/xen.rb +6 -1
  148. data/lib/facter/templates/man.erb +13 -5
  149. data/lib/facter/util/facts/posix/virtual_detector.rb +74 -0
  150. data/lib/facter/util/facts/unit_converter.rb +2 -2
  151. data/lib/facter/util/linux/dhcp.rb +86 -0
  152. data/lib/facter/util/linux/if_inet6.rb +73 -0
  153. data/lib/facter/util/linux/routing_table.rb +60 -0
  154. data/lib/facter/util/linux/socket_parser.rb +114 -0
  155. data/lib/facter/util/resolvers/ffi/hostname.rb +70 -0
  156. data/lib/facter/util/resolvers/http.rb +7 -1
  157. data/lib/facter/util/resolvers/networking/primary_interface.rb +11 -5
  158. data/lib/facter/util/utils.rb +18 -1
  159. data/lib/facter/version.rb +1 -1
  160. metadata +77 -13
  161. data/lib/facter/facts/linux/cloud.rb +0 -15
  162. data/lib/facter/framework/core/fact_augmenter.rb +0 -37
  163. data/lib/facter/resolvers/cloud.rb +0 -39
  164. data/lib/facter/resolvers/networking_linux.rb +0 -296
  165. 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: db03b26f8336c77d444ced6b4d073a927b529e6272ef0ba65eafc69af0e66060
4
- data.tar.gz: a07adb46289f6315764d40a3f21c967de22c187fe9070177959a02c82bd1da6a
3
+ metadata.gz: 7d82b5638d66725eb654bb71a40be9e8faf9f98ab17200bc3340ec2a88416076
4
+ data.tar.gz: 2f6d868d28453ddf1fce7ce5cd24efce4365f5f7383980b6857f4771f7e8e22a
5
5
  SHA512:
6
- metadata.gz: 1cf1b38ac9c4e67b93e73474afa8f134132f0afd90d9cb5e45a4ced0c2cca3874ca581d1e6dd59ea154eb57e7ffc423a2a0c9aa1d36bdd04501648499dc30c3f
7
- data.tar.gz: 0567b4d6940087e0c0d273392b103bd507fe6f15adbcaa826d783db1eda0c512582da10031400a0360b76fa397150101e925b4f814b394bdc478b615a1d1c1d0
6
+ metadata.gz: 8a81868164b70e5f172354f3666c2d3c7cb8f8bf52ccbb4b8bd150ce097d771ad6c2df99f43401311d089eac5cb7404c90ec8cc7c2d074c062b7f2a66249be0f
7
+ data.tar.gz: 7de563f91031e60fd404bd00843f38a73c9782d1b816a997975db71bc0bca4a7302190fbded94559e0b1bc8613c32d950749fd2578b75d1518826d4b09958465
@@ -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,23 +27,32 @@ 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)
35
-
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, [])
42
- else
43
- cli.invoke(:arg_parser)
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)
44
41
  end
42
+
43
+ # user provided options
44
+ cli_options[:show_legacy] ||= false
45
+ Facter::Options.store(cli_options)
46
+
47
+ queried_facts(cli.args)
45
48
  end
46
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
47
56
  def puppet_facts
48
57
  require 'puppet'
49
58
 
@@ -110,10 +119,10 @@ module Facter
110
119
  nil
111
120
  end
112
121
 
113
- # Gets the value for a core fact, external or custom facts are
114
- # 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.
115
124
  #
116
- # @return [FactCollection] hash with fact names and values
125
+ # @return [FactCollection] A hash with fact names and values
117
126
  #
118
127
  # @api private
119
128
  def core_value(user_query)
@@ -198,14 +207,29 @@ module Facter
198
207
  Facter::Options[:debug] = debug_bool
199
208
  end
200
209
 
210
+ # Enable sequential resolving of facts
211
+ #
212
+ # @return [bool]
213
+ #
214
+ # @api public
201
215
  def enable_sequential
202
216
  Facter::Options[:sequential] = true
203
217
  end
204
218
 
219
+ # Disable sequential resolving of facts
220
+ #
221
+ # @return [bool]
222
+ #
223
+ # @api public
205
224
  def disable_sequential
206
225
  Facter::Options[:sequential] = false
207
226
  end
208
227
 
228
+ # Check if facts are resolved sequentially or not
229
+ #
230
+ # @return [bool]
231
+ #
232
+ # @api public
209
233
  def sequential?
210
234
  Facter::Options[:sequential]
211
235
  end
@@ -229,23 +253,6 @@ module Facter
229
253
  self
230
254
  end
231
255
 
232
- # Returns a fact object by name. If you use this, you still have to
233
- # call {Facter::Util::Fact#value `value`} on it to retrieve the actual
234
- # value.
235
- #
236
- # @param user_query [String] the name of the fact
237
- #
238
- # @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
239
- # is found.
240
- #
241
- # @api public
242
- def fact(user_query)
243
- user_query = user_query.to_s
244
- resolve_fact(user_query)
245
-
246
- @already_searched[user_query]
247
- end
248
-
249
256
  # Reset search paths for custom and external facts
250
257
  # If config file is set custom and external facts will be reloaded
251
258
  #
@@ -343,10 +350,10 @@ module Facter
343
350
  Options.custom_dir
344
351
  end
345
352
 
346
- # Gets a hash mapping fact names to their values
347
- # 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.
348
354
  #
349
- # @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
350
357
  #
351
358
  # @api public
352
359
  def to_hash
@@ -387,30 +394,25 @@ module Facter
387
394
  def value(user_query)
388
395
  user_query = user_query.to_s
389
396
  resolve_fact(user_query)
397
+
390
398
  @already_searched[user_query]&.value
391
399
  end
392
400
 
393
- # 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.
394
404
  #
395
- # @param options [Hash] parameters for the fact - attributes
396
- # of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
397
- # supplied here
398
- # @param user_queries [Array] the fact names
405
+ # @param user_query [String] the name of the fact
399
406
  #
400
- # @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.
401
409
  #
402
410
  # @api public
403
- def values(options, user_queries)
404
- init_cli_options(options, user_queries)
405
- log_blocked_facts
406
- resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
407
- 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)
408
414
 
409
- if user_queries.count.zero?
410
- Facter::FactCollection.new.build_fact_collection!(resolved_facts)
411
- else
412
- FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
413
- end
415
+ @already_searched[user_query]
414
416
  end
415
417
 
416
418
  # Returns Facter version
@@ -428,7 +430,7 @@ module Facter
428
430
  #
429
431
  # @api private
430
432
  def to_user_output(cli_options, *args)
431
- init_cli_options(cli_options, args)
433
+ init_cli_options(cli_options)
432
434
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
433
435
  logger.debug("Facter version: #{Facter::VERSION}")
434
436
  log_blocked_facts
@@ -454,7 +456,7 @@ module Facter
454
456
  nil
455
457
  end
456
458
 
457
- # Returns a list with the names of all solved facts
459
+ # Returns a list with the names of all resolved facts
458
460
  # @return [Array] the list with all the fact names
459
461
  #
460
462
  # @api public
@@ -490,6 +492,18 @@ module Facter
490
492
 
491
493
  private
492
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
+
493
507
  def resolve_facts_for_user_query(user_query)
494
508
  resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
495
509
  user_querie = resolved_facts.uniq(&:user_query).map(&:user_query).first
@@ -516,9 +530,9 @@ module Facter
516
530
  @logger ||= Log.new(self)
517
531
  end
518
532
 
519
- def init_cli_options(options, args)
533
+ def init_cli_options(options)
520
534
  options = options.map { |(k, v)| [k.to_sym, v] }.to_h
521
- Facter::Options.init_from_cli(options, args)
535
+ Facter::Options.init_from_cli(options)
522
536
  end
523
537
 
524
538
  def add_fact_to_searched_facts(user_query, value)
@@ -532,17 +546,16 @@ module Facter
532
546
  # @return [ResolvedFact]
533
547
  def resolve_fact(user_query)
534
548
  user_query = user_query.to_s
535
- resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
549
+ resolved_facts = Facter::FactManager.instance.resolve_fact(user_query)
536
550
  # we must make a distinction between custom facts that return nil and nil facts
537
551
  # Nil facts should not be packaged as ResolvedFacts! (add_fact_to_searched_facts packages facts)
538
552
  resolved_facts = resolved_facts.reject { |fact| fact.type == :nil }
539
553
  fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
540
- splitted_user_query = Facter::Utils.split_user_query(user_query)
541
554
 
542
555
  begin
543
- value = fact_collection.value(*splitted_user_query)
556
+ value = fact_collection.value(user_query)
544
557
  add_fact_to_searched_facts(user_query, value)
545
- rescue KeyError
558
+ rescue KeyError, TypeError
546
559
  nil
547
560
  end
548
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
  #
@@ -4,7 +4,8 @@ module LegacyFacter
4
4
  module Util
5
5
  module Root
6
6
  def self.root?
7
- Facter::Resolvers::Identity.resolve(:privileged)
7
+ require 'facter/resolvers/windows/ffi/identity_ffi'
8
+ IdentityFFI.privileged?
8
9
  end
9
10
  end
10
11
  end