puppetdb_query 0.0.36 → 0.0.37

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: 6fe43dde7f253acd669b4482bc7cb1b952bd62c9
4
- data.tar.gz: 726bb2a347d54ceb2b21510044385d7b70d6b7aa
3
+ metadata.gz: 2c321779c7c9b60e57efba9fda1a71e122770a77
4
+ data.tar.gz: 4740cdf7ac990def716168c2a4aad7bdef4bf30f
5
5
  SHA512:
6
- metadata.gz: e0382ae312d52f98fdd34e2ac6aa734b5db99c3ff2cd03ee369eeee7ab384f809ff055b104339fbdf9cd8cb5f485ee192ccdec6e76bb29e6a64bfda9e9ef1c92
7
- data.tar.gz: 140778b75a73b53bdd0725e3378539e936f12c3ca8aa53c0e255308e86de4e26361d9586529d4fe9779072f6648adfdcebfd9bc3fd8aa212f8d07807ebb3b2e8
6
+ metadata.gz: 8f25e946d438bedd94d26afcc27c11428fbffdf156d3279c6a914370b5378c6aee44af90fe15c1d428879cc808bd9ac541bad1aa4e5349e32d12382c1c02b7e5
7
+ data.tar.gz: ce06b58cb677afd03c073f49317325bdecc8352f7f47e07025f6d2e8fef4c376ab97d391cfe6a2e75da6f2a08b159fc6c374ef48300830894e4e8ebee5a38497
@@ -2,6 +2,18 @@ require 'time'
2
2
 
3
3
  require_relative "logging"
4
4
 
5
+ # monkey patch mongodb to get rid of
6
+ # ".. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'. (BSON::String::IllegalKey)"
7
+ module Mongo
8
+ module Protocol
9
+ class Message
10
+ def validating_keys?
11
+ false
12
+ end
13
+ end
14
+ end
15
+ end
16
+
5
17
  module PuppetDBQuery
6
18
  # access nodes and their facts from mongo database
7
19
  # rubocop:disable Metrics/ClassLength
@@ -151,17 +163,27 @@ module PuppetDBQuery
151
163
  # update or insert facts for given node name
152
164
  #
153
165
  # @param node [String] node name
154
- # @param facts [Array<String>] get these facts in the result, eg ['fqdn'], empty for all
166
+ # @param facts [Hash] facts for the node
155
167
  def node_update(node, facts)
156
- connection[nodes_collection].find(_id: node).replace_one(facts, upsert: true)
168
+ logger.debug " updating #{node}"
169
+ connection[nodes_collection].find(_id: node).replace_one(facts, upsert: true,
170
+ bypass_document_validation: true, check_keys: false, validating_keys: false)
157
171
  rescue ::Mongo::Error::OperationFailure => e
172
+ logger.warn " updating #{node} failed with: #{e.message}"
158
173
  # mongodb doesn't support keys with a dot
159
174
  # see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
160
175
  # as a dirty workaround we delete the document and insert it ;-)
161
176
  # The dotted field .. in .. is not valid for storage. (57)
162
- raise e unless e.message =~ /The dotted field /
163
- connection[nodes_collection].find(_id: node).delete_one
164
- connection[nodes_collection].insert_one(facts.merge(_id: node))
177
+ # .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'. (BSON::String::IllegalKey)
178
+ raise e unless (e.message =~ /The dotted field / || e.message =~ /is an illegal key/)
179
+ logger.warn " we try again deleting and inserting the node"
180
+ begin
181
+ connection[nodes_collection].find(_id: node).delete_one
182
+ connection[nodes_collection].insert_one(facts.merge(_id: node),
183
+ bypass_document_validation: true, check_keys: false, validating_keys: false)
184
+ rescue
185
+ logger.error " updating #{node} failed with: #{e.message}"
186
+ end
165
187
  end
166
188
 
167
189
  # delete node data for given node name
@@ -32,7 +32,7 @@ module PuppetDBQuery
32
32
  updater.update3(timestamp - seconds_back)
33
33
  timestamp = ts
34
34
  rescue Timeout::Error
35
- logger.info "syncing puppetdb nodes: now our time is up, we finsh"
35
+ logger.info "syncing puppetdb nodes: now our time is up, we finish"
36
36
  return
37
37
  rescue
38
38
  logger.error $!
@@ -1,3 +1,3 @@
1
1
  module PuppetDBQuery
2
- VERSION = "0.0.36".freeze
2
+ VERSION = "0.0.37".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.36
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Meyling