facter 4.0.7.pre → 4.0.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +17 -4
  4. data/.rubocop_todo.yml +119 -0
  5. data/Gemfile +3 -2
  6. data/VERSION +1 -1
  7. data/facter.gemspec +2 -0
  8. data/lib/custom_facts/core/execution/posix.rb +1 -1
  9. data/lib/custom_facts/core/execution/windows.rb +1 -1
  10. data/lib/custom_facts/core/logging.rb +6 -3
  11. data/lib/custom_facts/core/resolvable.rb +3 -2
  12. data/lib/custom_facts/util/confine.rb +1 -1
  13. data/lib/custom_facts/util/fact.rb +10 -6
  14. data/lib/custom_facts/util/resolution.rb +1 -1
  15. data/lib/facter.rb +4 -2
  16. data/lib/facts/solaris/zfs_featurenumbers.rb +14 -0
  17. data/lib/facts/solaris/zfs_version.rb +14 -0
  18. data/lib/facts/solaris/zpool_featurenumbers.rb +14 -0
  19. data/lib/facts/solaris/zpool_version.rb +14 -0
  20. data/lib/framework/config/config_reader.rb +0 -1
  21. data/lib/framework/core/file_loader.rb +2 -3
  22. data/lib/framework/core/options.rb +3 -0
  23. data/lib/framework/core/options/config_file_options.rb +12 -6
  24. data/lib/framework/core/options/default_options.rb +3 -1
  25. data/lib/framework/core/options/validate_options.rb +47 -0
  26. data/lib/framework/formatters/legacy_fact_formatter.rb +1 -1
  27. data/lib/resolvers/aix/networking_resolver.rb +1 -1
  28. data/lib/resolvers/hostname_resolver.rb +2 -2
  29. data/lib/resolvers/macosx/system_profiler_resolver.rb +1 -1
  30. data/lib/resolvers/selinux_resolver.rb +1 -1
  31. data/lib/resolvers/solaris/zfs_resolver.rb +35 -0
  32. data/lib/resolvers/solaris/zpool_resolver.rb +35 -0
  33. data/lib/resolvers/windows/ffi/ffi.rb +6 -9
  34. data/lib/resolvers/windows/ffi/network_utils.rb +2 -1
  35. data/lib/resolvers/windows/identity_resolver.rb +2 -2
  36. data/lib/resolvers/windows/memory_resolver.rb +1 -1
  37. data/lib/resolvers/windows/netkvm_resolver.rb +2 -0
  38. data/lib/resolvers/windows/system32_resolver.rb +1 -1
  39. metadata +38 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a95b579c2d3ee03ac3fbf5cb0425502f3e18e33c5e434209c0ed0c71f2accd9
4
- data.tar.gz: 790cb477add917be240ffff97c31b276a481e1e5e65748422efbf7a33a4ef10a
3
+ metadata.gz: 476e88581612a000fbf67c3eb00d8dc338cf15085a3717b32dea1a6214856469
4
+ data.tar.gz: bb0258fe0e3df51439f90427c5e2afeee3b6057e4e98291f410d9869e44ed350
5
5
  SHA512:
6
- metadata.gz: d12e9913d3a16d3997b0c4a21f5876e4c96e27fc2dfb0f3b33d777fc04c37930a41a2b81edbfe35d2b9921441b5da78ca8825aa1b210321e589fb18013de16a2
7
- data.tar.gz: a57c800847dd860b39e24f11742655aa1deeea5a62e816386e0d9487b0dec0a61f23849fab4e57dc7a6c8d1f2c7f7e9169932077a422787462ae2511ceec1f6e
6
+ metadata.gz: 2048f930daed9ea2e5b008b8941246af8d094b7d84de1e465828804ef04122812fa7e0b9115a4b76b74de33da46f0ffa2cc321399d6794985858e58c6a55911b
7
+ data.tar.gz: 40741371996abb97ccfd30d60dfe9a8e6279b757f8eb4fa8f6af1dfaf9f0d2457edbe14ba2ff943a397c13f302cd76f88a819e321259a53c8cfae777fbb1686c
data/.gitignore CHANGED
@@ -54,3 +54,4 @@ build-iPhoneSimulator/
54
54
 
55
55
  .rspec_status
56
56
  Gemfile.lock
57
+ Gemfile.local
@@ -1,13 +1,16 @@
1
+ ---
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ require:
5
+ - rubocop-performance
6
+ - rubocop-rspec
7
+
1
8
  Documentation:
2
9
  Enabled: false
3
10
 
4
11
  Metrics/LineLength:
5
12
  Max: 120
6
13
 
7
- Metrics/ModuleLength:
8
- Exclude:
9
- - 'lib/facter-ng.rb'
10
-
11
14
  Metrics/MethodLength:
12
15
  Max: 20
13
16
  Exclude:
@@ -24,14 +27,17 @@ Metrics/ModuleLength:
24
27
  Metrics/BlockLength:
