puppetdb_query 0.0.39 → 0.0.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppetdb_query/mongodb.rb +18 -9
- data/lib/puppetdb_query/parser.rb +23 -15
- data/lib/puppetdb_query/to_mongo.rb +12 -2
- data/lib/puppetdb_query/version.rb +1 -1
- data/spec/puppetdb_query/to_mongo_spec.rb +5 -0
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5501279b16f9e4c1efe66c8f374393e97fb07036
|
4
|
+
data.tar.gz: ccb1b607446816621b544c6d1cf6885b83bae5f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 719fcc36e5f63e61dfe9bd3f59fcfee3ad2944aba56e869bac8575d7c59cd1f990e3630df87ede8f7c5ba6f8ed6f516f9fa5fce28edc9878ba32784ebda0752d
|
7
|
+
data.tar.gz: 599e13100028af3edab9d2b908205e7b7698061bd4fa32e3e7751eb253e81569276e18a2554003935e78b33c3234af011bff27190b98f77deb10a6ef456f9676
|
@@ -3,9 +3,11 @@ require 'time'
|
|
3
3
|
require_relative "logging"
|
4
4
|
|
5
5
|
# monkey patch mongodb to get rid of
|
6
|
-
# ".. is an illegal key in MongoDB.
|
6
|
+
# ".. is an illegal key in MongoDB.
|
7
|
+
# Keys may not start with '$' or contain a '.'. (BSON::String::IllegalKey)"
|
7
8
|
module Mongo
|
8
9
|
module Protocol
|
10
|
+
# fool the monkey
|
9
11
|
class Message
|
10
12
|
def validating_keys?
|
11
13
|
false
|
@@ -166,21 +168,28 @@ module PuppetDBQuery
|
|
166
168
|
# @param facts [Hash] facts for the node
|
167
169
|
def node_update(node, facts)
|
168
170
|
logger.debug " updating #{node}"
|
169
|
-
connection[nodes_collection].find(_id: node).replace_one(facts,
|
170
|
-
|
171
|
+
connection[nodes_collection].find(_id: node).replace_one(facts,
|
172
|
+
upsert: true,
|
173
|
+
bypass_document_validation: true,
|
174
|
+
check_keys: false,
|
175
|
+
validating_keys: false)
|
171
176
|
rescue ::Mongo::Error::OperationFailure => e
|
172
177
|
logger.warn " updating #{node} failed with: #{e.message}"
|
173
178
|
# mongodb doesn't support keys with a dot
|
174
179
|
# see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
|
175
180
|
# as a dirty workaround we delete the document and insert it ;-)
|
176
181
|
# The dotted field .. in .. is not valid for storage. (57)
|
177
|
-
# .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.
|
178
|
-
|
179
|
-
|
182
|
+
# .. is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.
|
183
|
+
# (BSON::String::IllegalKey)
|
184
|
+
raise e unless e.message =~ /The dotted field / || e.message =~ /is an illegal key/
|
185
|
+
logger.warn " we transform the dots into underline characters"
|
180
186
|
begin
|
181
|
-
|
182
|
-
connection[nodes_collection].
|
183
|
-
|
187
|
+
facts = Hash[facts.map { |k, v| [k.tr('.', '_'), v] }]
|
188
|
+
connection[nodes_collection].find(_id: node).replace_one(facts,
|
189
|
+
upsert: true,
|
190
|
+
bypass_document_validation: true,
|
191
|
+
check_keys: false,
|
192
|
+
validating_keys: false)
|
184
193
|
rescue
|
185
194
|
logger.error " inserting node #{node} failed again with: #{e.message}"
|
186
195
|
end
|
@@ -15,25 +15,33 @@ module PuppetDBQuery
|
|
15
15
|
|
16
16
|
# these are the operators we understand
|
17
17
|
# rubocop:disable Style/ExtraSpacing
|
18
|
-
AND
|
19
|
-
OR
|
20
|
-
NOT
|
21
|
-
EQUAL
|
22
|
-
NOT_EQUAL
|
23
|
-
|
24
|
-
|
18
|
+
AND = Operator.new(:_and, true, 100, 2)
|
19
|
+
OR = Operator.new(:_or, true, 90, 2)
|
20
|
+
NOT = Operator.new(:_not, false, 150, 1, 1)
|
21
|
+
EQUAL = Operator.new(:_equal, true, 200, 2, 2)
|
22
|
+
NOT_EQUAL = Operator.new(:_not_equal, true, 200, 2, 2)
|
23
|
+
LESS = Operator.new(:_less, true, 190, 2, 2)
|
24
|
+
LESS_OR_EQUAL = Operator.new(:_less_or_equal, true, 190, 2, 2)
|
25
|
+
GREATER = Operator.new(:_greater, true, 190, 2, 2)
|
26
|
+
GREATER_OR_EQUAL = Operator.new(:_greater_or_equal, true, 190, 2, 2)
|
27
|
+
MATCH = Operator.new(:_match, true, 200, 2, 2)
|
28
|
+
IN = Operator.new(:_in, true, 200, 2, 2)
|
25
29
|
# rubocop:enable Style/ExtraSpacing
|
26
30
|
|
27
31
|
# map certain symbols (we get them from a tokenizer) to our operators
|
28
32
|
OPERATORS = {
|
29
|
-
AND.symbol
|
30
|
-
OR.symbol
|
31
|
-
NOT.symbol
|
32
|
-
EQUAL.symbol
|
33
|
-
:_is
|
34
|
-
NOT_EQUAL.symbol
|
35
|
-
MATCH.symbol
|
36
|
-
IN.symbol
|
33
|
+
AND.symbol => AND,
|
34
|
+
OR.symbol => OR,
|
35
|
+
NOT.symbol => NOT,
|
36
|
+
EQUAL.symbol => EQUAL,
|
37
|
+
:_is => EQUAL,
|
38
|
+
NOT_EQUAL.symbol => NOT_EQUAL,
|
39
|
+
MATCH.symbol => MATCH,
|
40
|
+
IN.symbol => IN,
|
41
|
+
LESS.symbol => LESS,
|
42
|
+
LESS_OR_EQUAL.symbol => LESS_OR_EQUAL,
|
43
|
+
GREATER.symbol => GREATER,
|
44
|
+
GREATER_OR_EQUAL.symbol => GREATER_OR_EQUAL,
|
37
45
|
}.freeze
|
38
46
|
|
39
47
|
attr_reader :symbols # array of symbols
|
@@ -22,14 +22,15 @@ module PuppetDBQuery
|
|
22
22
|
private
|
23
23
|
|
24
24
|
# rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/AbcSize
|
25
|
+
# rubocop:disable Metrics/MethodLength
|
25
26
|
def query_term(term)
|
26
27
|
# rubocop:disable Style/GuardClause
|
27
28
|
if term.is_a?(Symbol)
|
28
29
|
return term.to_s
|
29
30
|
elsif term.is_a?(Integer)
|
30
|
-
return
|
31
|
+
return term
|
31
32
|
elsif term.is_a?(TrueClass)
|
32
|
-
return term
|
33
|
+
return term
|
33
34
|
elsif !term.is_a?(Term)
|
34
35
|
return "'#{term}'"
|
35
36
|
end
|
@@ -54,10 +55,19 @@ module PuppetDBQuery
|
|
54
55
|
{ term.args[0] => { :$regex => term.args[1].to_s } }
|
55
56
|
when :_in
|
56
57
|
{ term.args[0] => { :$in => term.args[1] } }
|
58
|
+
when :_greater
|
59
|
+
{ term.args[0] => { :$gt => term.args[1] } }
|
60
|
+
when :_greater_or_equal
|
61
|
+
{ term.args[0] => { :$gte => term.args[1] } }
|
62
|
+
when :_less
|
63
|
+
{ term.args[0] => { :$lt => term.args[1] } }
|
64
|
+
when :_less_or_equal
|
65
|
+
{ term.args[0] => { :$lte => term.args[1] } }
|
57
66
|
else
|
58
67
|
raise "can't handle operator '#{term.operator}' yet"
|
59
68
|
end
|
60
69
|
end
|
61
70
|
# rubocop:enable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/AbcSize
|
71
|
+
# rubocop:enable Metrics/MethodLength
|
62
72
|
end
|
63
73
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetdb_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.41
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Meyling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: easy_diff
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Allow puppetdb access from resources like mongodb.
|
@@ -45,9 +45,9 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
48
|
+
- .gitignore
|
49
|
+
- .rubocop.yml
|
50
|
+
- .travis.yml
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
@@ -75,24 +75,24 @@ homepage: https://github.com/m-31/puppetdb_query
|
|
75
75
|
licenses:
|
76
76
|
- MIT
|
77
77
|
metadata: {}
|
78
|
-
post_install_message:
|
79
|
-
by itself.
|
78
|
+
post_install_message: ' Sitting quietly, doing nothing, spring comes, and grass grows
|
79
|
+
by itself.'
|
80
80
|
rdoc_options: []
|
81
81
|
require_paths:
|
82
82
|
- lib
|
83
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - '>='
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: 1.9.3
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - '>='
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.8
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: access puppetdb data from other sources
|