facter 4.2.4 → 4.2.5

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: ee51134133739cd64ee9fb160993ddd8ec683af8a2893aa98744709398d7ffce
4
- data.tar.gz: d5bf29fc2338094cc267949431222af0cfa186f25998413dc6d50d14af5aafaa
3
+ metadata.gz: 5fa80567c0c01b5ceed0181b78f9e9e813d4eea3c70905733ba1aa5e9298ad15
4
+ data.tar.gz: 1541ade4a87eacbbaa569c0ace340312dfde0c8299b12cd1973d8861449a798f
5
5
  SHA512:
6
- metadata.gz: 71a0943be14cca0cfc2a1cde31f10deae26fad0c2cc845dec8ba981e86c33b97278adc424a92b301b868fddb6213024431fec51a44f090913de58937865906ed
7
- data.tar.gz: 13fbe6fc74dccb348d67c274861bf89fce18d4e792801546b63c4b1f260c270afc338fddf355166b27e1bef5c5484541655c70e4c8e7bfcc39468d94ae247d8e
6
+ metadata.gz: ea3608714cc012b4f64de7f4b472c904152e82387b980d7b3740a318b3b500228dc2e57a41bab27c113d7d6cb9ce8985394d69db2c6ef49d0fd1483b0608b220
7
+ data.tar.gz: 33f8a676b5a70c964f90f2576e4b1a65d5e2b27c9b2b09edd12145f77da20f303ab295ee3de1998aed74eff967e4765ac0ad48a885a9ffbe175bbda2f6ce3b20
@@ -42,7 +42,7 @@ module Facter
42
42
  end
43
43
 
44
44
  def execute(command, options = {})
45
- on_fail, expand, logger, time_limit = extract_options(options)
45
+ on_fail, expand, logger, timeout = extract_options(options)
46
46
 
47
47
  expanded_command = if !expand && builtin_command?(command) || logger
48
48
  command
@@ -59,12 +59,12 @@ module Facter
59
59
  return on_fail
60
60
  end
61
61
 
62
- out, = execute_command(expanded_command, on_fail, logger, time_limit)
62
+ out, = execute_command(expanded_command, on_fail, logger, timeout)
63
63
  out
64
64
  end
65
65
 
66
- def execute_command(command, on_fail = nil, logger = nil, time_limit = nil)
67
- time_limit ||= 300
66
+ def execute_command(command, on_fail = nil, logger = nil, timeout = nil)
67
+ timeout ||= 300
68
68
  begin
69
69
  # Set LC_ALL and LANG to force i18n to C for the duration of this exec;
70
70
  # this ensures that any code that parses the
@@ -78,12 +78,12 @@ module Facter
78
78
  out_reader = Thread.new { stdout.read }
79
79
  err_reader = Thread.new { stderr.read }
80
80
  begin
81
- Timeout.timeout(time_limit) do
81
+ Timeout.timeout(timeout) do
82
82
  stdout_messages << out_reader.value
83
83
  stderr_messages << err_reader.value
84
84
  end
85
85
  rescue Timeout::Error
86
- message = "Timeout encounter after #{time_limit}s, killing process with pid: #{pid}"
86
+ message = "Timeout encounter after #{timeout}s, killing process with pid: #{pid}"
87
87
  Process.kill('KILL', pid)
88
88
  on_fail == :raise ? (raise StandardError, message) : @log.debug(message)
89
89
  ensure
@@ -114,10 +114,15 @@ module Facter
114
114
  on_fail = options.fetch(:on_fail, :raise)
115
115
  expand = options.fetch(:expand, true)
116
116
  logger = options[:logger]
117
- time_limit = options[:limit].to_i
118
- time_limit = time_limit.positive? ? time_limit : nil
117
+ timeout = (options[:timeout] || options[:time_limit] || options[:limit]).to_i
118
+ timeout = timeout.positive? ? timeout : nil
119
119
 
120
- [on_fail, expand, logger, time_limit]
120
+ extra_keys = options.keys - %i[on_fail expand logger timeout]
121
+ unless extra_keys.empty?
122
+ @log.warn("Unexpected key passed to Facter::Core::Execution.execute option: #{options.keys.join(',')}")
123
+ end
124
+
125
+ [on_fail, expand, logger, timeout]
121
126
  end
