facterdb 1.20.0 → 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +17 -0
  3. data/.github/workflows/release.yml +3 -3
  4. data/.github/workflows/test.yml +29 -5
  5. data/.rubocop.yml +5 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +27 -1
  8. data/Gemfile +1 -5
  9. data/README.md +124 -119
  10. data/Rakefile +56 -51
  11. data/facterdb.gemspec +7 -7
  12. data/facts/3.14/rocky-9-x86_64.facts +597 -0
  13. data/facts/3.14/ubuntu-22.10-x86_64.facts +631 -0
  14. data/facts/4.0/rocky-9-x86_64.facts +617 -0
  15. data/facts/4.1/centos-7-x86_64.facts +582 -0
  16. data/facts/4.1/debian-10-x86_64.facts +519 -0
  17. data/facts/4.1/rocky-9-x86_64.facts +619 -0
  18. data/facts/4.2/debian-12-i386.facts +593 -0
  19. data/facts/4.2/debian-12-x86_64.facts +593 -0
  20. data/facts/4.2/fedora-37-x86_64.facts +512 -0
  21. data/facts/4.2/fedora-38-x86_64.facts +656 -0
  22. data/facts/4.2/rocky-9-x86_64.facts +626 -0
  23. data/facts/4.2/sles-12-x86_64.facts +483 -0
  24. data/facts/4.2/ubuntu-22.10-x86_64.facts +654 -0
  25. data/facts/4.3/almalinux-8-x86_64.facts +551 -0
  26. data/facts/4.3/almalinux-9-x86_64.facts +525 -0
  27. data/facts/4.3/centos-7-x86_64.facts +592 -0
  28. data/facts/4.3/debian-10-x86_64.facts +526 -0
  29. data/facts/4.3/debian-11-x86_64.facts +521 -0
  30. data/facts/4.3/debian-12-i386.facts +593 -0
  31. data/facts/4.3/debian-12-x86_64.facts +593 -0
  32. data/facts/4.3/fedora-36-x86_64.facts +507 -0
  33. data/facts/4.3/fedora-37-x86_64.facts +512 -0
  34. data/facts/4.3/fedora-38-x86_64.facts +656 -0
  35. data/facts/4.3/opensuse-15-x86_64.facts +533 -0
  36. data/facts/4.3/redhat-8-x86_64.facts +526 -0
  37. data/facts/4.3/rocky-8-x86_64.facts +545 -0
  38. data/facts/4.3/rocky-9-x86_64.facts +626 -0
  39. data/facts/4.3/sles-12-x86_64.facts +908 -0
  40. data/facts/4.3/ubuntu-18.04-x86_64.facts +557 -0
  41. data/facts/4.3/ubuntu-20.04-x86_64.facts +647 -0
  42. data/facts/4.3/ubuntu-22.04-x86_64.facts +655 -0
  43. data/facts/4.3/windows-10-x86_64.facts +182 -0
  44. data/facts/4.3/windows-11-x86_64.facts +182 -0
  45. data/facts/4.3/windows-2012 r2-x86_64.facts +179 -0
  46. data/facts/4.3/windows-2012-x86_64.facts +179 -0
  47. data/facts/4.3/windows-2016-core-x86_64.facts +181 -0
  48. data/facts/4.3/windows-2016-x86_64.facts +181 -0
  49. data/facts/4.3/windows-2019-core-x86_64.facts +181 -0
  50. data/facts/4.3/windows-2019-x86_64.facts +181 -0
  51. data/facts/4.3/windows-2022-core-x86_64.facts +183 -0
  52. data/facts/4.3/windows-2022-x86_64.facts +183 -0
  53. data/facts/4.4/almalinux-8-x86_64.facts +551 -0
  54. data/facts/4.4/almalinux-9-x86_64.facts +525 -0
  55. data/facts/4.4/centos-7-x86_64.facts +592 -0
  56. data/facts/4.4/debian-10-x86_64.facts +526 -0
  57. data/facts/4.4/debian-11-x86_64.facts +521 -0
  58. data/facts/4.4/debian-12-i386.facts +593 -0
  59. data/facts/4.4/debian-12-x86_64.facts +593 -0
  60. data/facts/4.4/fedora-36-x86_64.facts +507 -0
  61. data/facts/4.4/fedora-37-x86_64.facts +512 -0
  62. data/facts/4.4/fedora-38-x86_64.facts +656 -0
  63. data/facts/4.4/opensuse-15-x86_64.facts +514 -0
  64. data/facts/4.4/redhat-8-x86_64.facts +526 -0
  65. data/facts/4.4/rocky-8-x86_64.facts +545 -0
  66. data/facts/4.4/rocky-9-x86_64.facts +626 -0
  67. data/facts/4.4/sles-12-x86_64.facts +908 -0
  68. data/facts/4.4/ubuntu-18.04-x86_64.facts +557 -0
  69. data/facts/4.4/ubuntu-20.04-x86_64.facts +647 -0
  70. data/facts/4.4/ubuntu-22.04-x86_64.facts +655 -0
  71. data/facts/4.4/windows-10-x86_64.facts +182 -0
  72. data/facts/4.4/windows-11-x86_64.facts +186 -0
  73. data/facts/4.4/windows-2012 r2-x86_64.facts +179 -0
  74. data/facts/4.4/windows-2012-x86_64.facts +179 -0
  75. data/facts/4.4/windows-2016-core-x86_64.facts +181 -0
  76. data/facts/4.4/windows-2016-x86_64.facts +181 -0
  77. data/facts/4.4/windows-2019-core-x86_64.facts +181 -0
  78. data/facts/4.4/windows-2019-x86_64.facts +181 -0
  79. data/facts/4.4/windows-2022-core-x86_64.facts +183 -0
  80. data/facts/4.4/windows-2022-x86_64.facts +183 -0
  81. data/facts/Gemfile +3 -7
  82. data/facts/Vagrantfile +315 -275
  83. data/facts/get_facts.sh +68 -10
  84. data/lib/facterdb/bin.rb +1 -1
  85. data/lib/facterdb/version.rb +1 -1
  86. data/lib/facterdb.rb +40 -32
  87. data/rakelib/rhel_alts.rake +8 -14
  88. data/spec/facterdb_spec.rb +37 -37
  89. data/spec/facts_spec.rb +13 -7
  90. metadata +92 -6