25
28
  Exclude:
26
29
  - !ruby/regexp /(?:(?!.+_spec.rb).)*$/
30
+
27
31
  Style/ClassVars:
28
32
  Exclude:
29
33
  - !ruby/regexp /(?:(?!.+_resolver.rb).)*$/
34
+
30
35
  Naming/ClassAndModuleCamelCase:
31
36
  Exclude:
32
37
  - 'spec/mocks/**/*'
33
38
 
34
39
  Metrics/AbcSize:
40
+ Max: 16
35
41
  Exclude:
36
42
  - 'spec/custom_facts/util/parser_spec.rb'
37
43
  - 'spec/custom_facts/core/logging_spec.rb'
@@ -41,6 +47,7 @@ Metrics/AbcSize:
41
47
  - 'lib/custom_facts/util/confine.rb'
42
48
  - 'lib/custom_facts/core/execution/windows.rb'
43
49
  - 'lib/custom_facts/core/execution/base.rb'
50
+ - 'lib/custom_facts/core/resolvable.rb'
44
51
 
45
52
  Style/FrozenStringLiteralComment:
46
53
  Exclude:
@@ -120,3 +127,9 @@ Naming/FileName:
120
127
  Exclude:
121
128
  - 'lib/facter.rb'
122
129
  - 'agent/lib/facter-ng.rb'
130
+
131
+ RSpec/ExampleLength:
132
+ Enabled: false
133
+
134
+ RSpec/DescribedClass:
135
+ EnforcedStyle: explicit
@@ -0,0 +1,119 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-02-21 22:34:28 +0200 using RuboCop version 0.74.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 75
10
+ RSpec/AnyInstance:
11
+ Enabled: false
12
+
13
+ # Offense count: 79
14
+ # Configuration parameters: Prefixes.
15
+ # Prefixes: when, with, without
16
+ RSpec/ContextWording:
17
+ Enabled: false
18
+
19
+ # Offense count: 82
20
+ RSpec/ExpectInHook:
21
+ Enabled: false
22
+
23
+ # Offense count: 412
24
+ # Configuration parameters: CustomTransform, IgnoreMethods.
25
+ RSpec/FilePath:
26
+ Enabled: false
27
+
28
+ # Offense count: 15
29
+ # Configuration parameters: AssignmentOnly.
30
+ RSpec/InstanceVariable:
31
+ Exclude:
32
+ - 'spec/custom_facts/core/execution/fact_manager_spec.rb'
33
+ - 'spec/custom_facts/util/collection_spec.rb'
34
+ - 'spec/custom_facts/util/confine_spec.rb'
35
+
36
+ # Offense count: 2
37
+ RSpec/IteratedExpectation:
38
+ Exclude:
39
+ - 'spec/custom_facts/core/aggregate_spec.rb'
40
+ - 'spec/custom_facts/core/suitable_spec.rb'
41
+
42
+ # Offense count: 16
43
+ RSpec/LeakyConstantDeclaration:
44
+ Exclude:
45
+ - 'spec/custom_facts/core/resolvable_spec.rb'
46
+ - 'spec/custom_facts/core/suitable_spec.rb'
47
+ - 'spec/custom_facts/shared_contexts/platform.rb'
48
+ - 'spec/custom_facts/util/collection_spec.rb'
49
+ - 'spec/facter/resolvers/macosx/mountpoints_resolver_spec.rb'
50
+ - 'spec/facter/resolvers/utils/windows/network_utils_spec.rb'
51
+
52
+ # Offense count: 428
53
+ # Configuration parameters: EnforcedStyle.
54
+ # SupportedStyles: have_received, receive
55
+ RSpec/MessageSpies:
56
+ Enabled: false
57
+
58
+ # Offense count: 146
59
+ # Configuration parameters: AggregateFailuresByDefault.
60
+ RSpec/MultipleExpectations:
61
+ Max: 9
62
+
63
+ # Offense count: 250
64
+ # Configuration parameters: IgnoreSharedExamples.
65
+ RSpec/NamedSubject:
66
+ Exclude:
67
+ - 'spec/custom_facts/core/aggregate_spec.rb'
68
+ - 'spec/custom_facts/core/execution/fact_manager_spec.rb'
69
+ - 'spec/custom_facts/core/execution/posix_spec.rb'
70
+ - 'spec/custom_facts/core/execution/windows_spec.rb'
71
+ - 'spec/custom_facts/core/execution_spec.rb'
72
+ - 'spec/custom_facts/core/logging_spec.rb'
73
+ - 'spec/custom_facts/core/resolvable_spec.rb'
74
+ - 'spec/custom_facts/core/suitable_spec.rb'
75
+ - 'spec/custom_facts/util/directory_loader_spec.rb'
76
+ - 'spec/custom_facts/util/fact_spec.rb'
77
+ - 'spec/custom_facts/util/normalization_spec.rb'
78
+ - 'spec/custom_facts/util/resolution_spec.rb'
79
+ - 'spec/facter/resolvers/linux/networking_linux_resolver_spec.rb'
80
+ - 'spec/framework/core/options_spec.rb'
81
+
82
+ # Offense count: 22
83
+ RSpec/NestedGroups:
84
+ Max: 4
85
+
86
+ # Offense count: 7
87
+ RSpec/RepeatedDescription:
88
+ Exclude:
89
+ - 'spec/custom_facts/util/confine_spec.rb'
90
+ - 'spec/facter/resolvers/macosx/system_memory_resolver_spec.rb'
91
+ - 'spec/facter/resolvers/windows/uptime_resolver_spec.rb'
92
+
93
+ # Offense count: 4
94
+ RSpec/RepeatedExampleGroupDescription:
95
+ Exclude:
96
+ - 'spec/custom_facts/util/parser_spec.rb'
97
+ - 'spec/facter/resolvers/windows/fips_resolver_spec.rb'
98
+
99
+ # Offense count: 7
100
+ RSpec/ScatteredLet:
101
+ Exclude:
102
+ - 'spec/facter/resolvers/windows/product_release_resolver_spec.rb'
103
+
104
+ # Offense count: 39
105
+ RSpec/SubjectStub:
106
+ Exclude:
107
+ - 'spec/custom_facts/core/aggregate_spec.rb'
108
+ - 'spec/custom_facts/core/execution/fact_manager_spec.rb'
109
+ - 'spec/custom_facts/core/execution/posix_spec.rb'
110
+ - 'spec/custom_facts/core/execution/windows_spec.rb'
111
+ - 'spec/custom_facts/core/logging_spec.rb'
112
+ - 'spec/custom_facts/core/resolvable_spec.rb'
113
+ - 'spec/custom_facts/util/fact_spec.rb'
114
+ - 'spec/custom_facts/util/resolution_spec.rb'
115
+
116
+ # Offense count: 392
117
+ # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
118
+ RSpec/VerifiedDoubles:
119
+ Enabled: false
data/Gemfile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  source ENV['GEM_SOURCE'] || 'https://rubygems.org'
4
4
 
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
5
  gemspec name: 'facter'