122
127
 
123
128
  def log_stderr(msg, command, logger)
@@ -15,9 +15,9 @@ module Facter
15
15
 
16
16
  module_function
17
17
 
18
- # Returns the locations to be searched when looking for a binary. This
19
- # is currently determined by the +PATH+ environment variable plus
20
- # `/sbin` and `/usr/sbin` when run on unix
18
+ # Returns the locations to be searched when looking for a binary. This is
19
+ # currently determined by the +PATH+ environment variable plus `/sbin`
20
+ # and `/usr/sbin` when run on unix
21
21
  #
22
22
  # @return [Array<String>] The paths to be searched for binaries
23
23
  #
@@ -27,8 +27,9 @@ module Facter
27
27
  end
28
28
 
29
29
  # Determines the full path to a binary. If the supplied filename does not
30
- # already describe an absolute path then different locations (determined
31
- # by {search_paths}) will be searched for a match.
30
+ # already describe an absolute path then different locations (determined
31
+ # by {search_paths}) will be searched for a match.
32
+ #
32
33
  # @param bin [String] The executable to locate
33
34
  #
34
35
  # @return [String/nil] The full path to the executable or nil if not
@@ -40,7 +41,8 @@ module Facter
40
41
  end
41
42
 
42
43
  # Determine in a platform-specific way whether a path is absolute. This
43
- # defaults to the local platform if none is specified.
44
+ # defaults to the local platform if none is specified.
45
+ #
44
46
  # @param path [String] The path to check
45
47
 
46
48
  # @param platform [:posix/:windows/nil] The platform logic to use
@@ -58,8 +60,9 @@ module Facter
58
60
  end
59
61
 
60
62
  # Given a command line, this returns the command line with the
61
- # executable written as an absolute path. If the executable contains
62
- # spaces, it has to be put in double quotes to be properly recognized.
63
+ # executable written as an absolute path. If the executable contains
64
+ # spaces, it has to be put in double quotes to be properly recognized.
65
+ #
63
66
  # @param command [String] the command line
64
67
  #
65
68
  # @return [String/nil] The command line with the executable's path
@@ -71,8 +74,9 @@ module Facter
71
74
  end
72
75
 
73
76
  # Overrides environment variables within a block of code. The
74
- # specified values will be set for the duration of the block, after
75
- # which the original values (if any) will be restored.
77
+ # specified values will be set for the duration of the block, after
78
+ # which the original values (if any) will be restored.
79
+ #
76
80
  # @param values [Hash<String=>String>] A hash of the environment
77
81
  # variables to override
78
82
  #
@@ -84,6 +88,7 @@ module Facter
84
88
  end
85
89
 
86
90
  # Try to execute a command and return the output.
91
+ #
87
92
  # @param command [String] Command to run
88
93
  #
89
94
  # @return [String/nil] Output of the program, or nil if the command does
@@ -96,16 +101,18 @@ module Facter
96
101
  end
97
102
 
98
103
  # Execute a command and return the output of that program.
104
+ #
99
105
  # @param command [String] Command to run
100
106
  #
101
107
  # @param options [Hash] Hash with options for the command
102
108
  #
103
- # Options accepted values :on_fail How to behave when the command could
109
+ # @option options [Object] :on_fail How to behave when the command could
104
110
  # not be run. Specifying :raise will raise an error, anything else will
105
111
  # return that object on failure. Default is :raise.
106
- # :logger Optional logger used to log the command's stderr.
107
- # :time_limit Optional time out for the specified command. If no time_limit is passed,
108
- # a default of 300 seconds is used.
112
+ # @option options [Object] :logger Optional logger used to log the
113
+ # command's stderr.
114
+ # @option options :timeout Optional time out for the specified
115
+ # command. If no timeout is passed, a default of 300 seconds is used.
109
116
  #
110
117
  # @raise [Facter::Core::Execution::ExecutionFailure] If the command does
111
118
  # not exist or could not be executed and :on_fail is set to :raise