data/facts/get_facts.sh CHANGED
@@ -65,7 +65,7 @@ case "${osfamily}" in
65
65
  wget "http://yum.puppetlabs.com/puppet7-release-el-${operatingsystemmajrelease}.noarch.rpm" -O /tmp/puppet7-release.rpm
66
66
  if test -f /tmp/puppet7-release.rpm; then
67
67
  rpm -ivh /tmp/puppet7-release.rpm
68
- for puppet_agent_version in 7.5.0 7.6.1 7.17.0; do
68
+ for puppet_agent_version in 7.5.0 7.6.1 7.17.0 7.24.0; do
69
69
  if yum install -y puppet-agent-${puppet_agent_version}; then
70
70
  output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
71
71
  mkdir -p $(dirname ${output_file})
@@ -74,15 +74,29 @@ case "${osfamily}" in
74
74
  done
75
75
  yum remove -y puppet7-release
76
76
  fi
77
+ wget "http://yum.puppetlabs.com/puppet8-release-el-${operatingsystemmajrelease}.noarch.rpm" -O /tmp/puppet8-release.rpm
78
+ if test -f /tmp/puppet8-release.rpm; then
79
+ rpm -ivh /tmp/puppet8-release.rpm
80
+ for puppet_agent_version in 8.0.0; do
81
+ if yum install -y puppet-agent-${puppet_agent_version}; then
82
+ output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter os.name | tr '[:upper:]' '[:lower:]')-$(facter os.release.major)-$(facter os.hardware).facts"
83
+ mkdir -p $(dirname ${output_file})
84
+ facter --show-legacy -p -j | tee ${output_file}
85
+ fi
86
+ done
87
+ yum remove -y puppet8-release
88
+ fi
77
89
  ;;
78
90
  'Debian')
79
- apt_install curl
91
+ apt_install curl file
80
92
  curl "https://apt.puppetlabs.com/puppet6-release-${lsbdistcodename}.deb" -o /tmp/puppet6-release.deb
81
93
  # apt.puppetlabs.com returns an html document if the requested deb doesn't exist and /tmp/puppet6-release.deb will be an html doc
82
94
  if test "$?" -eq 0 -a -f /tmp/puppet6-release.deb && [[ "$(file -b /tmp/puppet6-release.deb)" =~ "Debian binary package".* ]] ; then
83
95
  dpkg --install /tmp/puppet6-release.deb
84
96
  apt-get update
85
- for puppet_agent_version in 6.2 6.4 6.6; do
97
+ # as of 2023-04-27 older 6.x series aren't available (i.e. facter 3.12)
98
+ # the trailing dot is so that 6.4.* is the match so we get the last in the 6.4 series and not 6.40
99
+ for puppet_agent_version in 6.4. 6.28.; do
86
100
  if apt_install puppet-agent=${puppet_agent_version}*; then
87
101
  output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
88
102
  mkdir -p $(dirname ${output_file})
@@ -93,10 +107,10 @@ case "${osfamily}" in
93
107
  fi
94
108
  curl "https://apt.puppetlabs.com/puppet7-release-${lsbdistcodename}.deb" -o /tmp/puppet7-release.deb
95
109
  # apt.puppetlabs.com returns an html document if the requested deb doesn't exist and /tmp/puppet6-release.deb will be an html doc
96
- if test "$?" -eq 0 -a -f /tmp/puppet7-release.deb && [[ "$(file -b /tmp/puppet6-release.deb)" =~ "Debian binary package".* ]] ; then
110
+ if test "$?" -eq 0 -a -f /tmp/puppet7-release.deb && [[ "$(file -b /tmp/puppet7-release.deb)" =~ "Debian binary package".* ]] ; then
97
111
  dpkg --install /tmp/puppet7-release.deb