6
+
7
+ local_gemfile = File.expand_path('Gemfile.local', __dir__)
8
+ eval_gemfile(local_gemfile) if File.exist?(local_gemfile)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.7.pre
1
+ 4.0.8.pre
@@ -40,6 +40,8 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'rake', '~> 10.0'
41
41
  spec.add_development_dependency 'rspec', '~> 3.0'
42
42
  spec.add_development_dependency 'rubocop', '~> 0.74.0'
43
+ spec.add_development_dependency 'rubocop-performance', '~> 1.5'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.38'
43
45
  spec.add_development_dependency 'rubycritic', '~> 4.1.0'
44
46
  spec.add_development_dependency 'sys-filesystem', '~> 1.3'
45
47
 
@@ -44,7 +44,7 @@ module LegacyFacter
44
44
 
45
45
  return unless exe && (expanded = which(exe))
46
46
 
47
- expanded = "'#{expanded}'" if expanded.match(/\s/)
47
+ expanded = "'#{expanded}'" if expanded =~ /\s/
48
48
  expanded << " #{args}" if args
49
49
 
50
50
  expanded
@@ -52,7 +52,7 @@ module LegacyFacter
52
52
 
53
53
  return unless exe && (expanded = which(exe))
54
54
 
55
- expanded = "\"#{expanded}\"" if expanded.match(/\s+/)
55
+ expanded = "\"#{expanded}\"" if expanded =~ /\s+/
56
56
  expanded << " #{args}" if args
57
57
 
58
58
  expanded
@@ -48,7 +48,7 @@ module LegacyFacter
48
48
  return unless debugging?
49
49
 
50
50
  if msg.nil? || msg.empty?
51
- invoker = caller[0].slice(/.*:\d+/)
51
+ invoker = caller(1..1).first.slice(/.*:\d+/)
52
52
  self.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
53
53
  elsif @@message_callback
54
54
  @@message_callback.call(:debug, msg)
@@ -79,7 +79,7 @@ module LegacyFacter
79
79
  # @return [void]
80
80
  def warn(msg)
81
81
  if msg.nil? || msg.empty?
82
- invoker = caller[0].slice(/.*:\d+/)
82
+ invoker = caller(1..1).first.slice(/.*:\d+/)
83
83
  msg = "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
84
84
  end
85
85
  if @@message_callback
@@ -119,7 +119,10 @@ module LegacyFacter
119
119
  arr << message
120
120
  end
121
121
 
122
- arr.concat(exception.backtrace) if trace
122
+ if trace
123
+ arr << 'backtrace:'
124
+ arr.concat(exception.backtrace)
125
+ end
123
126
 
124
127
  "#{RED}#{arr.flatten.join("\n")}#{RESET}"
125
128
  end
@@ -75,8 +75,9 @@ module LegacyFacter
75
75
  LegacyFacter.log_exception(e, "Fact resolution #{qualified_name} resolved to an invalid value: #{e.message}")
76
76
  nil
77
77
  rescue StandardError => e
78
- LegacyFacter.log_exception(e, "error while resolving custom fact #{qualified_name}: #{e.message}")
79
- nil
78
+ LegacyFacter.log_exception(e, "Error while resolving custom fact #{qualified_name}: #{e.message}")
79
+ at_exit { exit 1 }
80
+ raise Facter::ResolveCustomFactError
80
81
  end
81
82
 
82
83
  private
@@ -46,7 +46,7 @@ module LegacyFacter
46
46
  end
47
47
  end
48
48
 
49
- unless (fact = LegacyFacter[@fact])
49
+ unless (fact = Facter[@fact])
50
50
  LegacyFacter.debug format('No fact for %<fact>s', fact: @fact)
51
51
  return false
52
52
  end
@@ -48,7 +48,7 @@ module LegacyFacter
48
48
  #
49
49
  # @param options [Hash] A hash of options to set on the resolution
50
50
  #
51
- # @return [LegacyFacter::Util::Resolution]
51
+ # @return [Facter::Util::Resolution]
52
52
  #
53
53
  # @api private
54
54
  def add(options = {}, &block)
@@ -61,7 +61,7 @@ module LegacyFacter
61
61
  #
62
62
  # @param resolution_name [String] The name of the resolve to define or look up
63
63
  # @param options [Hash] A hash of options to set on the resolution
64
- # @return [LegacyFacter::Util::Resolution]
64
+ # @return [Facter::Util::Resolution]
65
65
  #
66
66
  # @api public
67
67
  def define_resolution(resolution_name, options = {}, &block)
@@ -82,7 +82,7 @@ module LegacyFacter
82
82
  #
83
83
  # @param name [String]
84
84
  #
85
- # @return [LegacyFacter::Util::Resolution, nil] The resolution if exists, nil if
85
+ # @return [Facter::Util::Resolution, nil] The resolution if exists, nil if
86
86
  # it doesn't exist or name is nil
87
87
  def resolution(name)
88
88
  return nil if name.nil?
@@ -163,7 +163,11 @@ module LegacyFacter
163
163
 
164
164
  def find_first_real_value(resolutions)
165
165
  resolutions.each do |resolve|
166
- value = resolve.value
166
+ begin
167
+ value = resolve.value
168
+ rescue Facter::ResolveCustomFactError
169
+ break
170
+ end
167
171
  @used_resolution_weight = resolve.weight
168
172
  return value unless value.nil?
169
173
  end
@@ -173,7 +177,7 @@ module LegacyFacter
173
177
  def announce_when_no_suitable_resolution(resolutions)
174
178
  return unless resolutions.empty?
175
179
 
