facter 4.0.39 → 4.0.40

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1cc7c2dc4026c1c24f4140c319b3ac68c5b77dd1b42e61c46f07facff044380
4
- data.tar.gz: 3565addd16973284508cfc3058aab779dcf3bb30d4c65257fc9831cee898a380
3
+ metadata.gz: 64bb37710d33d522370161fab93516fed5961615ff3fc44609ee6700318efda4
4
+ data.tar.gz: 47e222b78a6a4ce13ee4d0fc91cbcca942b4b3c9357e35debbc2ea61d401867c
5
5
  SHA512:
6
- metadata.gz: ca715b689b8b050d20021ed104770a75737fed542236826592068d01066adfc369b222dbf94f2d1eb867c5b3d2023689f8ebd458f690f3f969e98c1c39375ddb
7
- data.tar.gz: cf6be422f902d75dcbf6fb6d147c3c95f718ab2129a18756b0ffe0626f3cfb3fd4f652a8c9f3278801826a7e15e35e9574cf11e22780593f79db315c6aa3b87b
6
+ metadata.gz: 4bb85c358a104d83fde58ad5ce0733736f5e2295324d1041e79d24c5c08cf284f2eb32c30b9024a5f216713b8a12a92a01249aab0346aec016ebeecc1c77d82f
7
+ data.tar.gz: 2f079a4fc5788d5e4c5698d0b5ad31cfc7affa352b19d636c077faa3125e342ba14e4d1c3d53a1684112cd9a76c27365fe9f2f9713502ea52b8d4ceffd56eee7
data/bin/facter CHANGED
@@ -4,8 +4,7 @@
4
4
  require 'pathname'
5
5
  require 'facter/framework/cli/cli_launcher.rb'
6
6
 
7
- cli_launcher = CliLauncher.new(ARGV)
7
+ Facter::OptionsValidator.validate(ARGV)
8
+ processed_arguments = CliLauncher.prepare_arguments(ARGV)
8
9
 
9
- cli_launcher.validate_options
10
- cli_launcher.prepare_arguments
11
- cli_launcher.start
10
+ CliLauncher.start(processed_arguments)
@@ -17,6 +17,27 @@ module Facter
17
17
  @warn_once = []
18
18
 
19
19
  class << self
20
+ def resolve(args_as_string)
21
+ require 'facter/framework/cli/cli_launcher'
22
+
23
+ args = args_as_string.split(' ')
24
+
25
+ Facter::OptionsValidator.validate(args)
26
+ processed_arguments = CliLauncher.prepare_arguments(args, nil)
27
+
28
+ cli = Facter::Cli.new([], processed_arguments)
29
+
30
+ if cli.args.include?(:version)
31
+ cli.invoke(:version, [])
32
+ elsif cli.args.include?('--list-cache-groups')
33
+ cli.invoke(:list_cache_groups, [])
34
+ elsif cli.args.include?('--list-block-groups')
35
+ cli.invoke(:list_block_groups, [])
36
+ else
37
+ cli.invoke(:arg_parser)
38
+ end
39
+ end
40
+
20
41
  def clear_messages
21
42
  logger.debug('clear_messages is not implemented')
22
43
  end
@@ -284,6 +305,18 @@ module Facter
284
305
  @already_searched[user_query]&.value
285
306
  end
286
307
 
308
+ def values(options, user_queries)
309
+ init_cli_options(options, user_queries)
310
+ resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
311
+ Facter::SessionCache.invalidate_all_caches
312
+
313
+ if user_queries.count.zero?
314
+ Facter::FactCollection.new.build_fact_collection!(resolved_facts)
315
+ else
316
+ FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
317
+ end
318
+ end
319
+
287
320
  # Returns Facter version
288
321
  #
289
322
  # @return [String] Current version
@@ -311,19 +344,13 @@ module Facter
311
344
  [fact_formatter.format(resolved_facts), status || 0]
312
345
  end
313
346
 
314
- def log_exception(exception, message = :default)
315
- arr = []
316
- if message == :default
317
- arr << exception.message
318
- elsif message
319
- arr << message
320
- end
321
- if Options[:trace]
322
- arr << 'backtrace:'
323
- arr.concat(exception.backtrace)
324
- end
347
+ def log_exception(exception, message = nil)
348
+ error_message = []
349
+
350
+ error_message << message.to_s unless message.nil? || (message.is_a?(String) && message.empty?)
325
351
 