98
112
  apt-get update
99
- for puppet_agent_version in 7.5.0 7.6.1 7.12.0; do
113
+ for puppet_agent_version in 7.5.0 7.6.1 7.12.0 7.24.0; do
100
114
  if apt_install puppet-agent=${puppet_agent_version}*; then
101
115
  output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
102
116
  mkdir -p $(dirname ${output_file})
@@ -105,11 +119,33 @@ case "${osfamily}" in
105
119
  done
106
120
  apt-get -y remove --purge puppet7-release
107
121
  fi
108
- apt_install make gcc libgmp-dev
122
+ curl "https://apt.puppetlabs.com/puppet8-release-${lsbdistcodename}.deb" -o /tmp/puppet8-release.deb
123
+ # apt.puppetlabs.com returns an html document if the requested deb doesn't exist and /tmp/puppet6-release.deb will be an html doc
124
+ if test "$?" -eq 0 -a -f /tmp/puppet8-release.deb && [[ "$(file -b /tmp/puppet8-release.deb)" =~ "Debian binary package".* ]] ; then
125
+ dpkg --install /tmp/puppet8-release.deb
126
+ apt-get update
127
+ for puppet_agent_version in 8.0.0; do
128
+ if apt_install puppet-agent=${puppet_agent_version}*; then
129
+ output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter os.name | tr '[:upper:]' '[:lower:]')-$(facter os.release.major)-$(facter os.hardware).facts"
130
+ mkdir -p $(dirname ${output_file})
131
+ facter --show-legacy -p -j | tee ${output_file}
132
+ fi
133
+ done
134
+ apt-get -y remove --purge puppet8-release
135
+ fi
136
+ # libc6-dev needed to build the ffi gem
137
+ apt_install make gcc libgmp-dev libc6-dev
138
+
139
+ # puppetlabs repos/packages not yet available on bookworm https://puppet.atlassian.net/browse/PA-4995
140
+ # simply install puppet-agent that comes with the distro
141
+ if [[ "bookworm" =~ ${lsbdistcodename} ]]; then
142
+ apt_install ruby rubygems ruby-dev
143
+ facter --show-legacy -p -j | tee ${output_file}
144
+ fi
109
145
 
110
146
  # There are no puppet-agent packages for $releasename yet, so generate a Facter 3.x
111
147
  # fact set from the official Debian package.
112
- if [[ "hirsute" =~ ${lsbdistcodename} || "impish" =~ ${lsbdistcodename} || "jammy" =~ ${lsbdistcodename} ]]; then
148
+ if [[ "hirsute" =~ ${lsbdistcodename} || "impish" =~ ${lsbdistcodename} || "jammy" =~ ${lsbdistcodename} || "kinetic" =~ ${lsbdistcodename} ]]; then
113
149
  apt_install ruby rubygems ruby-dev puppet facter
114
150
  output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
115
151
  mkdir -p $(dirname ${output_file})
@@ -151,7 +187,7 @@ case "${osfamily}" in
151
187
  http_method='https'
152
188
  fi
153
189
  if rpm -Uvh ${http_method}://yum.puppet.com/puppet6-release-sles-${operatingsystemmajrelease}.noarch.rpm; then
154
- for puppet_agent_version in 6.2.0 6.4.2 6.6.0; do
190
+ for puppet_agent_version in 6.25.0 6.27.1; do
155
191
  if zypper --gpg-auto-import-keys --non-interactive install puppet-agent-${puppet_agent_version}; then
156
192
  output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
157
193
  mkdir -p $(dirname ${output_file})
@@ -160,6 +196,26 @@ case "${osfamily}" in
160
196
  done
161
197
  zypper --non-interactive remove puppet6-release
162
198
  fi
199
+ if rpm -Uvh ${http_method}://yum.puppet.com/puppet7-release-sles-${operatingsystemmajrelease}.noarch.rpm; then
200
+ for puppet_agent_version in 7.5.0 7.6.1 7.12.0 7.24.0; do
201
+ if zypper --gpg-auto-import-keys --non-interactive install puppet-agent-${puppet_agent_version}; then
202
+ output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
203
+ mkdir -p $(dirname ${output_file})
204
+ facter --show-legacy -p -j | tee ${output_file}
205
+ fi
206
+ done
207
+ zypper --non-interactive remove puppet7-release
208
+ fi
209
+ if rpm -Uvh ${http_method}://yum.puppet.com/puppet8-release-sles-${operatingsystemmajrelease}.noarch.rpm; then
210
+ for puppet_agent_version in 8.0.0; do
211
+ if zypper --gpg-auto-import-keys --non-interactive install puppet-agent-${puppet_agent_version}; then
212
+ output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
213
+ mkdir -p $(dirname ${output_file})
214
+ facter --show-legacy -p -j | tee ${output_file}
215
+ fi
216
+ done
217
+ zypper --non-interactive remove puppet8-release
218
+ fi
163
219
  ;;
