facterdb 1.4.0 → 1.8.0

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/.github/workflows/release.yml +32 -0
  3. data/.github/workflows/test.yml +28 -0
  4. data/CHANGELOG.md +172 -118
  5. data/Gemfile +2 -2
  6. data/README.md +110 -100
  7. data/Rakefile +9 -3
  8. data/facterdb.gemspec +7 -8
  9. data/facts/1.7/centos-9-x86_64.facts +82 -0
  10. data/facts/2.0/centos-9-x86_64.facts +82 -0
  11. data/facts/2.1/centos-9-x86_64.facts +112 -0
  12. data/facts/2.2/centos-9-x86_64.facts +137 -0
  13. data/facts/2.3/centos-9-x86_64.facts +138 -0
  14. data/facts/2.4/centos-9-x86_64.facts +139 -0
  15. data/facts/3.11/archlinux-x86_64.facts +11 -1
  16. data/facts/3.11/solaris-10-i86pc.facts +1 -4
  17. data/facts/3.11/solaris-11-i86pc.facts +1 -4
  18. data/facts/3.11/solaris-11-sun4v.facts +1 -4
  19. data/facts/3.14/almalinux-8-x86_64.facts +522 -0
  20. data/facts/3.14/archlinux-x86_64.facts +11 -1
  21. data/facts/3.14/darwin-19-x86_64.facts +412 -0
  22. data/facts/3.14/darwin-20-x86_64.facts +516 -0
  23. data/facts/3.14/solaris-11-i86pc.facts +1 -4
  24. data/facts/3.14/solaris-11-sun4v.facts +1 -4
  25. data/facts/3.9/solaris-10-i86pc.facts +0 -3
  26. data/facts/4.0/almalinux-8-x86_64.facts +307 -0
  27. data/facts/4.0/centos-7-x86_64.facts +706 -0
  28. data/facts/4.0/debian-10-x86_64.facts +1091 -0
  29. data/facts/4.0/solaris-11-sun4v.facts +585 -0
  30. data/facts/4.2/centos-9-x86_64.facts +291 -0
  31. data/facts/4.2/darwin-20-x86_64.facts +524 -0
  32. data/facts/Vagrantfile +8 -1
  33. data/facts/get_facts.sh +14 -0
  34. data/lib/facterdb.rb +47 -11
  35. data/lib/facterdb/version.rb +1 -1
  36. data/spec/facterdb_spec.rb +36 -0
  37. data/spec/facts_spec.rb +9 -2
  38. metadata +25 -30
  39. data/.travis.yml +0 -28
data/facts/Vagrantfile CHANGED
@@ -150,7 +150,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
150
150
  host.vm.provision "shell", path: "get_facts.sh"
151
151
  host.vm.provision "shell", inline: "/sbin/shutdown -h now"
152
152
  end
153
-
153
+ config.vm.define "almalinux-8-x86_64" do |host|
154
+ host.vm.box = "almalinux/8"
155
+ host.vm.synced_folder ".", "/vagrant"
156
+ host.vm.provision "shell", inline: "dnf -y install wget make gcc net-tools"
157
+ host.vm.provision "file", source: "Gemfile", destination: "Gemfile"
158
+ host.vm.provision "shell", path: "get_facts.sh"
159
+ host.vm.provision "shell", inline: "/sbin/shutdown -h now"
160
+ end
154
161
  config.vm.define "redhat-8-x86_64" do |host|
155
162
  host.vm.box = "generic/rhel8"
156
163
  host.vm.synced_folder ".", "/vagrant"
data/facts/get_facts.sh CHANGED
@@ -37,6 +37,9 @@ elif test -f /etc/redhat-release ; then
37
37
  fedora*)
38
38
  osfamily='Fedora'
39
39
  ;;
40
+ almalinux*)
41
+ osfamily='AlmaLinux'
42
+ ;;
40
43
  *)
41
44
  echo 'Failed to determine osfamily from /etc/redhat-release'
42
45
  exit 1
@@ -150,6 +153,14 @@ case "${osfamily}" in
150
153
  yum remove -y puppet6-release
151
154
  fi
152
155
  ;;