326
- logger.error(arr.flatten.join("\n"))
352
+ parse_exception(exception, error_message)
353
+ logger.error(error_message.flatten.join("\n"))
327
354
  end
328
355
 
329
356
  # Returns a list with the names of all solved facts
@@ -365,6 +392,19 @@ module Facter
365
392
 
366
393
  private
367
394
 
395
+ def parse_exception(exception, error_message)
396
+ if exception.is_a?(Exception)
397
+ error_message << exception.message if error_message.empty?
398
+
399
+ if Options[:trace] && !exception.backtrace.nil?
400
+ error_message << 'backtrace:'
401
+ error_message.concat(exception.backtrace)
402
+ end
403
+ elsif error_message.empty?
404
+ error_message << exception.to_s
405
+ end
406
+ end
407
+
368
408
  def logger
369
409
  @logger ||= Log.new(self)
370
410
  end
@@ -59,7 +59,7 @@ module LegacyFacter
59
59
  basename = File.basename(file)
60
60
  next if file_blocked?(basename)
61
61
 
62
- if facts.find { |f| f.name == basename } && cm.group_cached?(basename)
62
+ if facts.find { |f| f.name == basename } && cm.fact_cache_enabled?(basename)
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
@@ -24,7 +24,7 @@ module Facts
24
24
 
25
25
  def add_legacy_facts(disks, facts)
26
26
  disks.each do |disk_name, disk_info|
27
- facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy))
27
+ facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes], :legacy))
28
28
  end
29
29
  end
30
30
  end
@@ -35,7 +35,8 @@ module Facts
35
35
  product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
36
36
  return unless product_name
37
37
 
38
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
38
+ _, value = Facter::FactsUtils::HYPERVISORS_HASH.find { |key, _value| product_name.include?(key) }
39
+ value
39
40
  end
40
41
 
41
42
  def check_bios_vendor
@@ -33,7 +33,8 @@ module Facts
33
33
  product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
34
34
  return unless product_name
35
35
 
36
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
36
+ _, value = Facter::FactsUtils::HYPERVISORS_HASH.find { |key, _value| product_name.include?(key) }
37
+ value
37
38
  end
38
39
 
39
40
  def check_bios_vendor
@@ -24,7 +24,7 @@ module Facts
24
24
 
25
25
  def add_legacy_facts(disks, facts)
26
26
  disks.each do |disk_name, disk_info|
27
- facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy))
27
+ facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes], :legacy))
28
28
  facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_vendor", disk_info[:vendor], :legacy))
29
29
  end
30
30
  end
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'thor'
5
+
4
6
  module Facter
5
7
  class Cli < Thor
6
- check_unknown_options!
7
-
8
8
  class_option :color,
9
9
  type: :boolean,
10
10
  desc: 'Enable color output.'
11
11
 
12
+ class_option :no_color,
13
+ type: :boolean,
14
+ desc: 'Disable color output.'
15
+
12
16
  class_option :config,
13
17
  aliases: '-c',
14
18
  type: :string,
@@ -29,17 +33,6 @@ module Facter
29
33
  repeatable: true,
30
34
  desc: 'A directory to use for external facts.'
31
35
 
32
- class_option :help,
33
- hide: true,
34
- aliases: '-h',
35
- type: :boolean,
36
- desc: 'Print this help message.'
37
-
38
- class_option :man,
39
- hide: true,
40
- type: :boolean,
41
- desc: 'Display manual.'
42
-
43
36
  class_option :hocon,
44
37
  type: :boolean,
45
38
  desc: 'Output in Hocon format.'
@@ -49,36 +42,28 @@ module Facter
49
42
  type: :boolean,
50
43
  desc: 'Output in JSON format.'
51
44
 
52
- class_option :list_block_groups,
53
- type: :boolean,
54
- desc: 'List the names of all blockable fact groups.'
55
-
56
- class_option :list_cache_groups,
57
- type: :boolean,
58
- desc: 'List the names of all cacheable fact groups.'
59
-
60
45
  class_option :log_level,
61
46
  aliases: '-l',
62
47
  type: :string,
63
48
  desc: 'Set logging level. Supported levels are: none, trace, debug, info, warn, error, and fatal.'
64
49
 
65
- class_option :block,
50
+ class_option :no_block,
66
51
  type: :boolean,
67
52
  desc: 'Disable fact blocking.'
68
53
 