164
220
  'Archlinux')
165
221
  pacman -Syu --noconfirm ruby puppet ruby-bundler base-devel dnsutils facter
@@ -174,6 +230,9 @@ case "${osfamily}" in
174
230
  facter --show-legacy -p -j | tee ${output_file}
175
231
  esac
176
232
 
233
+ # this lower section relies on the ruby version and facter version that came
234
+ # with the last installed puppet_agent per above
235
+ # puppet-agent 8.0.0 has ruby 3.2.2 and it cant install 4.0.0, 4.1.0 facter gem
177
236
  operatingsystem=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
178
237
  operatingsystemrelease=$(facter operatingsystemrelease)
179
238
  operatingsystemmajrelease=$(facter operatingsystemmajrelease)
@@ -190,7 +249,7 @@ else
190
249
  fi
191
250
  bundle install --path vendor/bundler
192
251
 
193
- for version in 4.0.0 4.1.0 4.2.0; do
252
+ for version in 4.0.0 4.1.0 4.2.0 4.3.0 4.4.0; do
194
253
  FACTER_GEM_VERSION="~> ${version}" bundle update
195
254
  # sometimes all versions of facter are not possible, if the bundle update fails, skip the rest of the loop
196
255
  if [ $? -ne 0 ]; then
@@ -223,4 +282,3 @@ for version in 4.0.0 4.1.0 4.2.0; do
223
282
  FACTER_GEM_VERSION="~> ${version}" bundle exec facter --show-legacy --json | bundle exec ruby -e 'require "json"; jj JSON.parse gets' | tee $output_file ||
224
283
  FACTER_GEM_VERSION="~> ${version}" bundle exec facter --show-legacy --json | tee $output_file
225
284
  done
226
-
data/lib/facterdb/bin.rb CHANGED
@@ -8,7 +8,7 @@ module FacterDB
8
8
  end
9
9
 
10
10
  def run
11
- puts JSON.pretty_generate(FacterDB::get_os_facts('*', @args[0]))
11
+ puts JSON.pretty_generate(FacterDB.get_os_facts('*', @args[0]))
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  module FacterDB
2
2
  module Version
3
- STRING = '1.20.0'
3
+ STRING = '1.22.0'
4
4
  end
5
5
  end
data/lib/facterdb.rb CHANGED
@@ -6,7 +6,7 @@ module FacterDB
6
6
  class InvalidFilter < RuntimeError; end
7
7
  end
8
8
 
9
- # @return [String] - returns a giant incomprehensible string of concatenated json data
9
+ # @return [String] returns a giant incomprehensible string of concatenated json data
10
10
  def self.database
11
11
  @database ||= "[#{facterdb_fact_files.map { |f| read_json_file(f) }.join(',')}]\n"
12
12
  end
@@ -18,14 +18,14 @@ module FacterDB
18
18
  Thread.current[:facterdb_last_facts_seen] = nil
19
19
  end
20
20
 
21
- # @return [Boolean] - returns true if we should use the default facterdb database, false otherwise
21
+ # @return [Boolean] returns true if we should use the default facterdb database, false otherwise
22
22
  # @note If the user passes anything to the FACTERDB_SKIP_DEFAULTDB environment variable we assume
23
23
  # they want to skip the default db
24
24
  def self.use_defaultdb?
25
25
  ENV['FACTERDB_SKIP_DEFAULTDB'].nil?
26
26
  end
27
27
 
28
- # @return [Boolean] - returns true if we should inject the source file name and file path into the json factsets.
28
+ # @return [Boolean] returns true if we should inject the source file name and file path into the json factsets.
29
29
  # The default is false.
30
30
  def self.inject_source?
31
31
  !ENV['FACTERDB_INJECT_SOURCE'].nil?
@@ -34,9 +34,11 @@ module FacterDB
34
34
  def self.read_json_file(f)
35
35
  content = File.read(f)
36
36
  return content unless inject_source?
37
+
37
38
  # Find the opening brace
38
39
  first_brace = content.index('{')
39
40
  return content if first_brace.nil?
41
+
40
42
  # Inject source file information
41
43
  json_injection = "\"_facterdb_filename\": #{File.basename(f).to_json}, "
42
44
  json_injection += "\"_facterdb_path\": #{File.expand_path(f).to_json}, "
@@ -44,19 +46,21 @@ module FacterDB
44
46
  end
45
47
  private_class_method :read_json_file
46
48
 
47
- # @return [Array[String]] - list of all files found in the default facterdb facts path
49
+ # @return [Array[String]] list of all files found in the default facterdb facts path
48
50
  def self.default_fact_files
49
51
  return [] unless use_defaultdb?
52
+
50
53
  proj_root = File.join(File.dirname(File.dirname(__FILE__)))