156
+ 'AlmaLinux')
157
+ dnf localinstall -y "http://yum.puppetlabs.com/puppet6-release-el-${operatingsystemmajrelease}.noarch.rpm"
158
+ if dnf install -y puppet-agent; then
159
+ output_file="/vagrant/$(facter --version | cut -d. -f1,2)/$(facter operatingsystem | tr '[:upper:]' '[:lower:]')-$(facter operatingsystemmajrelease)-$(facter hardwaremodel).facts"
160
+ mkdir -p $(dirname ${output_file})
161
+ facter --show-legacy -p -j | tee ${output_file}
162
+ fi
163
+ ;;
153
164
 
154
165
  'Debian')
155
166
  if [[ "serena" =~ ${lsbdistcodename} ]]; then
@@ -300,6 +311,9 @@ bundle install --path vendor/bundler
300
311
  for version in 1.6.0 1.7.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0; do
301
312
  FACTER_GEM_VERSION="~> ${version}" bundle update
302
313
  case "${operatingsystem}" in
314
+ almalinux)
315
+ break
316
+ ;;
303
317
  openbsd)
304
318
  output_file="/vagrant/$(bundle exec facter --version | cut -d. -f1,2)/${operatingsystem}-${operatingsystemrelease}-${hardwaremodel}.facts"
305
319
  ;;
data/lib/facterdb.rb CHANGED
@@ -2,12 +2,22 @@ require 'facter'
2
2
  require 'jgrep'
3
3
 
4
4
  module FacterDB
5
+ module Errors
6
+ class InvalidFilter < RuntimeError; end
7
+ end
5
8
 
6
9
  # @return [String] - returns a giant incomprehensible string of concatenated json data
7
10
  def self.database
8
11
  @database ||= "[#{facterdb_fact_files.map { |f| read_json_file(f) }.join(',')}]\n"
9
12
  end
10
13
 
14
+ # @note Call this method at the end of test suite, for example via after(:suite), to reclaim back the memory required to hold json data and filter cache
15
+ def self.cleanup
16
+ @database = nil
17
+ Thread.current[:facterdb_last_filter_seen] = nil
18
+ Thread.current[:facterdb_last_facts_seen] = nil
19
+ end
20
+
11
21
  # @return [Boolean] - returns true if we should use the default facterdb database, false otherwise
12
22
  # @note If the user passes anything to the FACTERDB_SKIP_DEFAULTDB environment variable we assume
13
23
  # they want to skip the default db
@@ -92,18 +102,44 @@ module FacterDB
92
102
  get_facts(filter_str)
93
103
  end
94
104
 
95
- def self.get_facts(filter=nil)
96
- if filter.is_a?(Array)
97
- filter_str = '(' + filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
98
- elsif filter.is_a?(Hash)
99
- filter_str = filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
100
- elsif filter.is_a?(String)
101
- filter_str = filter
102
- elsif filter == nil
103
- filter_str = ''
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)
108
+ case filter
109
+ when ::Array
110
+ '(' + filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(') or (') + ')'
111
+ when ::Hash
112
+ filter.map { |k,v | "#{k}=#{v}" }.join(' and ')
113
+ when ::String
114
+ filter
115
+ when ::NilClass
116
+ ''
104
117
  else
105
- raise 'filter must be either an Array a Hash or a String'
118
+ raise Errors::InvalidFilter, "filter must be either an Array a Hash, String, or nil, received #{filter.class}"
119
+ end
120
+ end
121
+
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
124
+ def self.valid_filters?(filters)
125
+ filter_str = generate_filter_str(filters)
126
+ JGrep.validate_filters(filter_str).nil?
127
+ rescue RuntimeError
128
+ false
129
+ end
130
+
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)
134
+ if cache && filter && filter == Thread.current[:facterdb_last_filter_seen]
135
+ return Thread.current[:facterdb_last_facts_seen]
136
+ end
137
+ filter_str = generate_filter_str(filter)
138
+ result = JGrep.jgrep(database, filter_str).map { |hash| Hash[hash.map{ |k, v| [k.to_sym, v] }] }
139
+ if cache
140
+ Thread.current[:facterdb_last_filter_seen] = filter
141
+ Thread.current[:facterdb_last_facts_seen] = result
106
142
  end
107
- JGrep.jgrep(database, filter_str).map { |hash| Hash[hash.map{ |k, v| [k.to_sym, v] }] }
143
+ result
108
144
  end
109
145
  end
@@ -1,5 +1,5 @@
1
1
  module FacterDB
2
2
  module Version
3
- STRING = '1.4.0'
3
+ STRING = '1.8.0'
4
4
  end
5
5
  end
@@ -282,6 +282,42 @@ describe FacterDB do
282
282
  end
283
283
  end
284
284
 
285
+ describe '.valid_filters?' do
286
+ it 'invalid and false' do
287
+ expect( FacterDB.valid_filters?('and')).to be_falsey
288
+ end
289
+
290
+ it 'valid and true' do
291
+ expect( FacterDB.valid_filters?('foo')).to be_truthy
292
+ end
293
+ end
294
+
295
+ describe '.generate_filter_str' do
296
+ it 'invalid type' do
297
+ expect{FacterDB.generate_filter_str(3)}.to raise_error(FacterDB::Errors::InvalidFilter)
298
+ end
299
+
300
+ it 'with string' do
301
+ expect(FacterDB.generate_filter_str('foo')).to eq("foo")
302
+ end
303
+
304
+ it 'with hash' do
305
+ expect(FacterDB.generate_filter_str({:osfamily => 'Debian'})).to eq("osfamily=Debian")
306
+ end
307
+
308
+ it 'with Array' do
309
+ expect(FacterDB.generate_filter_str([:osfamily => 'Debian'])).to eq("(osfamily=Debian)")
310
+ end
311
+
312
+ it 'empty' do
313
+ expect(FacterDB.generate_filter_str('')).to eq('')
314
+ end
315
+
316
+ it 'nil filter' do
317
+ expect(FacterDB.generate_filter_str(nil)).to eq('')
318
+ end
319
+ end
320
+
285
321
  describe '.get_facts' do
286
322
  subject(:result) { FacterDB.get_facts(filter) }
287
323
 
data/spec/facts_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'digest'
3
+ require 'pathname'
3
4
 
4
5
  RSpec::Matchers.define :have_a_unique_hash do
5
6
  match do |actual|
@@ -99,9 +100,15 @@ describe 'Default Facts' do
99
100
  expect(content['facterversion']).to have_facter_version(facter_dir_path, filepath)
100
101
  end
101
102
 
102
- it 'contains an ipaddress fact' do
103
+ it 'contains an ipaddress or networking.ip fact' do
103
104
  pending KNOWN_IPADDRESS_PENDING[relative_path] if KNOWN_IPADDRESS_PENDING.key?(relative_path)
104
- expect(content['ipaddress']).to not_be_nil.and not_be_empty
105
+ case content['facterversion']
106
+ when /^[1-3]/
107
+ expect(content['ipaddress']).to not_be_nil.and not_be_empty
108
+ else
109
+ expect(content['networking']['ip']).to not_be_nil.and not_be_empty
110
+ end
111
+
105
112
  end
106
113
  end
107
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facterdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
- - Mickaël Canévet
7
+ - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-09 00:00:00.000000000 Z
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -66,40 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: github_changelog_generator
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.10'
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: 1.10.4
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '1.10'
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: 1.10.4
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: facter
91
71
  requirement: !ruby/object:Gem::Requirement
92
72
  requirements:
93
73
  - - "<"
94
74
  - !ruby/object:Gem::Version
95
- version: 4.0.0
75
+ version: 5.0.0
96
76
  type: :runtime
97
77
  prerelease: false
98
78
  version_requirements: !ruby/object:Gem::Requirement
99
79
  requirements:
100
80
  - - "<"
101
81
  - !ruby/object:Gem::Version
102
- version: 4.0.0
82
+ version: 5.0.0
103
83
  - !ruby/object:Gem::Dependency
104
84
  name: jgrep
105
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,15 +96,16 @@ dependencies:
116
96
  version: '0'
117
97
  description: Contains facts from many Facter version on many Operating Systems
118
98
  email:
119
- - mickael.canevet@camptocamp.com
99
+ - voxpupuli@groups.io
120
100
  executables:
121
101
  - facterdb
122
102
  extensions: []
123
103
  extra_rdoc_files: []
124
104
  files:
105
+ - ".github/workflows/release.yml"
106
+ - ".github/workflows/test.yml"
125
107
  - ".gitignore"
126
108
  - ".gitmodules"
127
- - ".travis.yml"
128
109
  - CHANGELOG.md
129
110
  - Gemfile
130
111
  - HISTORY.md
@@ -238,6 +219,7 @@ files:
238
219
  - facts/1.7/centos-7-i386.facts
239
220
  - facts/1.7/centos-7-x86_64.facts
240
221
  - facts/1.7/centos-8-x86_64.facts
222
+ - facts/1.7/centos-9-x86_64.facts
241
223
  - facts/1.7/debian-10-x86_64.facts
242
224
  - facts/1.7/debian-6-i386.facts
243
225
  - facts/1.7/debian-6-x86_64.facts
@@ -332,6 +314,7 @@ files:
332
314
  - facts/2.0/centos-7-i386.facts
333
315
  - facts/2.0/centos-7-x86_64.facts
334
316
  - facts/2.0/centos-8-x86_64.facts
317
+ - facts/2.0/centos-9-x86_64.facts
335
318
  - facts/2.0/darwin-14-i386.facts
336
319
  - facts/2.0/darwin-14-x86_64.facts
337
320
  - facts/2.0/darwin-15-x86_64.facts
@@ -442,6 +425,7 @@ files:
442
425
  - facts/2.1/centos-7-i386.facts
443
426
  - facts/2.1/centos-7-x86_64.facts
444
427
  - facts/2.1/centos-8-x86_64.facts
428
+ - facts/2.1/centos-9-x86_64.facts
445
429
  - facts/2.1/darwin-14-i386.facts
446
430
  - facts/2.1/darwin-14-x86_64.facts
447
431
  - facts/2.1/darwin-15-x86_64.facts
@@ -562,6 +546,7 @@ files:
562
546
  - facts/2.2/centos-7-i386.facts
563
547
  - facts/2.2/centos-7-x86_64.facts
564
548
  - facts/2.2/centos-8-x86_64.facts
549
+ - facts/2.2/centos-9-x86_64.facts
565
550
  - facts/2.2/darwin-14-i386.facts
566
551
  - facts/2.2/darwin-14-x86_64.facts
567
552
  - facts/2.2/darwin-15-x86_64.facts
@@ -682,6 +667,7 @@ files:
682
667
  - facts/2.3/centos-7-i386.facts
683
668
  - facts/2.3/centos-7-x86_64.facts
684
669
  - facts/2.3/centos-8-x86_64.facts
670
+ - facts/2.3/centos-9-x86_64.facts
685
671
  - facts/2.3/darwin-14-i386.facts
686
672
  - facts/2.3/darwin-14-x86_64.facts
687
673
  - facts/2.3/darwin-15-x86_64.facts
@@ -803,6 +789,7 @@ files:
803
789
  - facts/2.4/centos-7-i386.facts
804
790
  - facts/2.4/centos-7-x86_64.facts
805
791
  - facts/2.4/centos-8-x86_64.facts
792
+ - facts/2.4/centos-9-x86_64.facts
806
793
  - facts/2.4/darwin-14-i386.facts
807
794
  - facts/2.4/darwin-14-x86_64.facts
808
795
  - facts/2.4/darwin-15-x86_64.facts
@@ -1292,6 +1279,7 @@ files:
1292
1279
  - facts/3.13/windows-2016-x86_64.facts
1293
1280
  - facts/3.13/windows-2019-x86_64.facts
1294
1281
  - facts/3.14/VirtuozzoLinux-7-x86_64.facts
1282
+ - facts/3.14/almalinux-8-x86_64.facts
1295
1283
  - facts/3.14/amazon-2-x86_64.facts
1296
1284
  - facts/3.14/amazon-2016-x86_64.facts
1297
1285
  - facts/3.14/archlinux-x86_64.facts
@@ -1301,6 +1289,8 @@ files:
1301
1289
  - facts/3.14/darwin-16-x86_64.facts
1302
1290
  - facts/3.14/darwin-17-x86_64.facts
1303
1291
  - facts/3.14/darwin-18-x86_64.facts
1292
+ - facts/3.14/darwin-19-x86_64.facts
1293
+ - facts/3.14/darwin-20-x86_64.facts
1304
1294
  - facts/3.14/debian-10-x86_64.facts
1305
1295
  - facts/3.14/debian-8-x86_64.facts
1306
1296
  - facts/3.14/debian-9-x86_64.facts
@@ -1710,6 +1700,12 @@ files:
1710
1700
  - facts/3.9/windows-2012-x86_64.facts
1711
1701
  - facts/3.9/windows-2016-x86_64.facts
1712
1702
  - facts/3.9/windows-2019-x86_64.facts
1703
+ - facts/4.0/almalinux-8-x86_64.facts
1704
+ - facts/4.0/centos-7-x86_64.facts
1705
+ - facts/4.0/debian-10-x86_64.facts
1706
+ - facts/4.0/solaris-11-sun4v.facts
1707
+ - facts/4.2/centos-9-x86_64.facts
1708
+ - facts/4.2/darwin-20-x86_64.facts
1713
1709
  - facts/Gemfile
1714
1710
  - facts/Vagrantfile
1715
1711
  - facts/Windows_README.md
@@ -1738,7 +1734,7 @@ files:
1738
1734
  - spec/facterdb_spec.rb
1739
1735
  - spec/facts_spec.rb
1740
1736
  - spec/spec_helper.rb
1741
- homepage: http://github.com/camptocamp/facterdb
1737
+ homepage: http://github.com/voxpupuli/facterdb
1742
1738
  licenses:
1743
1739
  - Apache-2.0
1744
1740
  metadata: {}
@@ -1757,8 +1753,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1757
1753
  - !ruby/object:Gem::Version
1758
1754
  version: '0'
1759
1755
  requirements: []
1760
- rubyforge_project:
1761
- rubygems_version: 2.7.7
1756
+ rubygems_version: 3.2.22
1762
1757
  signing_key:
1763
1758
  specification_version: 4
1764
1759
  summary: A Database of OS facts provided by Facter
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
- script:
5
- - bundle exec rake spec
6
- rvm:
7
- - 2.3
8
- env:
9
- - FACTER_GEM_VERSION="~> 1.6.0"
10
- - FACTER_GEM_VERSION="~> 1.7.0"
11
- - FACTER_GEM_VERSION="~> 2.0.0"
12
- - FACTER_GEM_VERSION="~> 2.1.0"
13
- - FACTER_GEM_VERSION="~> 2.2.0"
14
- - FACTER_GEM_VERSION="~> 2.3.0"
15
- - FACTER_GEM_VERSION="~> 2.4.0"
16
- - FACTER_GEM_VERSION="~> 2.0" COVERAGE=yes
17
- matrix:
18
- fast_finish: true
19
- notifications:
20
- email: false
21
- deploy:
22
- provider: rubygems
23
- api_key:
24
- secure: Ja5JTWVsXcpYKVBrM35h9jLBoEuSm2f28A7UBk/culOC45dXzlS1BQfcxuVuNeRZ1/pPHHOnCM11yfliqJ2eF6FsNTqaLiFnNDAP/qPI2an9T1FO9dnBQ/EJp3jMp6DcXvb7CbYMS9n61CM+W0RzAdGpRK6AGLFAN5Ttba1SEIGPtlBV6e0MOu7Ma9DI7tFboqi3quSTPhvXUHpyYXDicQ+2/eijAWde/Tll3wJB8ir9lqmNh/xV9qHKdjZsAK8PG6PiuuaVsBUiQMFnapZD2OZmgLJFrOLnTvvntdcsQecsvlykHZXgbqta372KxDRIsJ2ld9a2GiL/wZDvZ9SWC+r5RAKxkvtKyQPezecO9yjJxaYAryY06YA92WibmZPBuODI4iz0MkueiulXjT4W5e/04Dj+oHtNTSGOucM5J8a08NN0UNW0IpJL/VDIw7viyXc2DzwrPJGzn/jfjzvjX7ITNKS2DIPNps/thmiGu88+Snx/5O3Cmg15OgrIlSQfkJmnLedR+qQHoE5Xk4laIJ/+4L3o9X5lFwzQYneY4u/xedKrZl66idlMGqxkbmzyf4gjKzq7pZPnFePavJwrJlCU7HXangYcOotBo4Lb2lwpeL2ilgrgLn1p7bfLdTlQcNCH4WyRAyOlVtN4vNPVc7+a3n+BL0gz7Y1B7NQUukQ=
25
- gem: facterdb
26
- on:
27
- tags: true
28
- repo: camptocamp/facterdb