69
- class_option :cache,
54
+ class_option :no_cache,
70
55
  type: :boolean,
71
56
  desc: 'Disable loading and refreshing facts from the cache'
72
57
 
73
- class_option :custom_facts,
58
+ class_option :no_custom_facts,
74
59
  type: :boolean,
75
60
  desc: 'Disable custom facts.'
76
61
 
77
- class_option :external_facts,
62
+ class_option :no_external_facts,
78
63
  type: :boolean,
79
64
  desc: 'Disable external facts.'
80
65
 
81
- class_option :ruby,
66
+ class_option :no_ruby,
82
67
  type: :boolean,
83
68
  desc: 'Disable loading Ruby, facts requiring Ruby, and custom facts.'
84
69
 
@@ -90,6 +75,11 @@ module Facter
90
75
  type: :boolean,
91
76
  desc: 'Enable verbose (info) output.'
92
77
 
78
+ class_option :puppet,
79
+ type: :boolean,
80
+ aliases: '-p',
81
+ desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
82
+
93
83
  class_option :show_legacy,
94
84
  type: :boolean,
95
85
  desc: 'Show legacy facts when querying all facts.'
@@ -103,17 +93,12 @@ module Facter
103
93
  type: :boolean,
104
94
  desc: 'Enable more aggressive error reporting.'
105
95
 
106
- class_option :puppet,
107
- type: :boolean,
108
- aliases: '-p',
109
- desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
110
-
111
96
  class_option :timing,
112
97
  type: :boolean,
113
98
  aliases: '-t',
114
99
  desc: 'Show how much time it took to resolve each fact'
115
100
 
116
- desc '--man', 'Manual', hide: true
101
+ desc '--man', 'Display manual.', hide: true
117
102
  map ['--man'] => :man
118
103
  def man(*args)
119
104
  require 'erb'
@@ -126,7 +111,6 @@ module Facter
126
111
  end
127
112
 
128
113
  desc 'query', 'Default method', hide: true
129
- desc '[options] [query] [query] [...]', ''
130
114
  def query(*args)
131
115
  output, status = Facter.to_user_output(@options, *args)
132
116
  puts output
@@ -135,13 +119,21 @@ module Facter
135
119
  exit status
136
120
  end
137
121
 
122
+ desc 'arg_parser', 'Parse arguments', hide: true
123
+ def arg_parser(*args)
124
+ # ignore unknown options
125
+ args.reject! { |arg| arg.start_with?('-') }
126
+
127
+ Facter.values(@options, args)
128
+ end
129
+
138
130
  desc '--version, -v', 'Print the version', hide: true
139
131
  map ['--version', '-v'] => :version
140
- def version
132
+ def version(*_args)
141
133
  puts Facter::VERSION
142
134
  end
143
135
 
144
- desc '--list-block-groups', 'List block groups', hide: true
136
+ desc '--list-block-groups', 'List block groups'
145
137
  map ['--list-block-groups'] => :list_block_groups
146
138
  def list_block_groups(*args)
147
139
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
@@ -153,7 +145,7 @@ module Facter
153
145
  puts block_groups
154
146
  end
155
147
 
156
- desc '--list-cache-groups', 'List cache groups', hide: true
148
+ desc '--list-cache-groups', 'List cache groups'
157
149
  map ['--list-cache-groups'] => :list_cache_groups
158
150
  def list_cache_groups(*args)
159
151
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
@@ -165,6 +157,61 @@ module Facter
165
157
  puts cache_groups
166
158
  end
167
159
 
160
+ desc 'help', 'Help for all arguments'
161
+ def help(*args)
162
+ help_string = +''
163
+ help_string << help_header(args)
164
+ help_string << add_class_options_to_help
165
+ help_string << add_commands_to_help
166
+
167
+ puts help_string
168
+ end
169
+
170
+ no_commands do
171
+ def help_header(_args)
172
+ path = File.join(File.dirname(__FILE__), '../../')
173
+
174
+ Util::FileHelper.safe_read("#{path}fixtures/facter_help_header")
175
+ end
176
+
177
+ IGNORE_OPTIONS = %w[log_level color no_color].freeze
178
+
179
+ def add_class_options_to_help
180
+ help_class_options = +''
181
+ class_options = Cli.class_options
182
+ class_options.each do |class_option|
183
+ option = class_option[1]
184
+ next if option.hide
185
+
186
+ help_class_options << build_option(option.name, option.aliases, option.description)
187
+ end
188
+
189
+ help_class_options
190
+ end
191
+
192
+ def add_commands_to_help
193
+ help_command_options = +''
194
+ Cli.commands
195
+ .select { |_k, command_class| command_class.instance_of?(Thor::Command) }
196
+ .each do |_k, command|
197
+ help_command_options << build_option(command['name'], [], command['description'])
198
+ end
199
+
200
+ help_command_options
201
+ end
202
+
203
+ def build_option(name, aliases, description)
204
+ help_option = +''
205
+ help_option << aliases.join(',').rjust(10)
206
+ help_option << ' '
207
+ help_option << "[--#{name}]".ljust(30)
208
+ help_option << " #{description}"
209
+ help_option << "\n"
210
+
211
+ help_option
212
+ end
213
+ end
214
+
168
215
  def self.exit_on_failure?