176
- LegacyFacter.debug format('Found no suitable resolves of %<resolver_lengths for %<name>s',
180
+ LegacyFacter.debug format('Found no suitable resolves of %<resolver_length> for %<name>s',
177
181
  resolver_length: @resolves.length, name: @name)
178
182
  end
179
183
 
@@ -192,7 +196,7 @@ module LegacyFacter
192
196
  else
193
197
  case resolution_type
194
198
  when :simple
195
- resolve = LegacyFacter::Util::Resolution.new(resolution_name, self)
199
+ resolve = Facter::Util::Resolution.new(resolution_name, self)
196
200
  when :aggregate
197
201
  resolve = LegacyFacter::Core::Aggregate.new(resolution_name, self)
198
202
  else
@@ -9,7 +9,7 @@
9
9
  # satisfied for a fact to be considered _suitable_.
10
10
  #
11
11
  # @api public
12
- module LegacyFacter
12
+ module Facter
13
13
  module Util
14
14
  class Resolution
15
15
  # @api private
@@ -8,6 +8,8 @@ require "#{ROOT_DIR}/lib/framework/core/file_loader"
8
8
  require "#{ROOT_DIR}/lib/framework/core/options/options_validator"
9
9
 
10
10
  module Facter
11
+ class ResolveCustomFactError < StandardError; end
12
+
11
13
  @options = Options.instance
12
14
 
13
15
  def self.[](name)
@@ -44,7 +46,7 @@ module Facter
44
46
  end
45
47
 
46
48
  def self.debugging(debug_bool)
47
- @options.priority_options = { debug: true }
49
+ @options.priority_options = { debug: debug_bool }
48
50
  @options.refresh
49
51
 
50
52
  debug_bool
@@ -108,7 +110,7 @@ module Facter
108
110
  end
109
111
 
110
112
  def self.to_user_output(cli_options, *args)
111
- @options.priority_options = cli_options
113
+ @options.priority_options = { is_cli: true }.merge!(cli_options.map { |(k, v)| [k.to_sym, v] }.to_h)
112
114
  @options.refresh(args)
113
115
 
114
116
  resolved_facts = Facter::FactManager.instance.resolve_facts(@options, args)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Solaris
5
+ class ZFSFeatureNumbers
6
+ FACT_NAME = 'zfs_featurenumbers'
7
+
8
+ def call_the_resolver
9
+ fact_value = Resolvers::Solaris::ZFS.resolve(:zfs_featurenumbers)
10
+ ResolvedFact.new(FACT_NAME, fact_value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Solaris
5
+ class ZFSVersion
6
+ FACT_NAME = 'zfs_version'
7
+
8
+ def call_the_resolver
9
+ fact_value = Resolvers::Solaris::ZFS.resolve(:zfs_version)
10
+ ResolvedFact.new(FACT_NAME, fact_value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Solaris
5
+ class ZPoolFeatureNumbers
6
+ FACT_NAME = 'zpool_featurenumbers'
7
+
8
+ def call_the_resolver
9
+ fact_value = Resolvers::Solaris::ZPool.resolve(:zpool_featurenumbers)
10
+ ResolvedFact.new(FACT_NAME, fact_value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Solaris
5
+ class ZPoolVersion
6
+ FACT_NAME = 'zpool_version'
7
+
8
+ def call_the_resolver
9
+ fact_value = Resolvers::Solaris::ZPool.resolve(:zpool_version)
10
+ ResolvedFact.new(FACT_NAME, fact_value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -18,7 +18,6 @@ module Facter
18
18
  end
19
19
 
20
20
  def global
21
- # puts @conf['global']
22
21
  @conf['global']
23
22
  end
24
23
 
@@ -40,7 +40,6 @@ load_dir(['config'])
40
40
 
41
41
  load_lib_dirs('resolvers')
42
42
  load_lib_dirs('facts_utils')
43
- load_lib_dirs('utils')
44
43
  load_lib_dirs('framework', 'core')
45
44
  load_lib_dirs('models')
46
45
  load_lib_dirs('framework', 'core', 'fact_loaders')
@@ -53,8 +52,8 @@ os_hierarchy.each { |operating_system| load_lib_dirs('facts', operating_system.d
53
52
  os_hierarchy.each { |operating_system| load_lib_dirs('resolvers', operating_system.downcase, '**') }
54
53
 
55
54
  require "#{ROOT_DIR}/lib/custom_facts/core/legacy_facter"
56
- require "#{ROOT_DIR}/lib/framework/utils/utils"
57
- require "#{ROOT_DIR}/lib/util/fact.rb"
55
+ load_lib_dirs('framework', 'utils')
56
+ load_lib_dirs('util')
58
57
 
59
58
  require "#{ROOT_DIR}/lib/framework/core/fact_augmenter"
60
59
  require "#{ROOT_DIR}/lib/framework/parsers/query_parser"
@@ -6,6 +6,7 @@ module Facter
6
6
  include Facter::ConfigFileOptions
7
7
  include Facter::PriorityOptions
8
8
  include Facter::HelperOptions
9
+ include Facter::ValidateOptions
9
10
 
10
11
  include Singleton
11
12
 
@@ -58,10 +59,12 @@ module Facter
58
59
  private
59
60
 
60
61
  def initialize_options
62
+ @options = {}
61
63
  augment_with_defaults!
62
64
  augment_with_to_hash_defaults! if @priority_options[:to_hash]
63
65
  augment_with_config_file_options!(@priority_options[:config])
64
66
  augment_with_priority_options!(@priority_options)
67
+ validate_configs
65
68
  augment_with_helper_options!(@user_query)
66
69
  end
67
70
  end
@@ -6,10 +6,12 @@ module Facter
6
6
  conf_reader = Facter::ConfigReader.new(config_path)
7
7
 
8
8
  augment_config_path(config_path)
9
- augment_cli(conf_reader.cli)
9
+ if @priority_options[:is_cli]
10
+ augment_cli(conf_reader.cli)
11
+ augment_ruby(conf_reader.global)
12
+ end
10
13
  augment_custom(conf_reader.global)
11
14
  augment_external(conf_reader.global)
12
- augment_ruby(conf_reader.global)
13
15
  augment_show_legacy(conf_reader.global)
14
16
  augment_facts(conf_reader.ttls)
15
17
  end
@@ -32,15 +34,19 @@ module Facter
32
34
  def augment_custom(file_global_conf)
33
35
  return unless file_global_conf
34
36
 
35
- @options[:custom_facts] = !file_global_conf['no-custom-facts'] unless file_global_conf['no-custom-facts'].nil?
36
- @options[:custom_dir] = file_global_conf['custom-dir'] unless file_global_conf['custom-dir'].nil?
37
+ if @priority_options[:is_cli]
38
+ @options[:custom_facts] = !file_global_conf['no-custom-facts'] unless file_global_conf['no-custom-facts'].nil?
39
+ end
40
+ @options[:custom_dir] = [file_global_conf['custom-dir']].flatten unless file_global_conf['custom-dir'].nil?
37
41
  end
38
42
 
39
43
  def augment_external(global_conf)
40
44
  return unless global_conf
41
45
 
42
- @options[:external_facts] = !global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
43
- @options[:external_dir] = global_conf['external-dir'] unless global_conf['external-dir'].nil?
46
+ if @priority_options[:is_cli]
47
+ @options[:external_facts] = !global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
48
+ end
49
+ @options[:external_dir] = [global_conf['external-dir']].flatten unless global_conf['external-dir'].nil?
44
50
  end
45
51
 
46
52
  def augment_ruby(global_conf)
@@ -7,6 +7,8 @@ module Facter
7
7
  global_defaults
8
8
  end
9
9
 
10
+ DEFAULT_LOG_LEVEL = :warn
11
+
10
12
  def augment_with_to_hash_defaults!
11
13
  @options[:show_legacy] = true
12
14
  end
@@ -17,7 +19,7 @@ module Facter
17
19
  @options[:debug] ||= false
18
20
  @options[:trace] ||= false
19
21
  @options[:verbose] ||= false
20
- @options[:log_level] ||= :warn
22
+ @options[:log_level] ||= DEFAULT_LOG_LEVEL
21
23
  @options[:show_legacy] ||= false
22
24
  end
23
25
 
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module ValidateOptions
5
+ def validate_configs
6
+ conflicting_configs.each do |op|
7
+ if op.values[0] && op.values[1]
8
+ raise_error("#{op.keys[0]} and #{op.keys[1]} options conflict: please specify only one")
9
+ end
10
+ end
11
+ validate_log_options
12
+ end
13
+
14
+ private
15
+
16
+ def conflicting_configs
17
+ no_ruby = !@options[:ruby]
18
+ no_custom_facts = !@options[:custom_facts]
19
+ puppet = @options[:puppet]
20
+ custom_dir = @options[:custom_dir].nil? ? false : @options[:custom_dir].any?
21
+ external_dir = @options[:external_dir].nil? ? false : @options[:external_dir].any?
22
+
23
+ [
24
+ { 'no-ruby' => no_ruby, 'custom-dir' => custom_dir },
25
+ { 'no-external-facts' => !@options[:external_facts], 'external-dir' => external_dir },
26
+ { 'no-custom-facts' => no_custom_facts, 'custom-fir' => custom_dir },
27
+ { 'no-ruby' => no_ruby, 'puppet' => puppet },
28
+ { 'no-custom-facts' => no_custom_facts, 'puppet' => puppet }
29
+ ]
30
+ end
31
+
32
+ def validate_log_options
33
+ return unless [@options[:debug],
34
+ @options[:verbose],
35
+ @options[:log_level] != Facter::DefaultOptions::DEFAULT_LOG_LEVEL]
36
+ .count(true) > 1
37
+
38
+ raise_error('debug, verbose, and log-level options conflict: please specify only one.')
39
+ end
40
+
41
+ def raise_error(message)
42
+ log = Facter::Log.new(self)
43
+ log.error(message, true)
44
+ raise ArgumentError, message
45
+ end
46
+ end
47
+ end
@@ -84,7 +84,7 @@ module Facter
84
84
 
85
85
  def remove_comma_and_quation(output)
86
86
  @log.debug('Remove unnecessary comma and quotation marks on root facts')
87
- output.split("\n").map! { |line| line.match(/^[\s]+/) ? line : line.gsub(/,$|\"/, '') }.join("\n")
87
+ output.split("\n").map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|\"/, '') }.join("\n")
88
88
  end
89
89
  end
90
90
  end
@@ -23,7 +23,7 @@ module Facter
23
23
  end
24
24
 
25
25
  def get_primary_interface_info(output)
26
- primary_interface_info = output.select { |line| line =~ /=>/ }.first.split(' ')
26
+ primary_interface_info = output.find { |line| line =~ /=>/ }.split(' ')
27
27
  @fact_list[:primary] = primary_interface_info[5]
28
28
  @fact_list[:ip] = primary_interface_info[1]
29
29
  end
@@ -32,9 +32,9 @@ module Facter
32
32
  domain = Regexp.last_match(1)
33
33
  elsif File.exist?('/etc/resolv.conf')
34
34
  file = File.read('/etc/resolv.conf')
35
- if file.match(/^search\s+(\S+)/)
35
+ if file =~ /^search\s+(\S+)/
36
36
  domain = Regexp.last_match(1)
37
- elsif file.match(/^domain\s+(\S+)/)
37
+ elsif file =~ /^domain\s+(\S+)/
38
38
  domain = Regexp.last_match(1)
39
39
  end
40
40
  end
@@ -53,7 +53,7 @@ module Facter
53
53
 
54
54
  def normalize_factlist
55
55
  @fact_list = @fact_list.map do |k, v|
56
- [k.downcase.gsub(' ', '_').delete("\(\)").to_sym, v]
56
+ [k.downcase.tr(' ', '_').delete("\(\)").to_sym, v]
57
57
  end.to_h
58
58
  end
59
59
  end
@@ -22,7 +22,7 @@ module Facter
22
22
  @fact_list[:enabled] = false
23
23
 
24
24
  output.each_line do |line|
25
- next unless line.match(/selinuxfs/)
25
+ next unless line =~ /selinuxfs/
26
26
 
27
27
  @fact_list[:enabled] = true
28
28
  @fact_list[:mountpoint] = line
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class ZFS < BaseResolver
7
+ @log = Facter::Log.new(self)
8
+ @semaphore = Mutex.new
9
+ @fact_list ||= {}
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { zfs_fact(fact_name) }
15
+ end
16
+
17
+ def zfs_fact(fact_name)
18
+ build_zfs_facts
19
+ @fact_list[fact_name]
20
+ end
21
+
22
+ def build_zfs_facts
23
+ output, _status = Open3.capture2('zfs upgrade -v')
24
+ features_list = output.scan(/^\s+(\d+)/).flatten
25
+
26
+ return if features_list.empty?
27
+
28
+ @fact_list[:zfs_featurenumbers] = features_list.join(',')
29
+ @fact_list[:zfs_version] = features_list.last
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class ZPool < BaseResolver
7
+ @log = Facter::Log.new(self)
8
+ @semaphore = Mutex.new
9
+ @fact_list ||= {}
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { zpool_fact(fact_name) }
15
+ end
16
+
17
+ def zpool_fact(fact_name)
18
+ build_zpool_facts
19
+ @fact_list[fact_name]
20
+ end
21
+
22
+ def build_zpool_facts
23
+ output, _status = Open3.capture2('zpool upgrade -v')
24
+ features_list = output.scan(/^\s+(\d+)/).flatten
25
+
26
+ return if features_list.empty?
27
+
28
+ @fact_list[:zpool_featurenumbers] = features_list.join(',')
29
+ @fact_list[:zpool_version] = features_list.last
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -23,13 +23,10 @@ ERROR_MORE_DATA = 234
23
23
  MAX_PATH = 32_767
24
24
 
25
25
  module FFI
26
- WIN32_FALSE = 0
26
+ WIN32FALSE = 0
27
27
  END_OF_WCHAR_STRING = "\0\0".encode('UTF-16LE')
28
28
 
29
29
  class Pointer
30
- alias write_dword write_uint32
31
- alias read_dword read_uint32
32
-
33
30
  def read_wide_string_with_length(char_length)
34
31
  # char_length is number of wide chars (typically excluding NULLs), *not* bytes
35
32
  str = get_bytes(0, char_length * 2).force_encoding('UTF-16LE')
@@ -39,27 +36,27 @@ module FFI
39
36
  def read_wide_string_without_length
40
37
  wide_character = get_bytes(0, 2)
41
38
  i = 2
42
- str = String.new
39
+ str = []
43
40
 
44
41
  while wide_character.encode('UTF-16LE') != END_OF_WCHAR_STRING
45
- str += wide_character
42
+ str << wide_character
46
43
  wide_character = get_bytes(i, 2)
47
44
  i += 2
48
45
  end
49
- str.force_encoding('UTF-16LE').encode('UTF-8')
46
+ str.join.force_encoding('UTF-16LE').encode('UTF-8')
50
47
  end
51
48
 
52
49
  def read_win32_bool
53
50
  # BOOL is always a 32-bit integer in Win32
54
51
  # some Win32 APIs return 1 for true, while others are non-0
55
- read_int32 != FFI::WIN32_FALSE
52
+ read_int32 != WIN32FALSE
56
53
  end
57
54
  end
58
55
 
59
56
  class Struct
60
57
  def self.read_list(first_address)
61
58
  instance = new(first_address)
62
- while instance.to_ptr != FFI::Pointer::NULL
59
+ while instance.to_ptr != Pointer::NULL
63
60
  yield(instance)
64
61
  instance = new(instance[:Next])
65
62
  end
@@ -47,7 +47,7 @@ class NetworkUtils
47
47
 
48
48
  def get_scope(sockaddr)
49
49
  require 'socket'
50
- scope6 = String.new
50
+ scope6 = []
51
51
  addrinfo = Addrinfo.new(['AF_INET6', 0, nil, sockaddr], :INET6)
52
52
 
53
53
  scope6 << 'compat,' if addrinfo.ipv6_v4compat?
@@ -59,6 +59,7 @@ class NetworkUtils
59
59
  'host'
60
60
  else 'global'
61
61
  end
62
+ scope6.join
62
63
  end
63
64
  end
64
65
  end
@@ -26,7 +26,7 @@ module Facter
26
26
  end
27
27
 
28
28
  name_ptr = FFI::MemoryPointer.new(:wchar, size_ptr.read_uint32)
29
- if IdentityFFI::GetUserNameExW(NAME_SAM_COMPATIBLE, name_ptr, size_ptr) == FFI::WIN32_FALSE
29
+ if IdentityFFI::GetUserNameExW(NAME_SAM_COMPATIBLE, name_ptr, size_ptr) == FFI::WIN32FALSE
30
30
  @log.debug "failure resolving identity facts: #{FFI.errno}"
31
31
  return
32
32
  end
@@ -36,7 +36,7 @@ module Facter
36
36
 
37
37
  def privileged?
38
38
  result = IdentityFFI::IsUserAnAdmin()
39
- result && result != FFI::WIN32_FALSE
39
+ result && result != FFI::WIN32FALSE
40
40
  end
41
41
 
42
42
  def retrieve_facts(fact_name)
@@ -17,7 +17,7 @@ module Facter
17
17
  require "#{ROOT_DIR}/lib/resolvers/windows/ffi/memory_ffi"
18
18
 
19
19
  state_ptr = FFI::MemoryPointer.new(PerformanceInformation.size)
20
- if MemoryFFI::GetPerformanceInfo(state_ptr, state_ptr.size) == FFI::WIN32_FALSE
20
+ if MemoryFFI::GetPerformanceInfo(state_ptr, state_ptr.size) == FFI::WIN32FALSE
21
21
  @log.debug 'Resolving memory facts failed'
22
22
  return
23
23
  end
@@ -23,7 +23,9 @@ module Facter
23
23
  end
24
24
 
25
25
  def build_fact_list(reg)
26
+ # rubocop:disable Performance/InefficientHashSearch
26
27
  @fact_list[:kvm] = reg.keys.include?('netkvm')
28
+ # rubocop:enable Performance/InefficientHashSearch
27
29
  end
28
30
  end
29
31
  end
@@ -24,7 +24,7 @@ module Facter
24
24
  end
25
25
 
26
26
  bool_ptr = FFI::MemoryPointer.new(:win32_bool, 1)
27
- if System32FFI::IsWow64Process(System32FFI::GetCurrentProcess(), bool_ptr) == FFI::WIN32_FALSE
27
+ if System32FFI::IsWow64Process(System32FFI::GetCurrentProcess(), bool_ptr) == FFI::WIN32FALSE
28
28
  @log.debug 'IsWow64Process failed'
29
29
  return
30
30
  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.7.pre
4
+ version: 4.0.8.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-18 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.74.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.38'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.38'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rubycritic
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +182,7 @@ files:
154
182
  - ".jrubyrc"
155
183
  - ".rspec"
156
184
  - ".rubocop.yml"
185
+ - ".rubocop_todo.yml"
157
186
  - ".rubycritic.yml"
158
187
  - ".travis.yml"
159
188
  - CODEOWNERS
@@ -457,6 +486,10 @@ files:
457
486
  - lib/facts/solaris/ruby/version.rb
458
487
  - lib/facts/solaris/solaris_zones/current.rb
459
488
  - lib/facts/solaris/solaris_zones/zone.rb
489
+ - lib/facts/solaris/zfs_featurenumbers.rb
490
+ - lib/facts/solaris/zfs_version.rb
491
+ - lib/facts/solaris/zpool_featurenumbers.rb
492
+ - lib/facts/solaris/zpool_version.rb
460
493
  - lib/facts/windows/dhcp_servers.rb
461
494
  - lib/facts/windows/dmi/manufacturer.rb
462
495
  - lib/facts/windows/dmi/product/name.rb
@@ -558,6 +591,7 @@ files:
558
591
  - lib/framework/core/options/helper_options.rb
559
592
  - lib/framework/core/options/options_validator.rb
560
593
  - lib/framework/core/options/priority_options.rb
594
+ - lib/framework/core/options/validate_options.rb
561
595
  - lib/framework/detector/os_detector.rb
562
596
  - lib/framework/formatters/formatter_factory.rb
563
597
  - lib/framework/formatters/formatter_helper.rb
@@ -617,7 +651,9 @@ files:
617
651
  - lib/resolvers/solaris/ipaddress_resolver.rb
618
652
  - lib/resolvers/solaris/solaris_os_release_resolver.rb
619
653
  - lib/resolvers/solaris/solaris_zone_name.rb
654
+ - lib/resolvers/solaris/zfs_resolver.rb
620
655
  - lib/resolvers/solaris/zone_resolver.rb
656
+ - lib/resolvers/solaris/zpool_resolver.rb
621
657
  - lib/resolvers/ssh_resolver.rb
622
658
  - lib/resolvers/suse_release_resolver.rb
623
659
  - lib/resolvers/sw_vers_resolver.rb