51
54
  facts_dir = File.expand_path(File.join(proj_root, 'facts'))
52
- Dir.glob(File.join(facts_dir, "**", '*.facts'))
55
+ Dir.glob(File.join(facts_dir, '**', '*.facts'))
53
56
  end
54
57
 
55
- # @return [Array[String]] - list of all files found in the user supplied facterdb facts path
56
- # @param fact_paths [String] - a comma separated list of paths to search for fact files
57
- def self.external_fact_files(fact_paths = ENV['FACTERDB_SEARCH_PATHS'])
58
+ # @return [Array[String]] list of all files found in the user supplied facterdb facts path
59
+ # @param fact_paths [String] a comma separated list of paths to search for fact files
60
+ def self.external_fact_files(fact_paths = ENV.fetch('FACTERDB_SEARCH_PATHS', nil))
58
61
  fact_paths ||= ''
59
62
  return [] if fact_paths.empty?
63
+
60
64
  paths = fact_paths.split(File::PATH_SEPARATOR).map do |fact_path|
61
65
  unless File.directory?(fact_path)
62
66
  warn("[FACTERDB] Ignoring external facts path #{fact_path} as it is not a directory")
@@ -68,33 +72,36 @@ module FacterDB
68
72
  Dir.glob(paths)
69
73
  end
70
74
 
71
- # @return [Array[String]] - list of all files found in the default facterdb facts path and user supplied path
75
+ # @return [Array[String]] list of all files found in the default facterdb facts path and user supplied path
72
76
  # @note external fact files supplied by the user will take precedence over default fact files found in this gem
73
77
  def self.facterdb_fact_files
74
78
  (external_fact_files + default_fact_files).uniq
75
79
  end
76
80
 
77
- def self.get_os_facts(facter_version='*', filter=[])
81
+ # @deprecated Use {.get_facts} instead.
82
+ def self.get_os_facts(facter_version = '*', filter = [])
78
83
  if facter_version == '*'
79
84
  if filter.is_a?(Array)
80
- filter_str = filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(' or ')
85
+ filter_str = filter.map { |f| f.map { |k, v| "#{k}=#{v}" }.join(' and ') }.join(' or ')
81
86
  elsif filter.is_a?(Hash)
82
- filter_str = filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
87
+ filter_str = filter.map { |k, v| "#{k}=#{v}" }.join(' and ')
83
88
  elsif filter.is_a?(String)
84
89
  filter_str = filter
85
90
  else
86
91
  raise 'filter must be either an Array a Hash or a String'
87
92
  end
93
+ elsif filter.is_a?(Array)
94
+ filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map do |f|
95
+ f.map do |k, v|
96
+ "#{k}=#{v}"
97
+ end.join(' and ')
98
+ end.join(' or ')})"
99
+ elsif filter.is_a?(Hash)
100
+ filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map { |k, v| "#{k}=#{v}" }.join(' and ')})"
101
+ elsif filter.is_a?(String)
102
+ filter_str = "facterversion=/^#{facter_version}/ and (#{filter})"
88
103
  else
89
- if filter.is_a?(Array)
90
- filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(' or ')})"
91
- elsif filter.is_a?(Hash)
92
- filter_str = "facterversion=/^#{facter_version}/ and (#{filter.map { |k,v | "#{k}=#{v}" }.join(' and ')})"
93
- elsif filter.is_a?(String)
94
- filter_str = "facterversion=/^#{facter_version}/ and (#{filter})"
95
- else
96
- raise 'filter must be either an Array a Hash or a String'
97
- end
104
+ raise 'filter must be either an Array a Hash or a String'
98
105
  end
99
106
 
100
107
  warn "[DEPRECATION] `get_os_facts` is deprecated. Please use `get_facts(#{filter_str})` instead."
@@ -102,14 +109,14 @@ module FacterDB
102
109
  get_facts(filter_str)
103
110
  end
104
111
 
105
- # @return [String] - the string filter
106
- # @param filter [Object] - The filter to convert to jgrep string
107
- def self.generate_filter_str(filter=nil)
112
+ # @return [String] the string filter
113
+ # @param filter [Object] The filter to convert to jgrep string
114
+ def self.generate_filter_str(filter = nil)
108
115
  case filter
109
116
  when ::Array