169
216
  true
170
217
  end
@@ -1,59 +1,55 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'thor'
5
4
  require 'facter/framework/logging/logger.rb'
6
5
  Facter::Log.output(STDERR)
7
6
  require 'facter'
8
7
  require 'facter/framework/cli/cli'
9
8
 
10
9
  class CliLauncher
11
- def initialize(args)
12
- @args = args
13
- end
14
-
15
- def validate_options
16
- Facter::OptionsValidator.validate(@args)
17
- end
10
+ class << self
11
+ def prepare_arguments(args, task = Facter::Cli.default_task)
12
+ args.unshift(task) unless
13
+ check_if_arguments_is_known(Facter::Cli.all_tasks, args) ||
14
+ check_if_arguments_is_known(Facter::Cli.instance_variable_get(:@map), args) ||
15
+ !task
16
+
17
+ reorder_program_arguments(args)
18
+ end
18
19
 
19
- def prepare_arguments
20
- @args.unshift(Facter::Cli.default_task) unless
21
- check_if_arguments_is_known(Facter::Cli.all_tasks, @args) ||
22
- check_if_arguments_is_known(Facter::Cli.instance_variable_get(:@map), @args)
20
+ def start(args)
21
+ # stop parsing arguments if we don't recognize them
22
+ Thor.check_unknown_options!
23
+ Facter::Cli.start(args, debug: true)
24
+ rescue Thor::UnknownArgumentError => e
25
+ Facter::OptionsValidator.write_error_and_exit("unrecognised option '#{e.unknown.first}'")
26
+ end
23
27
 
24
- @args = reorder_program_arguments(@args)
25
- end
28
+ private
26
29
 
27
- def start
28
- Facter::Cli.start(@args, debug: true)
29
- rescue Thor::UnknownArgumentError => e
30
- Facter::OptionsValidator.write_error_and_exit("unrecognised option '#{e.unknown.first}'")
31
- end
32
-
33
- private
30
+ def check_if_arguments_is_known(known_arguments, program_arguments)
31
+ program_arguments.each do |argument|
32
+ return true if known_arguments.key?(argument)
33
+ end
34
34
 
35
- def check_if_arguments_is_known(known_arguments, program_arguments)
36
- program_arguments.each do |argument|
37
- return true if known_arguments.key?(argument)
35
+ false
38
36
  end
39
37
 
40
- false
41
- end
42
-
43
- def reorder_program_arguments(program_arguments)
44
- priority_arguments = Facter::Cli.instance_variable_get(:@map)
38
+ def reorder_program_arguments(program_arguments)
39
+ priority_arguments = Facter::Cli.instance_variable_get(:@map)
45
40
 
46
- priority_args = []
47
- normal_args = []
41
+ priority_args = []
42
+ normal_args = []
48
43
 
49
- program_arguments.each do |argument|
50
- if priority_arguments.include?(argument)
51
- priority_args << argument
52
- else
53
- normal_args << argument
44
+ program_arguments.each do |argument|
45
+ if priority_arguments.include?(argument)
46
+ priority_args << argument
47
+ else
48
+ normal_args << argument
49
+ end
54
50
  end
55
- end
56
51
 
57
- priority_args.concat(normal_args)
52
+ priority_args.concat(normal_args)
53
+ end
58
54
  end
59
55
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Facter
4
4
  class FactGroups
5
- attr_reader :groups, :block_list
5
+ attr_reader :groups, :block_list, :facts_ttls
6
6
 
7
7
  @groups_ttls = []
8
8
 
