ruby-puppetdb 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f199ac32e1da71ed00c19f6b157660787d08a86
4
- data.tar.gz: 53c9970cb340bc587b2b3cdec6aaeda8133c5e40
3
+ metadata.gz: 88be7794aca945016db299dffdd58a3bfbddcbc5
4
+ data.tar.gz: c90c01f08accf3a7ba7e66ac8b6360a63d77ed15
5
5
  SHA512:
6
- metadata.gz: 385d225ca591427dde487a9d9a3232cc016b936c7c9014394361bee489109c6b963a5ab141e3dd3f76b5c0819ad04b3dea8edaae093b93236fd9c584f459d8f1
7
- data.tar.gz: afbb1e20ae8091011201d092aadfb6a7696b680cac65a7d3cc49800b986d37d88398655c382ae7266b63f3b5b0e81507eebe292afca72dad29430e2f70792fc9
6
+ metadata.gz: ffc5acdeb4cb4066c6aea9a567774cf91dc50cf3b4e313b382f949ba5301ed2de43daf7be04c177fb049d2f28e4de7b2466ba906c3c909359be06400e883b48b
7
+ data.tar.gz: a75d1b296d2207410e49b3fe3e4f151f4eca44b62d5a27043a980421cdde123604150ddfec5a1deff7c98a989c7974e00c087d8ef9955e221a07fd6b9dc96c8d
@@ -1,6 +1,6 @@
1
1
  require 'puppet/application/face_base'
2
2
 
3
- class Puppet::Application::Query < Puppet::Application::FaceBase
3
+ class Puppet::Application::Puppetdbquery < Puppet::Application::FaceBase
4
4
  def self.setting
5
5
  use_ssl = true
6
6
  begin
@@ -2,13 +2,13 @@ require 'puppet/application/query'
2
2
  require 'puppet/face'
3
3
  require 'puppet/util/colors'
4
4
 
5
- Puppet::Face.define(:query, '1.0.0') do
5
+ Puppet::Face.define(:puppetdbquery, '1.0.0') do
6
6
  require 'puppetdb/connection'
7
7
  PuppetDB::Connection.check_version
8
8
 
9
9
  extend Puppet::Util::Colors
10
10
 
11
- copyright 'Erik Dalen & Puppet Labs', 2012..2015
11
+ copyright 'Erik Dalen', 2012..2017
12
12
  license 'Apache 2 license; see COPYING'
13
13
 
14
14
  option '--host PUPPETDB' do
@@ -0,0 +1,34 @@
1
+ # The `puppetdb_lookup_key` is a hiera 5 `lookup_key` data provider function.
2
+ # See (https://docs.puppet.com/puppet/latest/hiera_custom_lookup_key.html) for
3
+ # more info.
4
+ #
5
+ # See README.md#hiera-backend for usage.
6
+ #
7
+ Puppet::Functions.create_function(:puppetdb_lookup_key) do
8
+
9
+ dispatch :puppetdb_lookup_key do
10
+ param 'String[1]', :key
11
+ param 'Hash[String[1],Any]', :options
12
+ param 'Puppet::LookupContext', :context
13
+ end
14
+
15
+ def puppetdb_lookup_key(key, options, context)
16
+ return context.cached_value(key) if context.cache_has_key(key)
17
+
18
+ if !key.end_with?('::_nodequery') && nodequery = call_function('lookup', "#{key}::_nodequery", 'merge' => 'first', 'default_value' => nil)
19
+ # Support specifying the query in a few different ways
20
+ query, fact, sort = case nodequery
21
+ when Hash then [nodequery['query'], nodequery['fact'], nodequery['sort']]
22
+ when Array then nodequery
23
+ else [nodequery.to_s, nil, nil]
24
+ end
25
+
26
+ paramz = [query, fact].compact
27
+ result = call_function('query_nodes', *paramz)
28
+ result.sort! if sort
29
+ context.cache(key, result)
30
+ else
31
+ context.not_found
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
1
  module PuppetDB
2
2
  # Current version of this module
3
- VERSION ||= [2, 3, 0].freeze
3
+ VERSION ||= [3, 0, 0].freeze
4
4
  end
@@ -46,7 +46,10 @@ module PuppetDB::ParserHelper
46
46
  fact_hash.reduce({}) do |ret, fact|
47
47
  # Array#include? only matches on values of the same type, so if we find
48
48
  # a matching string, it's not a nested query.
49
- name, value = if facts.include?(fact['name']) || facts == [:all]
49
+ name, value = if facts.include?(fact['name']) || facts == [:all] ||
50
+ # in case a regex pattern is used in the facts query
51
+ facts.index{ |factname| factname =~ /^\/(.+)\/$/ && Regexp.new(factname.match(/^\/(.+)\/$/)[1]).match(fact['name']) }
52
+
50
53
  [fact['name'], fact['value']]
51
54
  else
52
55
  # Find the set of keys where the first value is the fact name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-puppetdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Dalen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -183,8 +183,9 @@ files:
183
183
  - examples/query_node_examples.pp
184
184
  - examples/query_resource_examples.pp
185
185
  - lib/hiera/backend/puppetdb_backend.rb
186
- - lib/puppet/application/query.rb
187
- - lib/puppet/face/query.rb
186
+ - lib/puppet/application/puppetdbquery.rb
187
+ - lib/puppet/face/puppetdbquery.rb
188
+ - lib/puppet/functions/puppetdb_lookup_key.rb
188
189
  - lib/puppet/functions/query_facts.rb
189
190
  - lib/puppet/functions/query_nodes.rb
190
191
  - lib/puppet/parser/functions/query_facts.rb
@@ -224,17 +225,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  version: '0'
225
226
  requirements: []
226
227
  rubyforge_project:
227
- rubygems_version: 2.4.8
228
+ rubygems_version: 2.6.14
228
229
  signing_key:
229
230
  specification_version: 4
230
231
  summary: Query functions for PuppetDB
231
232
  test_files:
232
- - spec/puppet/util/puppetdb.rb
233
- - spec/spec_helper.rb
234
233
  - spec/unit/puppetdb/parser_spec.rb
234
+ - spec/spec_helper.rb
235
+ - spec/puppet/util/puppetdb.rb
235
236
  - spec/functions/query_facts_spec.rb
236
- - spec/functions/query_nodes_spec.rb
237
237
  - spec/functions/query_resources_spec.rb
238
+ - spec/functions/query_nodes_spec.rb
239
+ - examples/query_node_examples.pp
238
240
  - examples/nova_functions.pp
239
241
  - examples/query_resource_examples.pp
240
- - examples/query_node_examples.pp