110
- '(' + filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
117
+ '(' + filter.map { |f| f.map { |k, v| "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
111
118
  when ::Hash
112
- filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
119
+ filter.map { |k, v| "#{k}=#{v}" }.join(' and ')
113
120
  when ::String
114
121
  filter
115
122
  when ::NilClass
@@ -119,8 +126,8 @@ module FacterDB
119
126
  end
120
127
  end
121
128
 
122
- # @return [Boolean] - true if the filter is valid against the jgrep filter validator
123
- # @param filter [Object] - The filter to convert to jgrep string
129
+ # @return [Boolean] true if the filter is valid against the jgrep filter validator
130
+ # @param filters [Object] The filter to convert to jgrep string
124
131
  def self.valid_filters?(filters)
125
132
  filter_str = generate_filter_str(filters)
126
133
  JGrep.validate_filters(filter_str).nil?
@@ -128,14 +135,15 @@ module FacterDB
128
135
  false
129
136
  end
130
137
 
131
- # @return [Array] - array of hashes of facts
132
- # @param filter [Object] - The filter to convert to jgrep string
133
- def self.get_facts(filter=nil, cache=true)
138
+ # @return [Array[Hash[Symbol, Any]]] array of hashes of facts
139
+ # @param filter [Object] The filter to convert to jgrep string
140
+ def self.get_facts(filter = nil, cache = true)
134
141
  if cache && filter && filter == Thread.current[:facterdb_last_filter_seen]
135
142
  return Thread.current[:facterdb_last_facts_seen]
136
143
  end
144
+
137
145
  filter_str = generate_filter_str(filter)
138
- result = JGrep.jgrep(database, filter_str).map { |hash| Hash[hash.map{ |k, v| [k.to_sym, v] }] }
146
+ result = JGrep.jgrep(database, filter_str).map { |hash| hash.map { |k, v| [k.to_sym, v] }.to_h }
139
147
  if cache
140
148
  Thread.current[:facterdb_last_filter_seen] = filter
141
149
  Thread.current[:facterdb_last_facts_seen] = result
@@ -3,22 +3,16 @@ task :rhel_alts do
3
3
  Dir[File.join(__dir__, '..', 'facts', '*', 'centos-*-x86_64.facts')].each do |f|
4
4
  centos_factset = File.read(f)
5
5
 
6
- rhel_path = f.gsub(%r{centos-}, 'redhat-')
7
- File.open(rhel_path, 'w') do |fd|
8
- fd.puts centos_factset.gsub(%r{CentOS}, 'RedHat')
9
- end
6
+ rhel_path = f.gsub('centos-', 'redhat-')
7
+ File.write(rhel_path, centos_factset.gsub('CentOS', 'RedHat'))
10
8
 
11
- oracle_path = f.gsub(%r{centos-}, 'oraclelinux-')
12
- File.open(oracle_path, 'w') do |fd|
13
- fd.puts centos_factset.gsub(%r{CentOS}, 'OracleLinux')
14
- end
9
+ oracle_path = f.gsub('centos-', 'oraclelinux-')
10
+ File.write(oracle_path, centos_factset.gsub('CentOS', 'OracleLinux'))
15
11
 
16
12
  # Scientific isn't going to be updated to 8
17
- if File.basename(f)[%r{-(\d+)-}, 1].to_i <= 7
18
- scientific_path = f.gsub(%r{centos-}, 'scientific-')
19
- File.open(scientific_path, 'w') do |fd|
20
- fd.puts centos_factset.gsub(%r{CentOS}, 'Scientific')
21
- end
22
- end
13
+ next unless File.basename(f)[/-(\d+)-/, 1].to_i <= 7
14
+
15
+ scientific_path = f.gsub('centos-', 'scientific-')
16
+ File.write(scientific_path, centos_factset.gsub('CentOS', 'Scientific'))
23
17
  end
24
18
  end
@@ -16,14 +16,14 @@ describe FacterDB do
16
16
  end
17
17
 
18
18
  let(:facts_24_path) { File.join(project_dir, 'facts', '2.4') }
19
- let(:facts_24_count) { Dir.glob(File.join(facts_24_path,'*.facts')).count }
19
+ let(:facts_24_count) { Dir.glob(File.join(facts_24_path, '*.facts')).count }
20
20
  let(:facts_23_path) { File.join(project_dir, 'facts', '2.3') }
21
- let(:facts_23_count) { Dir.glob(File.join(facts_23_path,'*.facts')).count }
21
+ let(:facts_23_count) { Dir.glob(File.join(facts_23_path, '*.facts')).count }
22
22
 
23
23
  describe '.use_defaultdb?' do
24
24
  subject { described_class.use_defaultdb? }
25
25
 
26
- before(:each) do
26
+ before do
27
27
  ENV.delete('FACTERDB_SKIP_DEFAULTDB')
28
28
  end
29
29
 
@@ -32,7 +32,7 @@ describe FacterDB do
32
32
  end
33
33
 
34
34
  context 'when FACTERDB_SKIP_DEFAULTDB environment variable is set' do
35
- before(:each) do
35
+ before do
36
36
  ENV['FACTERDB_SKIP_DEFAULTDB'] = '1'
37
37
  end
38
38
 
@@ -45,7 +45,7 @@ describe FacterDB do
45
45
 
46
46
  let(:non_directory_path) { File.join('this', 'is', 'not', 'a', 'directory') }
47
47
 
48
- before(:each) do
48
+ before do
49
49
  ENV.delete('FACTERDB_SEARCH_PATHS')
50
50
  allow(File).to receive(:directory?).and_call_original
51
51
  allow(File).to receive(:directory?).with(non_directory_path).and_return(false)
@@ -73,7 +73,7 @@ describe FacterDB do
73
73
 
74
74
  object = defined?(Warning) ? Warning : Kernel
75
75
  allow(object).to receive(:warn).and_call_original
76
- allow(object).to receive(:warn).with(a_string_matching(%r{is not a directory}))
76
+ allow(object).to receive(:warn).with(a_string_matching(/is not a directory/))
77
77
 
78
78
  expect(file_count).to eq(facts_24_count)
79
79
  end
@@ -105,7 +105,7 @@ describe FacterDB do
105
105
  it 'ignores the path that is not a directory' do
106
106
  object = defined?(Warning) ? Warning : Kernel
107
107
  allow(object).to receive(:warn).and_call_original
108
- allow(object).to receive(:warn).with(a_string_matching(%r{is not a directory}))
108
+ allow(object).to receive(:warn).with(a_string_matching(/is not a directory/))
109
109
 
110
110
  expect(file_count).to eq(facts_24_count)
111
111
  end
@@ -116,7 +116,7 @@ describe FacterDB do
116
116
  describe '.default_fact_files' do
117
117
  subject(:default_fact_files) { described_class.default_fact_files }
118
118
 
119
- before(:each) do
119
+ before do
120
120
  ENV.delete('FACTERDB_SKIP_DEFAULTDB')
121
121
  end
122
122
 
@@ -128,7 +128,7 @@ describe FacterDB do
128
128
  end
129
129
 
130
130
  context 'when FACTERDB_SKIP_DEFAULTDB environment variable is set' do
131
- before(:each) do
131
+ before do
132
132
  ENV['FACTERDB_SKIP_DEFAULTDB'] = '1'
133
133
  end
134
134
 
@@ -139,11 +139,11 @@ describe FacterDB do
139
139
  describe '.facterdb_fact_files' do
140
140
  subject(:facterdb_fact_files) { described_class.facterdb_fact_files }
141
141
 
142
- before(:each) do
142
+ before do
143
143
  ENV.delete('FACTERDB_SKIP_DEFAULTDB')
144
144
  end
145
145
 
146
- after(:each) do
146
+ after do
147
147
  ENV.delete('FACTERDB_SEARCH_PATHS')
148
148
  end
149
149
 
@@ -154,7 +154,7 @@ describe FacterDB do
154
154
  end
155
155
 
156
156
  context 'with no loaded fact sets' do
157
- before(:each) do
157
+ before do
158
158
  ENV['FACTERDB_SKIP_DEFAULTDB'] = '1'
159
159
  ENV.delete('FACTERDB_SEARCH_PATHS')
160
160
  end
@@ -166,7 +166,7 @@ describe FacterDB do
166
166
  describe '.database' do
167
167
  subject(:database) { described_class.database }
168
168
 
169
- before(:each) do
169
+ before do
170
170
  ENV.delete('FACTERDB_SKIP_DEFAULTDB')
171
171
  ENV.delete('FACTERDB_SEARCH_PATHS')
172
172
  FacterDB.instance_variable_set(:@database, nil)
@@ -183,7 +183,7 @@ describe FacterDB do
183
183
  context 'when FACTERDB_INJECT_SOURCE environment variable is set' do
184
184
  subject(:json_database) { JSON.parse(database) }
185
185
 
186
- before(:each) do
186
+ before do
187
187
  ENV['FACTERDB_INJECT_SOURCE'] = '1'
188
188
  end
189
189
 
@@ -200,14 +200,14 @@ describe FacterDB do
200
200
  describe '.get_os_facts' do
201
201
  subject(:result) { FacterDB.get_os_facts(facter_version, filter) }
202
202
 
203
- before(:each) do
203
+ before do
204
204
  object = defined?(Warning) ? Warning : Kernel
205
205
  allow(object).to receive(:warn).and_call_original
206
- allow(object).to receive(:warn).with(a_string_matching(%r{`get_os_facts` is deprecated}))
206
+ allow(object).to receive(:warn).with(a_string_matching(/`get_os_facts` is deprecated/))
207
207
  end
208
208
 
209
209
  context 'without parameters' do
210
- subject(:result) { FacterDB.get_os_facts() }
210
+ subject(:result) { FacterDB.get_os_facts }
211
211
 
212
212
  include_examples 'returns a result'
213
213
  end
@@ -216,13 +216,13 @@ describe FacterDB do
216
216
  let(:facter_version) { '*' }
217
217
 
218
218
  context 'with an Array filter' do
219
- let(:filter) { [{ :osfamily => 'Debian' }] }
219
+ let(:filter) { [{ osfamily: 'Debian' }] }
220
220
 
221
221
  include_examples 'returns a result'
222
222
  end
223
223
 
224
224
  context 'with a Hash filter' do
225
- let(:filter) { { :osfamily => 'Debian' } }
225
+ let(:filter) { { osfamily: 'Debian' } }
226
226
 
227
227
  include_examples 'returns a result'
228
228
  end
@@ -237,7 +237,7 @@ describe FacterDB do
237
237
  let(:filter) { true }
238
238
 
239
239
  it 'raises an error' do
240
- expect { result }.to raise_error(%r{filter must be either})
240
+ expect { result }.to raise_error(/filter must be either/)
241
241
  end
242
242
  end
243
243
  end
@@ -247,19 +247,19 @@ describe FacterDB do
247
247
 
248
248
  shared_examples 'returns only the specified version' do
249
249
  it 'only includes fact sets for the specified version' do
250
- expect(result).to all(include(:facterversion => match(%r{\A2\.4})))
250
+ expect(result).to all(include(facterversion: match(/\A2\.4/)))
251
251
  end
252
252
  end
253
253
 
254
254
  context 'with an Array filter' do
255
- let(:filter) { [{ :osfamily => 'Debian' }] }
255
+ let(:filter) { [{ osfamily: 'Debian' }] }
256
256
 
257
257
  include_examples 'returns a result'
258
258
  include_examples 'returns only the specified version'
259
259
  end
260
260
 
261
261
  context 'with a Hash filter' do
262
- let(:filter) { { :osfamily => 'Debian' } }
262
+ let(:filter) { { osfamily: 'Debian' } }
263
263
 
264
264
  include_examples 'returns a result'
265
265
  include_examples 'returns only the specified version'
@@ -276,7 +276,7 @@ describe FacterDB do
276
276
  let(:filter) { true }
277
277
 
278
278
  it 'raises an error' do
279
- expect { result }.to raise_error(%r{filter must be either})
279
+ expect { result }.to raise_error(/filter must be either/)
280
280
  end
281
281
  end
282
282
  end
@@ -284,29 +284,29 @@ describe FacterDB do
284
284
 
285
285
  describe '.valid_filters?' do
286
286
  it 'invalid and false' do
287
- expect( FacterDB.valid_filters?('and')).to be_falsey
287
+ expect(FacterDB.valid_filters?('and')).to be_falsey
288
288
  end
289
289
 
290
290
  it 'valid and true' do
291
- expect( FacterDB.valid_filters?('foo')).to be_truthy
291
+ expect(FacterDB.valid_filters?('foo')).to be_truthy
292
292
  end
293
293
  end
294
294
 
295
295
  describe '.generate_filter_str' do
296
296
  it 'invalid type' do
297
- expect{FacterDB.generate_filter_str(3)}.to raise_error(FacterDB::Errors::InvalidFilter)
297
+ expect { FacterDB.generate_filter_str(3) }.to raise_error(FacterDB::Errors::InvalidFilter)
298
298
  end
299
299
 
300
300
  it 'with string' do
301
- expect(FacterDB.generate_filter_str('foo')).to eq("foo")
301
+ expect(FacterDB.generate_filter_str('foo')).to eq('foo')
302
302
  end
303
303
 
304
304
  it 'with hash' do
305
- expect(FacterDB.generate_filter_str({:osfamily => 'Debian'})).to eq("osfamily=Debian")
305
+ expect(FacterDB.generate_filter_str({ osfamily: 'Debian' })).to eq('osfamily=Debian')
306
306
  end
307
307
 
308
308
  it 'with Array' do
309
- expect(FacterDB.generate_filter_str([:osfamily => 'Debian'])).to eq("(osfamily=Debian)")
309
+ expect(FacterDB.generate_filter_str([osfamily: 'Debian'])).to eq('(osfamily=Debian)')
310
310
  end
311
311
 
312
312
  it 'empty' do
@@ -324,32 +324,32 @@ describe FacterDB do
324
324
  let(:filter) { nil }
325
325
 
326
326
  context 'without parameters' do
327
- include_examples "returns a result"
327
+ include_examples 'returns a result'
328
328
  end
329
329
 
330
330
  context 'with an Array filter' do
331
- let(:filter) { [:osfamily => 'Debian'] }
331
+ let(:filter) { [osfamily: 'Debian'] }
332
332
 
333
- include_examples "returns a result"
333
+ include_examples 'returns a result'
334
334
  end
335
335
 
336
336
  context 'with a Hash filter' do
337
- let(:filter) { { :osfamily => 'Debian' } }
337
+ let(:filter) { { osfamily: 'Debian' } }
338
338
 
339
- include_examples "returns a result"
339
+ include_examples 'returns a result'
340
340
  end
341
341
 
342
342
  context 'with a String filter' do
343
343
  let(:filter) { 'osfamily=Debian' }
344
344
 
345
- include_examples "returns a result"
345
+ include_examples 'returns a result'
346
346
  end
347
347
 
348
348
  context 'with a filter of an unsupported type' do
349
349
  let(:filter) { true }
350
350
 
351
351
  it 'raises an error' do
352
- expect { result }.to raise_error(%r{filter must be either})
352
+ expect { result }.to raise_error(/filter must be either/)
353
353
  end
354
354
  end
355
355
  end