@@ -14,6 +14,10 @@ module Facter
14
14
  @groups ||= File.readable?(@groups_file_path) ? Hocon.load(@groups_file_path) : {}
15
15
  load_groups
16
16
  load_groups_from_options
17
+ load_facts_ttls
18
+
19
+ # Reverse sort facts so that children have precedence when caching. eg: os.macosx vs os
20
+ @facts_ttls = @facts_ttls.sort.reverse.to_h
17
21
  end
18
22
 
19
23
  # Breakes down blocked groups in blocked facts
@@ -31,6 +35,9 @@ module Facter
31
35
 
32
36
  # Get the group name a fact is part of
33
37
  def get_fact_group(fact_name)
38
+ fact = get_fact(fact_name)
39
+ return fact[:group] if fact
40
+
34
41
  @groups.detect { |k, v| break k if Array(v).find { |f| fact_name =~ /^#{f}.*/ } }
35
42
  end
36
43
 
@@ -41,6 +48,15 @@ module Facter
41
48
  ttls_to_seconds(ttls[group_name])
42
49
  end
43
50
 
51
+ def get_fact(fact_name)
52
+ return @facts_ttls[fact_name] if @facts_ttls[fact_name]
53
+
54
+ result = @facts_ttls.select { |name, fact| break fact if fact_name =~ /^#{name}\..*/ }
55
+ return nil if result == {}
56
+
57
+ result
58
+ end
59
+
44
60
  private
45
61
 
46
62
  def load_groups_from_options
@@ -55,10 +71,28 @@ module Facter
55
71
  end
56
72
  end
57
73
 
74
+ def load_facts_ttls
75
+ @facts_ttls ||= {}
76
+ return if @groups_ttls == []
77
+
78
+ @groups_ttls.reduce(:merge).each do |group, ttls|
79
+ ttls = ttls_to_seconds(ttls)
80
+ if @groups[group]
81
+ @groups[group].each do |fact|
82
+ if (@facts_ttls[fact] && @facts_ttls[fact][:ttls] < ttls) || @facts_ttls[fact].nil?
83
+ @facts_ttls[fact] = { ttls: ttls, group: group }
84
+ end
85
+ end
86
+ else
87
+ @facts_ttls[group] = { ttls: ttls, group: group }
88
+ end
89
+ end
90
+ end
91
+
58
92
  def load_groups
59
93
  config = ConfigReader.init(Options[:config])
60
94
  @block_list = config.block_list || {}
61
- @groups_ttls = config.ttls || {}
95
+ @groups_ttls = config.ttls || []
62
96
  @groups.merge!(config.fact_groups) if config.fact_groups
63
97
  end
64
98
 
@@ -40,31 +40,42 @@ module Facter
40
40
  end
41
41
  end
42
42
 
43
- def group_cached?(group_name)
44
- cached = @fact_groups.get_group_ttls(group_name) ? true : false
45
- delete_cache(group_name) unless cached
43
+ def fact_cache_enabled?(fact_name)
44
+ fact = @fact_groups.get_fact(fact_name)
45
+ cached = if fact
46
+ !fact[:ttls].nil?
47
+ else
48
+ false
49
+ end
50
+
51
+ fact_group = @fact_groups.get_fact_group(fact_name)
52
+ delete_cache(fact_group) if fact_group && !cached
46
53
  cached
47
54
  end
48
55
 
49
56
  private
50
57
 
51
58
  def resolve_fact(searched_fact)
52
- group_name = if searched_fact.file
53
- searched_fact.name
54
- else
55
- @fact_groups.get_fact_group(searched_fact.name)
56
- end
59
+ return unless fact_cache_enabled?(searched_fact.name)
57
60
 
58
- return unless group_name
61
+ fact = if searched_fact.file
62
+ @fact_groups.get_fact(File.basename(searched_fact.file))
63
+ else
64
+ @fact_groups.get_fact(searched_fact.name)
65
+ end
59
66
 
60
- return unless group_cached?(group_name)
67
+ return unless fact
61
68
 
62
- return unless check_ttls?(group_name)
69
+ return unless check_ttls?(fact[:group], fact[:ttls])
63
70
 
64
- data = read_group_json(group_name)
71
+ read_fact(searched_fact, fact[:group])
72
+ end
73
+
74
+ def read_fact(searched_fact, fact_group)
75
+ data = read_group_json(fact_group)
65
76
  return unless data
66
77
 
67
- @log.debug("loading cached values for #{group_name} facts")
78
+ @log.debug("loading cached values for #{searched_fact.name} facts")
68
79
 
69
80
  create_facts(searched_fact, data)
70
81
  end
@@ -93,7 +104,7 @@ module Facter
93
104
  end
94
105
  return if !group_name || fact.value.nil?
95
106
 
96
- return unless group_cached?(group_name)
107
+ return unless fact_cache_enabled?(fact.name)
97
108
 
98
109
  @groups[group_name] ||= {}
99
110
  @groups[group_name][fact.name] = fact.value
@@ -106,10 +117,12 @@ module Facter
106
117
  end
107
118
 
108
119
  @groups.each do |group_name, data|
109
- next unless check_ttls?(group_name)
120
+ next unless check_ttls?(group_name, @fact_groups.get_group_ttls(group_name))
110
121
 
111
- @log.debug("caching values for #{group_name} facts")
112
122
  cache_file_name = File.join(@cache_dir, group_name)
123
+ next if File.readable?(cache_file_name)
124
+
125
+ @log.debug("caching values for #{group_name} facts")
113
126
  File.write(cache_file_name, JSON.pretty_generate(data))
114
127
  end
115
128
  end
@@ -128,8 +141,7 @@ module Facter
128
141
  @groups[group_name] = data
129
142
  end
130
143
 
131
- def check_ttls?(group_name)
132
- ttls = @fact_groups.get_group_ttls(group_name)
144
+ def check_ttls?(group_name, ttls)
133
145
  return false unless ttls
134
146
 
135
147
  cache_file_name = File.join(@cache_dir, group_name)
@@ -20,45 +20,48 @@ module Facter
20
20
 
21
21
  @facts = []
22
22
  @external_facts = []
23
- load_internal_facts(options)
24
- load_external_facts(options)
25
23
 
26
- @facts
24
+ @internal_facts = load_internal_facts(options)
25
+ @external_facts = load_external_facts(options)
26
+
27
+ @facts = @internal_facts + @external_facts
27
28
  end
28
29
 
29
30
  private
30
31
 
31
32
  def load_internal_facts(options)
32
33
  @log.debug('Loading internal facts')
34
+ internal_facts = []
33
35
 
34
36
  if options[:user_query] || options[:show_legacy]
35
37
  # if we have a user query, then we must search in core facts and legacy facts
36
38
  @log.debug('Loading all internal facts')
37
- @internal_facts = @internal_loader.facts
39
+ internal_facts = @internal_loader.facts
38
40
  else
39
41
  @log.debug('Load only core facts')
40
- @internal_facts = @internal_loader.core_facts
42
+ internal_facts = @internal_loader.core_facts
41
43
  end
42
44
 
43
- @internal_facts = block_facts(@internal_facts, options)
44
- @facts.concat(@internal_facts)
45
+ block_facts(internal_facts, options)
45
46
  end
46
47
 
47
48
  def load_external_facts(options)
48
49
  @log.debug('Loading external facts')
50
+ external_facts = []
51
+
49
52
  if options[:custom_facts]
50
53
  @log.debug('Loading custom facts')
51
- @external_facts.concat(@external_fact_loader.custom_facts)
54
+ external_facts += @external_fact_loader.custom_facts
52
55
  end
53
56
 
54
- @external_facts = block_facts(@external_facts, options)
57
+ external_facts = block_facts(external_facts, options)
55
58
 
56
59
  if options[:external_facts]
57
60
  @log.debug('Loading external facts')
58
- @external_facts.concat(@external_fact_loader.external_facts)
61
+ external_facts += @external_fact_loader.external_facts
59
62
  end
60
63
 
61
- @facts.concat(@external_facts)
64
+ external_facts
62
65
  end
63
66
 
64
67
  def block_facts(facts, options)
@@ -46,7 +46,9 @@ module Facter
46
46
  return unless file_global_conf
47
47
 
48
48
  if Options.cli?
49
- @options[:custom_facts] = !file_global_conf['no-custom-facts'] unless file_global_conf['no-custom-facts'].nil?
49
+ unless file_global_conf['no-custom-facts'].nil?
50
+ @options[:no_custom_facts] = file_global_conf['no-custom-facts']
51
+ end
50
52
  end
51
53
 
52
54
  @options[:custom_dir] = file_global_conf['custom-dir'] unless file_global_conf['custom-dir'].nil?
@@ -57,7 +59,7 @@ module Facter
57
59
  return unless global_conf
58
60
 
59
61
  if Options.cli?
60
- @options[:external_facts] = !global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
62
+ @options[:no_external_facts] = global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
61
63
  end
62
64
 
63
65
  @options[:external_dir] = [global_conf['external-dir']].flatten unless global_conf['external-dir'].nil?
@@ -67,7 +69,7 @@ module Facter
67
69
  def augment_ruby(global_conf)
68
70
  return unless global_conf
69
71
 
70
- @options[:ruby] = global_conf['no-ruby'].nil? ? true : !global_conf['no-ruby']
72
+ @options[:no_ruby] = global_conf['no-ruby'].nil? ? false : global_conf['no-ruby']
71
73
  end
72
74
 
73
75
  def augment_show_legacy(global_conf)
@@ -22,14 +22,14 @@ module Facter
22
22
  @user_query = []
23
23
  @block_list = {}
24
24
  @fact_groups = {}
25
- @color = false
25
+ @color = true
26
26
  @timing = false
27
27
 
28
28
  class << self
29
- attr_reader :debug, :verbose, :log_level, :show_legacy, :ruby,
30
- :custom_facts, :blocked_facts
29
+ attr_reader :debug, :verbose, :log_level, :show_legacy,
30
+ :custom_facts, :blocked_facts, :ruby, :external_facts
31
31
 
32
- attr_accessor :config, :user_query, :strict, :json, :haml, :external_facts,
32
+ attr_accessor :config, :user_query, :strict, :json, :haml,
33
33
  :cache, :yaml, :puppet, :ttls, :block, :cli, :config_file_custom_dir,
34
34
  :config_file_external_dir, :default_external_dir, :fact_groups,
35
35
  :block_list, :color, :trace, :timing
@@ -45,16 +45,28 @@ module Facter
45
45
  options
46
46
  end
47
47
 
48
- def ruby=(bool)
49
- if bool == true
50
- @ruby = true
51
- else
48
+ def no_ruby=(bool)
49
+ if bool
52
50
  @ruby = false
53
51
  @custom_facts = false
54
52
  @blocked_facts << 'ruby'
53
+ else
54
+ @ruby = true
55
55
  end
56
56
  end
57
57
 
58
+ def no_block=(bool)
59
+ @block = !bool
60
+ end
61
+
62
+ def no_cache=(bool)
63
+ @cache = !bool
64
+ end
65
+
66
+ def no_color=(bool)
67
+ @color = !bool
68
+ end
69
+
58
70
  def external_dir
59
71
  return fallback_external_dir if @external_dir.empty? && @external_facts
60
72
 
@@ -99,8 +111,8 @@ module Facter
99
111
  end
100
112
  end
101
113
 
102
- def custom_facts=(bool)
103
- if bool == true
114
+ def no_custom_facts=(bool)
115
+ if bool == false
104
116
  @custom_facts = true
105
117
  @ruby = true
106
118
  else
@@ -108,6 +120,10 @@ module Facter
108
120
  end
109
121
  end
110
122
 
123
+ def no_external_facts=(bool)
124
+ @external_facts = !bool
125
+ end
126
+
111
127
  def log_level=(level)
112
128
  level = level.to_sym
113
129
  case level
@@ -156,6 +172,7 @@ module Facter
156
172
  @custom_facts = true
157
173
  @external_dir = []
158
174
  @default_external_dir = []
175
+ @config_file_external_dir = []
159
176
  @external_facts = true
160
177
  @blocked_facts = []
161
178
  @fact_groups = {}
@@ -91,9 +91,7 @@ module Facter
91
91
  def error(msg, colorize = false)
92
92
  @@has_errors = true
93
93
 
94
- if msg.nil? || msg.empty?
95
- empty_message_error(msg)
96
- elsif @@message_callback
94
+ if @@message_callback
97
95
  @@message_callback.call(:error, msg)
98
96
  else
99
97
  msg = colorize(msg, RED) if colorize || Options[:color]
@@ -111,8 +109,6 @@ module Facter
111
109
  private
112
110
 
113
111
  def colorize(msg, color)
114
- return msg if OsDetector.instance.identifier.eql?(:windows)
115
-
116
112
  "#{color}#{msg}#{RESET}"
117
113
  end
118
114
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.0.39' unless defined?(VERSION)
4
+ VERSION = '4.0.40' 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.0.39
4
+ version: 4.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler