puppetdb_query 0.0.22 → 0.0.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a4a3d95bddb1796eb47d71e3850df41b120216
4
- data.tar.gz: 3fd110d298eafbff4f0e3b049e743024edfa157e
3
+ metadata.gz: 359b66cb570cf21f12b481392c3beaa7bc6534bb
4
+ data.tar.gz: bcba75c34ffe214aabe450326ed109bdeb9be67b
5
5
  SHA512:
6
- metadata.gz: afe4adf94c08743c2a6ed1cf232eecb973dc125db1ca3f15b177358c59e20132ed1977c290559b4c28daca62f134dbcbeee29c27f4ff59c00f6224b334725288
7
- data.tar.gz: 5fd63cc622d7261ecd9e2a44db76c95ed51528f586d67737b0b278ea30a70428933f6f07a17933f22d610d43091b25164e8af6a7c9f0b98d0c92e28934285275
6
+ metadata.gz: 6d99268035b8adc41e7f8a35c71f2e8b4ae7af39a67fd2a960a52b3176509b1584951baed3e00b4b81609729f12ecd78eb246b5844fa25ca03c18b4bf28aface
7
+ data.tar.gz: edb8aa5afb543003c3a78dd1c6f40e07464c5c1c810cce159e43cb674fbf48398339684b15d1641b68d340ceca4d739dfbde3f420424e77f6a6240d48767835c
@@ -4,6 +4,7 @@ require_relative "logging"
4
4
 
5
5
  module PuppetDBQuery
6
6
  # access nodes and their facts from mongo database
7
+ # rubocop:disable Metrics/ClassLength
7
8
  class MongoDB
8
9
  include Logging
9
10
  attr_reader :connection
@@ -47,7 +48,12 @@ module PuppetDBQuery
47
48
  end
48
49
 
49
50
  # get nodes and their facts for a pattern
50
- def search_facts(query, pattern, facts, check_names = false)
51
+ # @param query mongodb query
52
+ # @param pattern RegExp to search for
53
+ # @param facts Array get these values in the result, eg ['fqdn']
54
+ # @param facts_found Array fact names are added to this array
55
+ # @param check_names Boolean also search fact names
56
+ def search_facts(query, pattern, facts = [], facts_found = [], check_names = false)
51
57
  collection = connection[nodes_collection]
52
58
  result = {}
53
59
  collection.find(query).batch_size(999).each do |values|
@@ -60,8 +66,12 @@ module PuppetDBQuery
60
66
  found[k] = v
61
67
  end
62
68
  end
63
- facts.concat(found.keys).uniq!
64
- result[id] = found unless found.empty?
69
+ facts_found.concat(found.keys).uniq!
70
+ next if found.empty?
71
+ facts.each do |f|
72
+ found = values[f]
73
+ end
74
+ result[id] = found
65
75
  end
66
76
  result
67
77
  end
@@ -185,4 +195,5 @@ module PuppetDBQuery
185
195
  @node_properties_update_timestamp = ts_begin
186
196
  end
187
197
  end
198
+ # rubocop:enable Metrics/ClassLength
188
199
  end
@@ -1,3 +1,3 @@
1
1
  module PuppetDBQuery
2
- VERSION = "0.0.22".freeze
2
+ VERSION = "0.0.23".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Meyling