facter 4.0.13 → 4.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +322 -38
- data/VERSION +1 -1
- data/lib/custom_facts/core/aggregate.rb +2 -2
- data/lib/custom_facts/core/execution.rb +2 -2
- data/lib/custom_facts/core/execution/base.rb +27 -13
- data/lib/custom_facts/core/execution/posix.rb +2 -2
- data/lib/custom_facts/core/execution/windows.rb +9 -2
- data/lib/custom_facts/core/legacy_facter.rb +3 -3
- data/lib/custom_facts/util/collection.rb +3 -3
- data/lib/custom_facts/util/fact.rb +2 -2
- data/lib/custom_facts/util/resolution.rb +2 -2
- data/lib/facter.rb +9 -6
- data/lib/facts/aix/mountpoints.rb +15 -0
- data/lib/facts/debian/os/distro/release.rb +17 -8
- data/lib/facts/debian/os/name.rb +1 -1
- data/lib/facts/debian/os/release.rb +14 -2
- data/lib/facts/debian/partitions.rb +26 -0
- data/lib/facts/el/partitions.rb +26 -0
- data/lib/facts/sles/partitions.rb +26 -0
- data/lib/facts/solaris/solaris_zones/zone.rb +2 -0
- data/lib/framework/core/fact_loaders/internal_fact_loader.rb +11 -7
- data/lib/framework/core/{cache_manager.rb → session_cache.rb} +1 -1
- data/lib/framework/detector/os_detector.rb +2 -0
- data/lib/framework/logging/logger.rb +1 -10
- data/lib/resolvers/aix/mountpoints.rb +69 -0
- data/lib/resolvers/base_resolver.rb +1 -1
- data/lib/resolvers/{debian_version_resolver.rb → debian_version.rb} +4 -6
- data/lib/resolvers/partitions.rb +101 -0
- data/lib/resolvers/solaris/solaris_zone_name.rb +2 -0
- data/lib/resolvers/solaris/zone_resolver.rb +2 -0
- data/lib/util/api_debugger.rb +43 -0
- metadata +11 -5
- data/lib/util/fact.rb +0 -14
@@ -8,9 +8,9 @@ module Facter
|
|
8
8
|
# require_relative 'execution/posix'
|
9
9
|
|
10
10
|
@@impl = if LegacyFacter::Util::Config.windows?
|
11
|
-
|
11
|
+
Facter::Core::Execution::Windows.new
|
12
12
|
else
|
13
|
-
|
13
|
+
Facter::Core::Execution::Posix.new
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.impl
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module Facter
|
4
4
|
module Core
|
5
5
|
module Execution
|
6
6
|
class Base
|
@@ -33,12 +33,17 @@ module LegacyFacter
|
|
33
33
|
|
34
34
|
def execute(command, options = {})
|
35
35
|
on_fail = options.fetch(:on_fail, :raise)
|
36
|
+
expand = options.fetch(:expand, true)
|
36
37
|
|
37
38
|
# Set LC_ALL and LANG to force i18n to C for the duration of this exec;
|
38
39
|
# this ensures that any code that parses the
|
39
40
|
# output of the command can expect it to be in a consistent / predictable format / locale
|
40
41
|
with_env 'LC_ALL' => 'C', 'LANG' => 'C' do
|
41
|
-
expanded_command =
|
42
|
+
expanded_command = if !expand && builtin_command?(command)
|
43
|
+
command
|
44
|
+
else
|
45
|
+
expand_command(command)
|
46
|
+
end
|
42
47
|
|
43
48
|
if expanded_command.nil?
|
44
49
|
if on_fail == :raise
|
@@ -49,17 +54,7 @@ module LegacyFacter
|
|
49
54
|
return on_fail
|
50
55
|
end
|
51
56
|
|
52
|
-
|
53
|
-
out, stderr, _status_ = Open3.capture3(expanded_command.to_s)
|
54
|
-
log_stderr_from_file(stderr, expanded_command)
|
55
|
-
rescue StandardError => e
|
56
|
-
return on_fail unless on_fail == :raise
|
57
|
-
|
58
|
-
raise Facter::Core::Execution::ExecutionFailure.new,
|
59
|
-
"Failed while executing '#{expanded_command}': #{e.message}"
|
60
|
-
end
|
61
|
-
|
62
|
-
out.strip
|
57
|
+
execute_command(expanded_command, on_fail)
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
@@ -72,6 +67,25 @@ module LegacyFacter
|
|
72
67
|
logger = Facter::Log.new(file_name)
|
73
68
|
logger.warn(msg.strip)
|
74
69
|
end
|
70
|
+
|
71
|
+
def builtin_command?(command)
|
72
|
+
output, _status = Open3.capture2("type #{command}")
|
73
|
+
output.chomp =~ /builtin/ ? true : false
|
74
|
+
end
|
75
|
+
|
76
|
+
def execute_command(command, on_fail)
|
77
|
+
begin
|
78
|
+
out, stderr, _status_ = Open3.capture3(command.to_s)
|
79
|
+
log_stderr_from_file(stderr, command)
|
80
|
+
rescue StandardError => e
|
81
|
+
return on_fail unless on_fail == :raise
|
82
|
+
|
83
|
+
raise Facter::Core::Execution::ExecutionFailure.new,
|
84
|
+
"Failed while executing '#{command}': #{e.message}"
|
85
|
+
end
|
86
|
+
|
87
|
+
out.strip
|
88
|
+
end
|
75
89
|
end
|
76
90
|
end
|
77
91
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module
|
1
|
+
module Facter
|
2
2
|
module Core
|
3
3
|
module Execution
|
4
|
-
class Windows <
|
4
|
+
class Windows < Facter::Core::Execution::Base
|
5
5
|
def search_paths
|
6
6
|
ENV['PATH'].split(File::PATH_SEPARATOR)
|
7
7
|
end
|
@@ -57,6 +57,13 @@ module LegacyFacter
|
|
57
57
|
|
58
58
|
expanded
|
59
59
|
end
|
60
|
+
|
61
|
+
def execute(command, options = {})
|
62
|
+
expand = options.fetch(:expand, true)
|
63
|
+
raise ArgumentError.new, 'Unsupported argument on Windows expand with value false' unless expand
|
64
|
+
|
65
|
+
super(command, options)
|
66
|
+
end
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
@@ -73,7 +73,7 @@ module LegacyFacter
|
|
73
73
|
#
|
74
74
|
# @param name [String] the name of the fact
|
75
75
|
#
|
76
|
-
# @return [
|
76
|
+
# @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
|
77
77
|
# is found.
|
78
78
|
#
|
79
79
|
# @api public
|
@@ -131,7 +131,7 @@ module LegacyFacter
|
|
131
131
|
# @param name [Symbol] The name of the fact to define
|
132
132
|
# @param options [Hash] A hash of options to set on the fact
|
133
133
|
#
|
134
|
-
# @return [
|
134
|
+
# @return [Facter::Util::Fact] The fact that was defined
|
135
135
|
#
|
136
136
|
# @api public
|
137
137
|
# @see {Facter::Util::Collection#define_fact}
|
@@ -152,7 +152,7 @@ module LegacyFacter
|
|
152
152
|
# {Facter::Util::Resolution#timeout timeout} for this resolution
|
153
153
|
# @param block [Proc] a block defining a fact resolution
|
154
154
|
#
|
155
|
-
# @return [
|
155
|
+
# @return [Facter::Util::Fact] the fact object, which includes any previously
|
156
156
|
# defined resolutions
|
157
157
|
#
|
158
158
|
# @api public
|
@@ -24,7 +24,7 @@ module LegacyFacter
|
|
24
24
|
# @param name [Symbol] The name of the fact to define
|
25
25
|
# @param options [Hash] A hash of options to set on the fact
|
26
26
|
#
|
27
|
-
# @return [
|
27
|
+
# @return [Facter::Util::Fact] The fact that was defined
|
28
28
|
def define_fact(name, options = {}, &block)
|
29
29
|
fact = create_or_return_fact(name, options)
|
30
30
|
|
@@ -41,7 +41,7 @@ module LegacyFacter
|
|
41
41
|
# @param name [Symbol] The name of the fact to define
|
42
42
|
# @param options [Hash] A hash of options to set on the fact and resolution
|
43
43
|
#
|
44
|
-
# @return [
|
44
|
+
# @return [Facter::Util::Fact] The fact that was defined
|
45
45
|
def add(name, options = {}, &block)
|
46
46
|
fact = create_or_return_fact(name, options)
|
47
47
|
|
@@ -163,7 +163,7 @@ module LegacyFacter
|
|
163
163
|
fact = @facts[name]
|
164
164
|
|
165
165
|
if fact.nil?
|
166
|
-
fact =
|
166
|
+
fact = Facter::Util::Fact.new(name, options)
|
167
167
|
@facts[name] = fact
|
168
168
|
else
|
169
169
|
fact.extract_ldapname_option!(options)
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# Create facts using {Facter.add}
|
7
7
|
#
|
8
8
|
# @api public
|
9
|
-
module
|
9
|
+
module Facter
|
10
10
|
module Util
|
11
11
|
class Fact
|
12
12
|
# The name of the fact
|
@@ -201,7 +201,7 @@ module LegacyFacter
|
|
201
201
|
when :simple
|
202
202
|
resolve = Facter::Util::Resolution.new(resolution_name, self)
|
203
203
|
when :aggregate
|
204
|
-
resolve =
|
204
|
+
resolve = Facter::Core::Aggregate.new(resolution_name, self)
|
205
205
|
else
|
206
206
|
raise ArgumentError,
|
207
207
|
"Expected resolution type to be one of (:simple, :aggregate) but was #{resolution_type}"
|
@@ -38,7 +38,7 @@ module Facter
|
|
38
38
|
attr_accessor :name
|
39
39
|
|
40
40
|
# @!attribute [r] fact
|
41
|
-
# @return [
|
41
|
+
# @return [Facter::Util::Fact]
|
42
42
|
# @api private
|
43
43
|
attr_reader :fact
|
44
44
|
|
@@ -115,7 +115,7 @@ module Facter
|
|
115
115
|
def setcode(string = nil, &block)
|
116
116
|
if string
|
117
117
|
@code = proc do
|
118
|
-
output =
|
118
|
+
output = Facter::Core::Execution.execute(string, on_fail: nil)
|
119
119
|
if output.nil? || output.empty?
|
120
120
|
nil
|
121
121
|
else
|
data/lib/facter.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pathname'
|
4
|
+
require_relative 'util/api_debugger' if ENV['API_DEBUG']
|
4
5
|
|
5
6
|
ROOT_DIR = Pathname.new(File.expand_path('..', __dir__)) unless defined?(ROOT_DIR)
|
6
7
|
|
@@ -24,7 +25,7 @@ module Facter
|
|
24
25
|
# Alias method for Facter.fact()
|
25
26
|
# @param name [string] fact name
|
26
27
|
#
|
27
|
-
# @return [
|
28
|
+
# @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
|
28
29
|
# is found.
|
29
30
|
#
|
30
31
|
# @api public
|
@@ -39,7 +40,7 @@ module Facter
|
|
39
40
|
# supplied here
|
40
41
|
# @param block [Proc] a block defining a fact resolution
|
41
42
|
#
|
42
|
-
# @return [
|
43
|
+
# @return [Facter::Util::Fact] the fact object, which includes any previously
|
43
44
|
# defined resolutions
|
44
45
|
#
|
45
46
|
# @api public
|
@@ -114,7 +115,7 @@ module Facter
|
|
114
115
|
#
|
115
116
|
# @param name [String] the name of the fact
|
116
117
|
#
|
117
|
-
# @return [
|
118
|
+
# @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
|
118
119
|
# is found.
|
119
120
|
#
|
120
121
|
# @api public
|
@@ -192,7 +193,7 @@ module Facter
|
|
192
193
|
log_blocked_facts
|
193
194
|
|
194
195
|
resolved_facts = Facter::FactManager.instance.resolve_facts
|
195
|
-
|
196
|
+
SessionCache.invalidate_all_caches
|
196
197
|
FactCollection.new.build_fact_collection!(resolved_facts)
|
197
198
|
end
|
198
199
|
|
@@ -250,7 +251,7 @@ module Facter
|
|
250
251
|
log_blocked_facts
|
251
252
|
|
252
253
|
resolved_facts = Facter::FactManager.instance.resolve_facts(args)
|
253
|
-
|
254
|
+
SessionCache.invalidate_all_caches
|
254
255
|
fact_formatter = Facter::FormatterFactory.build(@options)
|
255
256
|
|
256
257
|
status = error_check(args, resolved_facts)
|
@@ -288,7 +289,7 @@ module Facter
|
|
288
289
|
@options.refresh([user_query])
|
289
290
|
user_query = user_query.to_s
|
290
291
|
resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
|
291
|
-
|
292
|
+
SessionCache.invalidate_all_caches
|
292
293
|
fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
|
293
294
|
splitted_user_query = Facter::Utils.split_user_query(user_query)
|
294
295
|
|
@@ -369,5 +370,7 @@ module Facter
|
|
369
370
|
)
|
370
371
|
nil
|
371
372
|
end
|
373
|
+
|
374
|
+
prepend ApiDebugger if ENV['API_DEBUG']
|
372
375
|
end
|
373
376
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facts
|
4
|
+
module Aix
|
5
|
+
class Mountpoints
|
6
|
+
FACT_NAME = 'mountpoints'
|
7
|
+
|
8
|
+
def call_the_resolver
|
9
|
+
mountpoints = Facter::Resolvers::Aix::Mountpoints.resolve(:mountpoints)
|
10
|
+
|
11
|
+
Facter::ResolvedFact.new(FACT_NAME, mountpoints)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,20 +9,29 @@ module Facts
|
|
9
9
|
ALIASES = %w[lsbdistrelease lsbmajdistrelease lsbminordistrelease].freeze
|
10
10
|
|
11
11
|
def call_the_resolver
|
12
|
-
fact_value =
|
12
|
+
fact_value = determine_release_for_os
|
13
|
+
|
13
14
|
return Facter::ResolvedFact.new(FACT_NAME, nil) unless fact_value
|
14
15
|
|
15
16
|
versions = fact_value.split('.')
|
16
|
-
release = {
|
17
|
-
'full' => fact_value,
|
18
|
-
'major' => versions[0],
|
19
|
-
'minor' => versions[1]
|
20
|
-
}
|
17
|
+
release = { 'full' => fact_value, 'major' => versions[0], 'minor' => versions[1].gsub(/^0([1-9])/, '\1') }
|
21
18
|
|
22
19
|
[Facter::ResolvedFact.new(FACT_NAME, release),
|
23
20
|
Facter::ResolvedFact.new(ALIASES[0], fact_value, :legacy),
|
24
|
-
Facter::ResolvedFact.new(ALIASES[1],
|
25
|
-
Facter::ResolvedFact.new(ALIASES[2],
|
21
|
+
Facter::ResolvedFact.new(ALIASES[1], release['major'], :legacy),
|
22
|
+
Facter::ResolvedFact.new(ALIASES[2], release['minor'], :legacy)]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def determine_release_for_os
|
28
|
+
os_name = Facter::Resolvers::OsRelease.resolve(:name)
|
29
|
+
|
30
|
+
if os_name =~ /Debian|Raspbian/
|
31
|
+
Facter::Resolvers::DebianVersion.resolve(:version)
|
32
|
+
else
|
33
|
+
Facter::Resolvers::OsRelease.resolve(:version_id)
|
34
|
+
end
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/facts/debian/os/name.rb
CHANGED
@@ -8,7 +8,7 @@ module Facts
|
|
8
8
|
ALIASES = 'operatingsystem'
|
9
9
|
|
10
10
|
def call_the_resolver
|
11
|
-
fact_value = Facter::Resolvers::
|
11
|
+
fact_value = Facter::Resolvers::OsRelease.resolve(:name)
|
12
12
|
|
13
13
|
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
|
14
14
|
end
|
@@ -8,7 +8,7 @@ module Facts
|
|
8
8
|
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze
|
9
9
|
|
10
10
|
def call_the_resolver
|
11
|
-
fact_value =
|
11
|
+
fact_value = determine_release_for_os
|
12
12
|
|
13
13
|
return Facter::ResolvedFact.new(FACT_NAME, nil) unless fact_value
|
14
14
|
|
@@ -16,13 +16,25 @@ module Facts
|
|
16
16
|
release = {
|
17
17
|
'full' => fact_value,
|
18
18
|
'major' => versions[0],
|
19
|
-
'minor' => versions[1]
|
19
|
+
'minor' => versions[1].gsub(/^0([1-9])/, '\1')
|
20
20
|
}
|
21
21
|
|
22
22
|
[Facter::ResolvedFact.new(FACT_NAME, release),
|
23
23
|
Facter::ResolvedFact.new(ALIASES.first, versions[0], :legacy),
|
24
24
|
Facter::ResolvedFact.new(ALIASES.last, fact_value, :legacy)]
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def determine_release_for_os
|
30
|
+
os_name = Facter::Resolvers::OsRelease.resolve(:name)
|
31
|
+
|
32
|
+
if os_name =~ /Debian|Raspbian/
|
33
|
+
Facter::Resolvers::DebianVersion.resolve(:version)
|
34
|
+
else
|
35
|
+
Facter::Resolvers::OsRelease.resolve(:version_id)
|
36
|
+
end
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facts
|
4
|
+
module Debian
|
5
|
+
class Partitions
|
6
|
+
FACT_NAME = 'partitions'
|
7
|
+
|
8
|
+
def call_the_resolver
|
9
|
+
Facter::ResolvedFact.new(FACT_NAME, partitions)
|
10
|
+
end
|
11
|
+
|
12
|
+
def partitions
|
13
|
+
parts = Facter::Resolvers::Partitions.resolve(:partitions)
|
14
|
+
mountpoints = Facter::Resolvers::Linux::Mountpoints.resolve(:mountpoints)
|
15
|
+
return parts unless mountpoints
|
16
|
+
|
17
|
+
mountpoints.each do |mnt|
|
18
|
+
next unless parts[mnt[:device]]
|
19
|
+
|
20
|
+
parts[mnt[:device]].merge!(mount: mnt[:path])
|
21
|
+
end
|
22
|
+
parts.empty? ? nil : parts
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facts
|
4
|
+
module El
|
5
|
+
class Partitions
|
6
|
+
FACT_NAME = 'partitions'
|
7
|
+
|
8
|
+
def call_the_resolver
|
9
|
+
Facter::ResolvedFact.new(FACT_NAME, partitions)
|
10
|
+
end
|
11
|
+
|
12
|
+
def partitions
|
13
|
+
parts = Facter::Resolvers::Partitions.resolve(:partitions)
|
14
|
+
mountpoints = Facter::Resolvers::Linux::Mountpoints.resolve(:mountpoints)
|
15
|
+
return parts unless mountpoints
|
16
|
+
|
17
|
+
mountpoints.each do |mnt|
|
18
|
+
next unless parts[mnt[:device]]
|
19
|
+
|
20
|
+
parts[mnt[:device]].merge!(mount: mnt[:path])
|
21
|
+
end
|
22
|
+
parts.empty? ? nil : parts
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facts
|
4
|
+
module Sles
|
5
|
+
class Partitions
|
6
|
+
FACT_NAME = 'partitions'
|
7
|
+
|
8
|
+
def call_the_resolver
|
9
|
+
Facter::ResolvedFact.new(FACT_NAME, partitions)
|
10
|
+
end
|
11
|
+
|
12
|
+
def partitions
|
13
|
+
parts = Facter::Resolvers::Partitions.resolve(:partitions)
|
14
|
+
mountpoints = Facter::Resolvers::Linux::Mountpoints.resolve(:mountpoints)
|
15
|
+
return parts unless mountpoints
|
16
|
+
|
17
|
+
mountpoints.each do |mnt|
|
18
|
+
next unless parts[mnt[:device]]
|
19
|
+
|
20
|
+
parts[mnt[:device]].merge!(mount: mnt[:path])
|
21
|
+
end
|
22
|
+
parts.empty? ? nil : parts
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|