@@ -119,13 +126,14 @@ module Facter
119
126
  end
120
127
 
121
128
  # Execute a command and return the stdout and stderr of that program.
129
+ #
122
130
  # @param command [String] Command to run
123
131
  #
124
132
  # @param on_fail[Object] How to behave when the command could
125
133
  # not be run. Specifying :raise will raise an error, anything else will
126
134
  # return that object on failure. Default is :raise.
127
135
  # @param logger Optional logger used to log the command's stderr.
128
- # @param time_limit Optional time out for the specified command. If no time_limit is passed,
136
+ # @param timeout Optional time out for the specified command. If no timeout is passed,
129
137
  # a default of 300 seconds is used.
130
138
  #
131
139
  # @raise [Facter::Core::Execution::ExecutionFailure] If the command does
@@ -135,8 +143,8 @@ module Facter
135
143
  # :on_fail if command execution failed and :on_fail was specified.
136
144
  #
137
145
  # @api private
138
- def execute_command(command, on_fail = nil, logger = nil, time_limit = nil)
139
- @@impl.execute_command(command, on_fail, logger, time_limit)
146
+ def execute_command(command, on_fail = nil, logger = nil, timeout = nil)
147
+ @@impl.execute_command(command, on_fail, logger, timeout)
140
148
  end
141
149
 
142
150
  class ExecutionFailure < StandardError; end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Windows
5
+ module Os
6
+ module Windows
7
+ class DisplayVersion
8
+ FACT_NAME = 'os.windows.display_version'
9
+
10
+ def call_the_resolver
11
+ fact_value = Facter::Resolvers::ProductRelease.resolve(:display_version)
12
+
13
+ Facter::ResolvedFact.new(FACT_NAME, fact_value)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -97,6 +97,10 @@ module Facter
97
97
  type: :boolean,
98
98
  desc: 'Resolve facts sequentially'
99
99
 
100
+ class_option :http_debug,
101
+ type: :boolean,
102
+ desc: 'Whether to write HTTP request and responses to stderr. This should never be used in production.'
103
+
100
104
  class_option :puppet,
101
105
  type: :boolean,
102
106
  aliases: '-p',
@@ -51,7 +51,9 @@ module Facter
51
51
  core_and_external_facts = core_or_external_fact(user_query) || []
52
52
  resolved_facts = core_and_external_facts + custom_facts
53
53
 
54
- resolved_facts = all_custom_facts(user_query) if resolved_facts.empty?
54
+ if resolved_facts.empty? || resolved_facts.none? { |rf| rf.resolves?(user_query) }
55
+ resolved_facts.concat(all_custom_facts(user_query))
56
+ end
55
57
 
56
58
  @cache_manager.cache_facts(resolved_facts)
57
59
 
@@ -36,6 +36,7 @@ module Facter
36
36
  @hocon = false
37
37
  @allow_external_loggers = true
38
38
  @force_dot_resolution = false
39
+ @http_debug = false
39
40
 
40
41
  class << self
41
42
  attr_reader :debug, :verbose, :log_level, :show_legacy,
@@ -44,7 +45,7 @@ module Facter
44
45
  attr_accessor :config, :strict, :json,
45
46
  :cache, :yaml, :puppet, :ttls, :block, :cli, :config_file_custom_dir,
46
47
  :config_file_external_dir, :default_external_dir, :fact_groups, :force_dot_resolution,
47
- :block_list, :color, :trace, :sequential, :timing, :hocon, :allow_external_loggers
48
+ :block_list, :color, :trace, :sequential, :timing, :hocon, :allow_external_loggers, :http_debug
48
49
 
49
50
  attr_writer :external_dir
50
51
 
@@ -179,6 +180,7 @@ module Facter
179
180
  @ttls = []
180
181
  @block = true
181
182
  @cli = nil
183
+ @http_debug = false
182
184
  reset_config
183
185
  end
184
186
 
@@ -23,5 +23,9 @@ module Facter
23
23
  def to_s
24
24
  @value.to_s
25
25
  end
26
+
27
+ def resolves?(user_query)
28
+ @name == user_query
29
+ end
26
30
  end
