facter 4.0.9.pre → 4.0.10.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rtc.yml +11 -0
- data/.rubocop_todo.yml +10 -190
- data/VERSION +1 -1
- data/facter.gemspec +1 -0
- data/lib/custom_facts/core/aggregate.rb +4 -6
- data/lib/custom_facts/core/execution.rb +1 -1
- data/lib/custom_facts/core/execution/base.rb +15 -24
- data/lib/custom_facts/core/execution/posix.rb +2 -2
- data/lib/custom_facts/core/resolvable.rb +1 -1
- data/lib/custom_facts/core/suitable.rb +2 -1
- data/lib/custom_facts/util/fact.rb +3 -3
- data/lib/custom_facts/util/loader.rb +2 -2
- data/lib/custom_facts/util/parser.rb +7 -7
- data/lib/custom_facts/util/resolution.rb +1 -3
- data/lib/custom_facts/version.rb +1 -1
- data/lib/facter.rb +217 -41
- data/lib/facts/aix/augeas/version.rb +4 -1
- data/lib/facts/aix/filesystems.rb +14 -0
- data/lib/facts/aix/identity/user.rb +17 -0
- data/lib/facts/aix/puppet_version.rb +15 -0
- data/lib/facts/aix/system_uptime/days.rb +16 -0
- data/lib/facts/aix/system_uptime/hours.rb +16 -0
- data/lib/facts/aix/system_uptime/seconds.rb +16 -0
- data/lib/facts/aix/system_uptime/uptime.rb +16 -0
- data/lib/facts/aix/timezone.rb +14 -0
- data/lib/facts/debian/augeas/version.rb +19 -0
- data/lib/facts/debian/dmi/bios/release_date.rb +2 -1
- data/lib/facts/debian/dmi/bios/vendor.rb +2 -1
- data/lib/facts/debian/dmi/bios/version.rb +2 -1
- data/lib/facts/debian/dmi/board/manufacturer.rb +2 -1
- data/lib/facts/debian/dmi/board/product.rb +2 -1
- data/lib/facts/debian/dmi/board/serial_number.rb +2 -1
- data/lib/facts/debian/dmi/chassis/asset_tag.rb +2 -1
- data/lib/facts/debian/dmi/chassis/type.rb +2 -1
- data/lib/facts/debian/dmi/manufacturer.rb +2 -1
- data/lib/facts/debian/dmi/product/name.rb +2 -1
- data/lib/facts/debian/identity/user.rb +17 -0
- data/lib/facts/debian/interfaces.rb +16 -0
- data/lib/facts/debian/memory/swap/available.rb +2 -1
- data/lib/facts/debian/memory/swap/available_bytes.rb +4 -1
- data/lib/facts/debian/memory/swap/total.rb +2 -1
- data/lib/facts/debian/memory/swap/total_bytes.rb +3 -1
- data/lib/facts/debian/memory/system/available.rb +3 -1
- data/lib/facts/debian/memory/system/available_bytes.rb +4 -1
- data/lib/facts/debian/memory/system/total.rb +2 -1
- data/lib/facts/debian/memory/system/total_bytes.rb +3 -1
- data/lib/facts/debian/networking/mac.rb +18 -0
- data/lib/facts/debian/os/distro/codename.rb +21 -0
- data/lib/facts/debian/os/distro/description.rb +21 -0
- data/lib/facts/debian/os/distro/id.rb +21 -0
- data/lib/facts/debian/os/distro/release.rb +31 -0
- data/lib/facts/debian/os/distro/specification.rb +21 -0
- data/lib/facts/debian/os/hardware.rb +2 -1
- data/lib/facts/debian/os/selinux/config_mode.rb +21 -0
- data/lib/facts/debian/os/selinux/config_policy.rb +21 -0
- data/lib/facts/debian/os/selinux/current_mode.rb +21 -0
- data/lib/facts/debian/os/selinux/enabled.rb +21 -0
- data/lib/facts/debian/os/selinux/enforced.rb +21 -0
- data/lib/facts/debian/os/selinux/policy_version.rb +21 -0
- data/lib/facts/debian/processors/count.rb +2 -1
- data/lib/facts/debian/processors/isa.rb +3 -2
- data/lib/facts/debian/processors/physicalcount.rb +2 -1
- data/lib/facts/debian/puppet_version.rb +15 -0
- data/lib/facts/debian/ruby/platform.rb +2 -1
- data/lib/facts/debian/ruby/sitedir.rb +2 -1
- data/lib/facts/debian/system_uptime/days.rb +2 -1
- data/lib/facts/debian/system_uptime/hours.rb +2 -1
- data/lib/facts/debian/system_uptime/seconds.rb +18 -0
- data/lib/facts/debian/system_uptime/uptime.rb +2 -1
- data/lib/facts/el/augeas/version.rb +19 -0
- data/lib/facts/el/dmi/bios/release_date.rb +2 -1
- data/lib/facts/el/dmi/bios/vendor.rb +2 -1
- data/lib/facts/el/dmi/bios/version.rb +2 -1
- data/lib/facts/el/dmi/board/manufacturer.rb +2 -1
- data/lib/facts/el/dmi/board/product.rb +2 -1
- data/lib/facts/el/dmi/board/serial_number.rb +2 -1
- data/lib/facts/el/dmi/chassis/asset_tag.rb +2 -1
- data/lib/facts/el/dmi/chassis/type.rb +2 -1
- data/lib/facts/el/dmi/manufacturer.rb +2 -1
- data/lib/facts/el/dmi/product/name.rb +2 -1
- data/lib/facts/el/dmi/product/serial_number.rb +2 -1
- data/lib/facts/el/dmi/product/uuid.rb +2 -1
- data/lib/facts/el/identity/user.rb +17 -0
- data/lib/facts/el/interfaces.rb +16 -0
- data/lib/facts/el/memory/swap/available.rb +2 -1
- data/lib/facts/el/memory/swap/available_bytes.rb +3 -1
- data/lib/facts/el/memory/swap/total.rb +2 -1
- data/lib/facts/el/memory/swap/total_bytes.rb +3 -1
- data/lib/facts/el/memory/system/available.rb +2 -1
- data/lib/facts/el/memory/system/available_bytes.rb +3 -1
- data/lib/facts/el/memory/system/total.rb +2 -1
- data/lib/facts/el/memory/system/total_bytes.rb +3 -1
- data/lib/facts/el/networking/mac.rb +18 -0
- data/lib/facts/el/os/distro/codename.rb +21 -0
- data/lib/facts/el/os/distro/description.rb +21 -0
- data/lib/facts/el/os/distro/id.rb +21 -0
- data/lib/facts/el/os/distro/release.rb +31 -0
- data/lib/facts/el/os/distro/specification.rb +21 -0
- data/lib/facts/el/os/hardware.rb +2 -1
- data/lib/facts/el/os/selinux/config_mode.rb +21 -0
- data/lib/facts/el/os/selinux/config_policy.rb +21 -0
- data/lib/facts/el/os/selinux/current_mode.rb +21 -0
- data/lib/facts/el/os/selinux/enabled.rb +21 -0
- data/lib/facts/el/os/selinux/enforced.rb +21 -0
- data/lib/facts/el/os/selinux/policy_version.rb +21 -0
- data/lib/facts/el/processor.rb +19 -0
- data/lib/facts/el/processors/count.rb +2 -1
- data/lib/facts/el/processors/isa.rb +3 -1
- data/lib/facts/el/processors/physicalcount.rb +3 -1
- data/lib/facts/el/puppet_version.rb +15 -0
- data/lib/facts/el/ruby/platform.rb +3 -1
- data/lib/facts/el/ruby/sitedir.rb +3 -1
- data/lib/facts/el/ruby/version.rb +1 -0
- data/lib/facts/el/sshalgorithmkey.rb +16 -0
- data/lib/facts/el/sshfp_algorithm.rb +19 -0
- data/lib/facts/el/system_uptime/days.rb +3 -1
- data/lib/facts/el/system_uptime/hours.rb +3 -1
- data/lib/facts/el/system_uptime/seconds.rb +3 -1
- data/lib/facts/el/system_uptime/uptime.rb +3 -1
- data/lib/facts/macosx/augeas/version.rb +19 -0
- data/lib/facts/macosx/dmi/product/name.rb +2 -1
- data/lib/facts/macosx/identity/group.rb +2 -0
- data/lib/facts/macosx/identity/user.rb +2 -1
- data/lib/facts/macosx/interfaces.rb +15 -0
- data/lib/facts/macosx/memory/swap/available.rb +2 -1
- data/lib/facts/macosx/memory/swap/available_bytes.rb +3 -1
- data/lib/facts/macosx/memory/swap/encrypted.rb +2 -1
- data/lib/facts/macosx/memory/swap/total.rb +2 -1
- data/lib/facts/macosx/memory/swap/total_bytes.rb +3 -1
- data/lib/facts/macosx/memory/system/available.rb +2 -1
- data/lib/facts/macosx/memory/system/available_bytes.rb +3 -1
- data/lib/facts/macosx/memory/system/total.rb +2 -1
- data/lib/facts/macosx/memory/system/total_bytes.rb +3 -1
- data/lib/facts/macosx/networking/mac.rb +18 -0
- data/lib/facts/macosx/os/hardware.rb +2 -1
- data/lib/facts/macosx/os/macosx/build.rb +2 -2
- data/lib/facts/macosx/os/macosx/product.rb +2 -2
- data/lib/facts/macosx/os/macosx/version.rb +5 -1
- data/lib/facts/macosx/os/release.rb +11 -5
- data/lib/facts/macosx/processors/count.rb +2 -1
- data/lib/facts/macosx/processors/isa.rb +2 -1
- data/lib/facts/macosx/processors/models.rb +6 -1
- data/lib/facts/macosx/processors/physicalcount.rb +2 -1
- data/lib/facts/macosx/{augeas.rb → puppet_version.rb} +4 -3
- data/lib/facts/macosx/ruby/platform.rb +2 -2
- data/lib/facts/macosx/ruby/sitedir.rb +2 -2
- data/lib/facts/macosx/ssh.rb +26 -0
- data/lib/facts/macosx/sshalgorithmkey.rb +16 -0
- data/lib/facts/macosx/sshfp_algorithm.rb +19 -0
- data/lib/facts/macosx/system_profiler/boot_mode.rb +2 -1
- data/lib/facts/macosx/system_profiler/boot_rom_version.rb +2 -1
- data/lib/facts/macosx/system_profiler/boot_volume.rb +2 -1
- data/lib/facts/macosx/system_profiler/computer_name.rb +2 -1
- data/lib/facts/macosx/system_profiler/cores.rb +2 -1
- data/lib/facts/macosx/system_profiler/hardware_uuid.rb +2 -1
- data/lib/facts/macosx/system_profiler/kernel_version.rb +2 -1
- data/lib/facts/macosx/system_profiler/l2_cache_per_core.rb +2 -1
- data/lib/facts/macosx/system_profiler/l3_cache.rb +2 -1
- data/lib/facts/macosx/system_profiler/memory.rb +2 -1
- data/lib/facts/macosx/system_profiler/model_identifier.rb +2 -1
- data/lib/facts/macosx/system_profiler/model_name.rb +2 -1
- data/lib/facts/macosx/system_profiler/processor_name.rb +2 -1
- data/lib/facts/macosx/system_profiler/processor_speed.rb +2 -1
- data/lib/facts/macosx/system_profiler/processors.rb +2 -1
- data/lib/facts/macosx/system_profiler/secure_virtual_memory.rb +2 -1
- data/lib/facts/macosx/system_profiler/serial_number.rb +2 -1
- data/lib/facts/macosx/system_profiler/smc_version.rb +2 -1
- data/lib/facts/macosx/system_profiler/system_version.rb +2 -1
- data/lib/facts/macosx/system_profiler/uptime.rb +2 -1
- data/lib/facts/macosx/system_profiler/username.rb +2 -1
- data/lib/facts/macosx/system_uptime/days.rb +2 -1
- data/lib/facts/macosx/system_uptime/hours.rb +2 -1
- data/lib/facts/macosx/system_uptime/seconds.rb +2 -1
- data/lib/facts/macosx/system_uptime/uptime.rb +2 -1
- data/lib/facts/sles/augeas/version.rb +19 -0
- data/lib/facts/sles/disks.rb +15 -0
- data/lib/facts/sles/dmi/bios/release_date.rb +19 -0
- data/lib/facts/sles/dmi/bios/vendor.rb +19 -0
- data/lib/facts/sles/dmi/bios/version.rb +19 -0
- data/lib/facts/sles/dmi/board/manufacturer.rb +19 -0
- data/lib/facts/sles/dmi/board/product.rb +19 -0
- data/lib/facts/sles/dmi/board/serial_number.rb +19 -0
- data/lib/facts/sles/dmi/chassis/asset_tag.rb +19 -0
- data/lib/facts/sles/dmi/chassis/type.rb +19 -0
- data/lib/facts/sles/dmi/manufacturer.rb +17 -0
- data/lib/facts/sles/dmi/product/name.rb +19 -0
- data/lib/facts/sles/dmi/product/serial_number.rb +19 -0
- data/lib/facts/sles/dmi/product/uuid.rb +19 -0
- data/lib/facts/sles/filesystems.rb +14 -0
- data/lib/facts/sles/fips_enabled.rb +14 -0
- data/lib/facts/sles/identity/user.rb +17 -0
- data/lib/facts/sles/interfaces.rb +16 -0
- data/lib/facts/sles/load_averages.rb +14 -0
- data/lib/facts/sles/memory/swap/available.rb +2 -1
- data/lib/facts/sles/memory/swap/available_bytes.rb +3 -1
- data/lib/facts/sles/memory/swap/total.rb +2 -1
- data/lib/facts/sles/memory/swap/total_bytes.rb +3 -1
- data/lib/facts/sles/memory/swap/used.rb +1 -1
- data/lib/facts/sles/memory/swap/used_bytes.rb +1 -1
- data/lib/facts/sles/memory/system/available.rb +2 -1
- data/lib/facts/sles/memory/system/available_bytes.rb +3 -1
- data/lib/facts/sles/memory/system/total.rb +2 -1
- data/lib/facts/sles/memory/system/total_bytes.rb +3 -1
- data/lib/facts/sles/mountpoints.rb +21 -0
- data/lib/facts/sles/networking/mac.rb +18 -0
- data/lib/facts/sles/os/distro/codename.rb +21 -0
- data/lib/facts/sles/os/distro/description.rb +21 -0
- data/lib/facts/sles/os/distro/id.rb +21 -0
- data/lib/facts/sles/os/distro/release.rb +31 -0
- data/lib/facts/sles/os/distro/specification.rb +21 -0
- data/lib/facts/sles/os/family.rb +1 -1
- data/lib/facts/sles/os/hardware.rb +2 -1
- data/lib/facts/sles/os/release.rb +3 -3
- data/lib/facts/sles/os/selinux/config_mode.rb +21 -0
- data/lib/facts/sles/os/selinux/config_policy.rb +21 -0
- data/lib/facts/sles/os/selinux/current_mode.rb +21 -0
- data/lib/facts/sles/os/selinux/enabled.rb +21 -0
- data/lib/facts/sles/os/selinux/enforced.rb +21 -0
- data/lib/facts/sles/os/selinux/policy_version.rb +21 -0
- data/lib/facts/sles/puppet_version.rb +15 -0
- data/lib/facts/sles/ruby/platform.rb +3 -1
- data/lib/facts/sles/ruby/sitedir.rb +3 -1
- data/lib/facts/sles/ruby/version.rb +1 -0
- data/lib/facts/sles/sshalgorithmkey.rb +16 -0
- data/lib/facts/sles/sshfp_algorithm.rb +19 -0
- data/lib/facts/sles/system_uptime/days.rb +18 -0
- data/lib/facts/sles/system_uptime/hours.rb +18 -0
- data/lib/facts/sles/system_uptime/seconds.rb +18 -0
- data/lib/facts/sles/system_uptime/uptime.rb +18 -0
- data/lib/facts/solaris/augeas/version.rb +19 -0
- data/lib/facts/solaris/filesystems.rb +14 -0
- data/lib/facts/solaris/identity/user.rb +17 -0
- data/lib/facts/solaris/os/hardware.rb +3 -1
- data/lib/facts/solaris/puppet_version.rb +15 -0
- data/lib/facts/solaris/ruby/platform.rb +3 -1
- data/lib/facts/solaris/ruby/sitedir.rb +2 -1
- data/lib/facts/solaris/solaris_zones/current.rb +3 -1
- data/lib/facts/solaris/solaris_zones/zone.rb +39 -6
- data/lib/facts/solaris/ssh.rb +26 -0
- data/lib/facts/solaris/system_uptime/days.rb +17 -0
- data/lib/facts/solaris/system_uptime/hours.rb +17 -0
- data/lib/facts/{debian/system_uptime/minutes.rb → solaris/system_uptime/seconds.rb} +4 -4
- data/lib/facts/solaris/system_uptime/uptime.rb +17 -0
- data/lib/facts/solaris/timezone.rb +14 -0
- data/lib/facts/windows/augeas/version.rb +19 -0
- data/lib/facts/windows/puppet_version.rb +15 -0
- data/lib/facts_utils/bytes_converter.rb +15 -0
- data/lib/framework/config/block_list.rb +1 -1
- data/lib/framework/config/config_reader.rb +1 -1
- data/lib/framework/core/fact/external/external_fact_manager.rb +1 -1
- data/lib/framework/core/fact_loaders/external_fact_loader.rb +1 -1
- data/lib/framework/core/fact_manager.rb +5 -0
- data/lib/framework/logging/logger.rb +10 -1
- data/lib/models/fact_collection.rb +15 -1
- data/lib/models/resolved_fact.rb +5 -1
- data/lib/resolvers/aix/filesystem_resolver.rb +33 -0
- data/lib/resolvers/disk_resolver.rb +11 -3
- data/lib/resolvers/dmi_resolver.rb +1 -1
- data/lib/resolvers/filesystems_resolver.rb +2 -0
- data/lib/resolvers/fips_enabled_resolver.rb +2 -1
- data/lib/resolvers/hostname_resolver.rb +1 -1
- data/lib/resolvers/load_averages_resolver.rb +2 -0
- data/lib/resolvers/lsb_release_resolver.rb +23 -5
- data/lib/resolvers/macosx/ipaddress_resolver.rb +14 -1
- data/lib/resolvers/memory_resolver.rb +2 -0
- data/lib/resolvers/mountpoints_resolver.rb +2 -0
- data/lib/resolvers/networking_linux_resolver.rb +7 -1
- data/lib/resolvers/os_release_resolver.rb +1 -1
- data/lib/resolvers/processors_resolver.rb +2 -0
- data/lib/resolvers/puppet_version_resolver.rb +27 -0
- data/lib/resolvers/selinux_resolver.rb +36 -4
- data/lib/resolvers/solaris/filesystems_resolver.rb +32 -0
- data/lib/resolvers/solaris/zone_resolver.rb +4 -4
- data/lib/resolvers/ssh_resolver.rb +1 -1
- metadata +123 -8
- data/lib/facts/debian/os/distro.rb +0 -31
- data/lib/facts/debian/os/selinux.rb +0 -23
- data/lib/facts/el/os/selinux.rb +0 -23
- data/lib/facts/sles/os/selinux.rb +0 -23
@@ -13,11 +13,11 @@ module LegacyFacter
|
|
13
13
|
|
14
14
|
def which(bin)
|
15
15
|
if absolute_path?(bin)
|
16
|
-
return bin if File.executable?(bin) &&
|
16
|
+
return bin if File.executable?(bin) && FileTest.file?(bin)
|
17
17
|
else
|
18
18
|
search_paths.each do |dir|
|
19
19
|
dest = File.join(dir, bin)
|
20
|
-
return dest if File.executable?(dest) &&
|
20
|
+
return dest if File.executable?(dest) && FileTest.file?(dest)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
nil
|
@@ -5,7 +5,7 @@ require 'timeout'
|
|
5
5
|
# The resolvable mixin defines behavior for evaluating and returning fact
|
6
6
|
# resolutions.
|
7
7
|
#
|
8
|
-
# Classes including this mixin should implement
|
8
|
+
# Classes including this mixin should implement a #name method describing
|
9
9
|
# the value being resolved and a #resolve_value that actually executes the code
|
10
10
|
# to resolve the value.
|
11
11
|
module LegacyFacter
|
@@ -20,6 +20,7 @@ module LegacyFacter
|
|
20
20
|
# @api public
|
21
21
|
def has_weight(weight)
|
22
22
|
@weight = weight
|
23
|
+
self
|
23
24
|
end
|
24
25
|
|
25
26
|
# Sets the conditions for this resolution to be used. This method accepts
|
@@ -69,7 +70,7 @@ module LegacyFacter
|
|
69
70
|
# evaluates to `false` or `nil` then the confined fact will not be
|
70
71
|
# evaluated.
|
71
72
|
# @example Confine the fact to systems with a specific file.
|
72
|
-
# confine { File.
|
73
|
+
# confine { File.readable? '/bin/foo' }
|
73
74
|
def confine(confines = nil, &block)
|
74
75
|
case confines
|
75
76
|
when Hash
|
@@ -11,7 +11,7 @@ module LegacyFacter
|
|
11
11
|
class Fact
|
12
12
|
# The name of the fact
|
13
13
|
# @return [String]
|
14
|
-
|
14
|
+
attr_reader :name
|
15
15
|
|
16
16
|
# @return [String]
|
17
17
|
# @deprecated
|
@@ -161,7 +161,7 @@ module LegacyFacter
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def sort_by_weight(resolutions)
|
164
|
-
resolutions.sort { |a, b| b.weight
|
164
|
+
resolutions.sort { |a, b| b.weight <=> a.weight }
|
165
165
|
end
|
166
166
|
|
167
167
|
def find_first_real_value(resolutions)
|
@@ -171,7 +171,7 @@ module LegacyFacter
|
|
171
171
|
rescue Facter::ResolveCustomFactError
|
172
172
|
break
|
173
173
|
end
|
174
|
-
@used_resolution_weight = resolve.weight
|
174
|
+
@used_resolution_weight = resolve.weight
|
175
175
|
return value unless value.nil?
|
176
176
|
end
|
177
177
|
nil
|
@@ -25,7 +25,7 @@ module LegacyFacter
|
|
25
25
|
# Load individual files
|
26
26
|
file = File.join(dir, filename)
|
27
27
|
|
28
|
-
load_file(file) if
|
28
|
+
load_file(file) if FileTest.file?(file)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -42,7 +42,7 @@ module LegacyFacter
|
|
42
42
|
# dir is already an absolute path
|
43
43
|
Dir.glob(File.join(dir, '*.rb')).each do |path|
|
44
44
|
# exclude dirs that end with .rb
|
45
|
-
load_file(path) if
|
45
|
+
load_file(path) if FileTest.file?(path)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -131,7 +131,7 @@ module LegacyFacter
|
|
131
131
|
|
132
132
|
class ScriptParser < Base
|
133
133
|
def parse_results
|
134
|
-
parse_executable_output(
|
134
|
+
parse_executable_output(Facter::Core::Execution.exec(quote(filename)))
|
135
135
|
end
|
136
136
|
|
137
137
|
private
|
@@ -143,9 +143,9 @@ module LegacyFacter
|
|
143
143
|
|
144
144
|
register(ScriptParser) do |filename|
|
145
145
|
if LegacyFacter::Util::Config.windows?
|
146
|
-
extension_matches?(filename, %w[bat cmd com exe]) &&
|
146
|
+
extension_matches?(filename, %w[bat cmd com exe]) && FileTest.file?(filename)
|
147
147
|
else
|
148
|
-
File.executable?(filename) &&
|
148
|
+
File.executable?(filename) && FileTest.file?(filename) && !extension_matches?(filename, %w[bat cmd com exe])
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -154,9 +154,9 @@ module LegacyFacter
|
|
154
154
|
# Returns a hash of facts from powershell output
|
155
155
|
def parse_results
|
156
156
|
powershell =
|
157
|
-
if File.
|
157
|
+
if File.readable?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
|
158
158
|
"#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
|
159
|
-
elsif File.
|
159
|
+
elsif File.readable?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
|
160
160
|
"#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
|
161
161
|
else
|
162
162
|
'powershell.exe'
|
@@ -164,13 +164,13 @@ module LegacyFacter
|
|
164
164
|
|
165
165
|
shell_command =
|
166
166
|
"\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\""
|
167
|
-
output =
|
167
|
+
output = Facter::Core::Execution.exec(shell_command)
|
168
168
|
parse_executable_output(output)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
register(PowershellParser) do |filename|
|
173
|
-
LegacyFacter::Util::Config.windows? && extension_matches?(filename, 'ps1') &&
|
173
|
+
LegacyFacter::Util::Config.windows? && extension_matches?(filename, 'ps1') && FileTest.file?(filename)
|
174
174
|
end
|
175
175
|
|
176
176
|
# A parser that is used when there is no other parser that can handle the file
|
data/lib/custom_facts/version.rb
CHANGED
@@ -79,7 +79,7 @@ module LegacyFacter
|
|
79
79
|
# @return [String] the version -- for example: "1.6.14-6-gea42046" or nil if the VERSION
|
80
80
|
# file does not exist.
|
81
81
|
def self.read_version_file(path)
|
82
|
-
File.read(path).chomp if File.
|
82
|
+
File.read(path).chomp if File.readable?(path)
|
83
83
|
end
|
84
84
|
private_class_method :read_version_file
|
85
85
|
end
|
data/lib/facter.rb
CHANGED
@@ -13,18 +13,47 @@ module Facter
|
|
13
13
|
@options = Options.instance
|
14
14
|
Log.add_legacy_logger(STDOUT)
|
15
15
|
@logger = Log.new(self)
|
16
|
+
@already_searched = {}
|
16
17
|
|
17
18
|
class << self
|
19
|
+
def clear_messages
|
20
|
+
@logger.debug('clear_messages is not implemented')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Alias method for Facter.fact()
|
24
|
+
# @param name [string] fact name
|
25
|
+
#
|
26
|
+
# @return [LegacyFacter::Util::Fact, nil] The fact object, or nil if no fact
|
27
|
+
# is found.
|
28
|
+
#
|
29
|
+
# @api public
|
18
30
|
def [](name)
|
19
31
|
fact(name)
|
20
32
|
end
|
21
33
|
|
34
|
+
# Add custom facts to fact collection
|
35
|
+
# @param name [String] Custom fact name
|
36
|
+
# @param options = {} [Hash] optional parameters for the fact - attributes
|
37
|
+
# of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
|
38
|
+
# supplied here
|
39
|
+
# @param block [Proc] a block defining a fact resolution
|
40
|
+
#
|
41
|
+
# @return [LegacyFacter::Util::Fact] the fact object, which includes any previously
|
42
|
+
# defined resolutions
|
43
|
+
#
|
44
|
+
# @api public
|
22
45
|
def add(name, options = {}, &block)
|
23
46
|
options[:fact_type] = :custom
|
24
47
|
LegacyFacter.add(name, options, &block)
|
25
48
|
end
|
26
49
|
|
50
|
+
# Clears all cached values and removes all facts from memory.
|
51
|
+
#
|
52
|
+
# @return [nil]
|
53
|
+
#
|
54
|
+
# @api public
|
27
55
|
def clear
|
56
|
+
@already_searched = {}
|
28
57
|
LegacyFacter.clear
|
29
58
|
end
|
30
59
|
|
@@ -36,6 +65,12 @@ module Facter
|
|
36
65
|
fact_collection.dig(*splitted_user_query)
|
37
66
|
end
|
38
67
|
|
68
|
+
# Prints out a debug message when debug option is set to true
|
69
|
+
# @param msg [String] Message to be printed out
|
70
|
+
#
|
71
|
+
# @return [nil]
|
72
|
+
#
|
73
|
+
# @api public
|
39
74
|
def debug(msg)
|
40
75
|
return unless debugging?
|
41
76
|
|
@@ -47,10 +82,21 @@ module Facter
|
|
47
82
|
Facter::Log.on_message(&block)
|
48
83
|
end
|
49
84
|
|
85
|
+
# Check whether debuging is enabled
|
86
|
+
#
|
87
|
+
# @return [bool]
|
88
|
+
#
|
89
|
+
# @api public
|
50
90
|
def debugging?
|
51
91
|
Options[:debug]
|
52
92
|
end
|
53
93
|
|
94
|
+
# Enable or disable debugging
|
95
|
+
# @param debug_bool [bool] State which debugging should have
|
96
|
+
#
|
97
|
+
# @return [type] [description]
|
98
|
+
#
|
99
|
+
# @api public
|
54
100
|
def debugging(debug_bool)
|
55
101
|
@options.priority_options[:debug] = debug_bool
|
56
102
|
@options.refresh
|
@@ -58,52 +104,83 @@ module Facter
|
|
58
104
|
debug_bool
|
59
105
|
end
|
60
106
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
107
|
+
# Returns a fact object by name. If you use this, you still have to
|
108
|
+
# call {Facter::Util::Fact#value `value`} on it to retrieve the actual
|
109
|
+
# value.
|
110
|
+
#
|
111
|
+
# @param name [String] the name of the fact
|
112
|
+
#
|
113
|
+
# @return [LegacyFacter::Util::Fact, nil] The fact object, or nil if no fact
|
114
|
+
# is found.
|
115
|
+
#
|
116
|
+
# @api public
|
117
|
+
def fact(user_query)
|
118
|
+
user_query = user_query.to_s
|
119
|
+
resolve_fact(user_query)
|
73
120
|
|
74
|
-
|
75
|
-
@logger.error(
|
76
|
-
"--#{name}-- not implemented but required \n" \
|
77
|
-
'with params: ' \
|
78
|
-
"#{args.inspect} \n" \
|
79
|
-
'with block: ' \
|
80
|
-
"#{block.inspect} \n" \
|
81
|
-
"called by: \n" \
|
82
|
-
"#{caller} \n"
|
83
|
-
)
|
84
|
-
nil
|
121
|
+
@already_searched[user_query]
|
85
122
|
end
|
86
123
|
|
124
|
+
# Reset search paths for custom and external facts
|
125
|
+
# If config file is set custom and external facts will be reloaded
|
126
|
+
#
|
127
|
+
# @return [nil]
|
128
|
+
#
|
129
|
+
# @api public
|
87
130
|
def reset
|
88
131
|
LegacyFacter.reset
|
132
|
+
LegacyFacter.search(*Options.custom_dir)
|
133
|
+
LegacyFacter.search_external(Options.external_dir)
|
134
|
+
nil
|
89
135
|
end
|
90
136
|
|
137
|
+
# Register directories to be searched for custom facts. The registered directories
|
138
|
+
# must be absolute paths or they will be ignored.
|
139
|
+
#
|
140
|
+
# @param dirs [Array<String>] An array of searched directories
|
141
|
+
#
|
142
|
+
# @return [void]
|
143
|
+
#
|
144
|
+
# @api public
|
91
145
|
def search(*dirs)
|
92
146
|
LegacyFacter.search(*dirs)
|
93
147
|
end
|
94
148
|
|
149
|
+
# Registers directories to be searched for external facts.
|
150
|
+
#
|
151
|
+
# @param dirs [Array<String>] An array of searched directories
|
152
|
+
#
|
153
|
+
# @return [void]
|
154
|
+
#
|
155
|
+
# @api public
|
95
156
|
def search_external(dirs)
|
96
157
|
LegacyFacter.search_external(dirs)
|
97
158
|
end
|
98
159
|
|
160
|
+
# Returns the registered search directories.for external facts.
|
161
|
+
#
|
162
|
+
# @return [Array<String>] An array of searched directories
|
163
|
+
#
|
164
|
+
# @api public
|
99
165
|
def search_external_path
|
100
166
|
LegacyFacter.search_external_path
|
101
167
|
end
|
102
168
|
|
169
|
+
# Returns the registered search directories for custom facts.
|
170
|
+
#
|
171
|
+
# @return [Array<String>] An array of the directories searched
|
172
|
+
#
|
173
|
+
# @api public
|
103
174
|
def search_path
|
104
175
|
LegacyFacter.search_path
|
105
176
|
end
|
106
177
|
|
178
|
+
# Gets a hash mapping fact names to their values
|
179
|
+
# The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
|
180
|
+
#
|
181
|
+
# @return [FactCollection] the hash of fact names and values
|
182
|
+
#
|
183
|
+
# @api public
|
107
184
|
def to_hash
|
108
185
|
@options.priority_options[:to_hash] = true
|
109
186
|
@options.refresh
|
@@ -115,6 +192,52 @@ module Facter
|
|
115
192
|
FactCollection.new.build_fact_collection!(resolved_facts)
|
116
193
|
end
|
117
194
|
|
195
|
+
# Check whether printing stack trace is enabled
|
196
|
+
#
|
197
|
+
# @return [bool]
|
198
|
+
#
|
199
|
+
# @api public
|
200
|
+
def trace?
|
201
|
+
LegacyFacter.trace?
|
202
|
+
end
|
203
|
+
|
204
|
+
# Enable or disable trace
|
205
|
+
# @param debug_bool [bool] Set trace on debug state
|
206
|
+
#
|
207
|
+
# @return [type] [description]
|
208
|
+
#
|
209
|
+
# @api public
|
210
|
+
def trace(bool)
|
211
|
+
LegacyFacter.trace(bool)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Gets the value for a fact. Returns `nil` if no such fact exists.
|
215
|
+
#
|
216
|
+
# @param name [String] the fact name
|
217
|
+
# @return [String] the value of the fact, or nil if no fact is found
|
218
|
+
#
|
219
|
+
# @api public
|
220
|
+
def value(user_query)
|
221
|
+
user_query = user_query.to_s
|
222
|
+
resolve_fact(user_query)
|
223
|
+
@already_searched[user_query]&.value
|
224
|
+
end
|
225
|
+
|
226
|
+
# Returns Facter version
|
227
|
+
#
|
228
|
+
# @return [String] Current version
|
229
|
+
#
|
230
|
+
# @api public
|
231
|
+
def version
|
232
|
+
version_file = ::File.join(ROOT_DIR, 'VERSION')
|
233
|
+
::File.read(version_file).strip
|
234
|
+
end
|
235
|
+
|
236
|
+
# Gets a hash mapping fact names to their values
|
237
|
+
#
|
238
|
+
# @return [Array] the hash of fact names and values
|
239
|
+
#
|
240
|
+
# @api private
|
118
241
|
def to_user_output(cli_options, *args)
|
119
242
|
@options.priority_options = { is_cli: true }.merge!(cli_options.map { |(k, v)| [k.to_sym, v] }.to_h)
|
120
243
|
@options.refresh(args)
|
@@ -130,36 +253,43 @@ module Facter
|
|
130
253
|
[fact_formatter.format(resolved_facts), status || 0]
|
131
254
|
end
|
132
255
|
|
133
|
-
|
134
|
-
LegacyFacter.trace?
|
135
|
-
end
|
256
|
+
private
|
136
257
|
|
137
|
-
def
|
138
|
-
|
258
|
+
def add_fact_to_searched_facts(user_query, value)
|
259
|
+
@already_searched[user_query] ||= ResolvedFact.new(user_query, value)
|
260
|
+
@already_searched[user_query].value = value
|
139
261
|
end
|
140
262
|
|
141
|
-
|
263
|
+
# Returns a ResolvedFact and saves the result in @already_searched array that is used as a global collection.
|
264
|
+
# @param user_query [String] Fact that needs resolution
|
265
|
+
#
|
266
|
+
# @return [ResolvedFact]
|
267
|
+
def resolve_fact(user_query)
|
142
268
|
@options.refresh([user_query])
|
143
269
|
user_query = user_query.to_s
|
144
270
|
resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
|
145
271
|
CacheManager.invalidate_all_caches
|
146
272
|
fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
|
147
273
|
splitted_user_query = Facter::Utils.split_user_query(user_query)
|
148
|
-
fact_collection.dig(*splitted_user_query)
|
149
|
-
end
|
150
|
-
|
151
|
-
def version
|
152
|
-
version_file = ::File.join(ROOT_DIR, 'VERSION')
|
153
|
-
::File.read(version_file).strip
|
154
|
-
end
|
155
274
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
275
|
+
begin
|
276
|
+
value = fact_collection.value(*splitted_user_query)
|
277
|
+
add_fact_to_searched_facts(user_query, value)
|
278
|
+
rescue KeyError
|
279
|
+
nil
|
280
|
+
end
|
161
281
|
end
|
162
282
|
|
283
|
+
# Returns exit status when user query contains facts that do
|
284
|
+
# not exist
|
285
|
+
#
|
286
|
+
# @param dirs [Array] Arguments sent to CLI
|
287
|
+
# @param dirs [Array] List of resolved facts
|
288
|
+
#
|
289
|
+
# @return [Integer, nil] Will return status 1 if user query contains
|
290
|
+
# facts that are not found or resolved, otherwise it will return nil
|
291
|
+
#
|
292
|
+
# @api private
|
163
293
|
def error_check(args, resolved_facts)
|
164
294
|
if Options.instance[:strict]
|
165
295
|
missing_names = args - resolved_facts.map(&:user_query).uniq
|
@@ -173,5 +303,51 @@ module Facter
|
|
173
303
|
|
174
304
|
status
|
175
305
|
end
|
306
|
+
|
307
|
+
# Prints out blocked facts before to_hash or to_user_output is called
|
308
|
+
#
|
309
|
+
# @return [nil]
|
310
|
+
#
|
311
|
+
# @api private
|
312
|
+
def log_blocked_facts
|
313
|
+
block_list = BlockList.instance.block_list
|
314
|
+
@logger.debug("blocking collection of #{block_list.join("\s")} facts") if block_list.any? && Options[:block]
|
315
|
+
end
|
316
|
+
|
317
|
+
# Used for printing errors regarding CLI user input validation
|
318
|
+
#
|
319
|
+
# @param missing_names [Array] List of facts that were requested
|
320
|
+
# but not found
|
321
|
+
#
|
322
|
+
# @return [nil]
|
323
|
+
#
|
324
|
+
# @api private
|
325
|
+
def log_errors(missing_names)
|
326
|
+
missing_names.each do |missing_name|
|
327
|
+
@logger.error("fact \"#{missing_name}\" does not exist.", true)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
# Proxy method that catches not yet implemented method calls
|
332
|
+
#
|
333
|
+
# @param name [type] [description]
|
334
|
+
# @param *args [type] [description]
|
335
|
+
# @param &block [type] [description]
|
336
|
+
#
|
337
|
+
# @return [type] [description]
|
338
|
+
#
|
339
|
+
# @api private
|
340
|
+
def method_missing(name, *args, &block)
|
341
|
+
@logger.error(
|
342
|
+
"--#{name}-- not implemented but required \n" \
|
343
|
+
'with params: ' \
|
344
|
+
"#{args.inspect} \n" \
|
345
|
+
'with block: ' \
|
346
|
+
"#{block.inspect} \n" \
|
347
|
+
"called by: \n" \
|
348
|
+
"#{caller} \n"
|
349
|
+
)
|
350
|
+
nil
|
351
|
+
end
|
176
352
|
end
|
177
353
|
end
|