27
31
  end
@@ -42,8 +42,9 @@ module Facter
42
42
  return unless result
43
43
 
44
44
  names = retrieve_from_array(result.scan(/name\s=\s.*/), 1)
45
+ status = retrieve_from_array(result.scan(/\s+status\s=\s.*/), 1)
45
46
 
46
- names.each { |elem| query_cuat(elem) }
47
+ names.each_with_index { |elem, idx| query_cuat(elem) if status[idx] == '1' }
47
48
  end
48
49
 
49
50
  def query_cuat(name)
@@ -24,10 +24,19 @@ module Facter
24
24
 
25
25
  def build_fact_list(reg)
26
26
  reg.each do |name, _value|
27
- @fact_list[:edition_id] = reg[name] if name == 'EditionID'
28
- @fact_list[:installation_type] = reg[name] if name == 'InstallationType'
29
- @fact_list[:product_name] = reg[name] if name == 'ProductName'
30
- @fact_list[:release_id] = reg[name] if name == 'ReleaseId'
27
+ case name
28
+ when 'EditionID'
29
+ @fact_list[:edition_id] = reg[name]
30
+ when 'InstallationType'
31
+ @fact_list[:installation_type] = reg[name]
32
+ when 'ProductName'
33
+ @fact_list[:product_name] = reg[name]
34
+ when 'DisplayVersion'
35
+ @fact_list[:release_id] = reg[name]
36
+ @fact_list[:display_version] = reg[name]
37
+ when 'ReleaseId'
38
+ @fact_list[:release_id] = reg[name] unless @fact_list[:release_id]
39
+ end
31
40
  end
32
41
  end
33
42
  end
@@ -23,9 +23,11 @@ module Facter
23
23
  private
24
24
 
25
25
  def check_version_10(consumerrel, kernel_version)
26
+ return '10' if consumerrel
27
+
26
28
  build_number = kernel_version[/([^.]*)$/].to_i
27
- if consumerrel
28
- '10'
29
+ if build_number >= 20_348
30
+ '2022'
29
31
  elsif build_number >= 17_623
30
32
  '2019'
31
33
  else
@@ -60,6 +60,9 @@ module Facter
60
60
  http = Net::HTTP.new(parsed_url.host)
61
61
  http.read_timeout = timeouts[:session] || SESSION_TIMEOUT
62
62
  http.open_timeout = timeouts[:connection] || CONNECTION_TIMEOUT
63
+
64
+ http.set_debug_output($stderr) if Options[:http_debug]
65
+
63
66
  http
64
67
  end
65
68
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.2.4' unless defined?(VERSION)
4
+ VERSION = '4.2.5' unless defined?(VERSION)
5
5
  end
data/lib/facter.rb CHANGED
@@ -205,6 +205,25 @@ module Facter
205
205
  Facter::Options[:debug] = debug_bool
206
206
  end
207
207
 
208
+ # Check whether http debugging is enabled
209
+ #
210
+ # @return [bool]
211
+ #
212
+ # @api public
213
+ def http_debug?
214
+ Options[:http_debug]
215
+ end
216
+
217
+ # Enable or disable http debugging
218
+ # @param debug_bool [bool] State which http debugging should have
219
+ #
220
+ # @return [type] [description]
221
+ #
222
+ # @api public
223
+ def http_debug(http_debug_bool)
224
+ Facter::Options[:http_debug] = http_debug_bool
225
+ end
226
+
208
227
  # Enable sequential resolving of facts
209
228
  #
210
229
  # @return [bool]
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.2.4
4
+ version: 4.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -846,6 +846,7 @@ files:
846
846
  - lib/facter/facts/windows/os/hardware.rb
847
847
  - lib/facter/facts/windows/os/name.rb
848
848
  - lib/facter/facts/windows/os/release.rb
849
+ - lib/facter/facts/windows/os/windows/display_version.rb
849
850
  - lib/facter/facts/windows/os/windows/edition_id.rb
850
851
  - lib/facter/facts/windows/os/windows/installation_type.rb
851
852
  - lib/facter/facts/windows/os/windows/product_name.rb