ruby-puppetdb 2.0.2 → 2.0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQ0Yjk1ZjhhYTY0NjAwZjZhNDlkZjllZWQxY2U5ZDFkOTc3NjUyOA==
4
+ YmEzMGI0YWE2YjMyNmE5YmJlZTM0ZTEzNWU5NzVkYTk0MWQ5NjAyZg==
5
5
  data.tar.gz: !binary |-
6
- MTVkYzlkMjY4MDNjZTYwZGJlNzk4ODI1ZjQ3NjMwY2JiMDQwNmRmZA==
6
+ NWVjOGNiOGM2Y2EzOWFiODRhNDQ2MTliZjBjZDUxNmQ4NTMyNDg5MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmY2YWM0Nzc4ZjVkZDI0OGRkYmUyNGQyZTA0NGJjNzk5YTYwZWUzNGRiNGUx
10
- M2RiMjdlMDNlODQ4N2E3MDg5MjE0YjMyNGQ1YTQzMTRlNDAzMWI3OGZjZGVm
11
- MzRjMGZhMWFmNzVmMGI1ZGQzOWJhYTczZDc3OWY2MTkyYjg4MTE=
9
+ YmE1MGQ2N2ZiNDUwODg5ZTJkOTEzMzczYWUzNjg0OTU3NDc2ZjE4MGU3MGMz
10
+ OGQ0YTY0OTIxYWI4ZWMzMTcwMmIxYTJlZmNjOWIzMzZkMTNmNTFiZWRiYzQ5
11
+ MTBhNmIxNDg1M2VkMGY2MzQ1YTc5NDQyM2EwNDA2MDExOWNiNGE=
12
12
  data.tar.gz: !binary |-
13
- M2U3MTg1ZThjZWQzNjBkNjJhNDRlOGJmMmUyNjI4OTU5ZTNmYjQzNTI1NjVl
14
- YTI1NzJmNTE2NjkwNTQyNmE0ZDMxZWVhZDEyZjE0OWJhZjhlYjgzNDZmNTZm
15
- Njc5ZTdkNDBiZGExYjJlNTI5ZWUwZDkxZDkyZTlkOWVjZGY0MWM=
13
+ ZjE2YmViNDU3NDYyM2FlYzMwNzE3MDlmZDcyYjA3ZTc4NmVhNWEwNDU3YTRm
14
+ Zjk2NjY1ZjFmYzg3YjYyYzljZGMwYmVmMWQ2Njk0NjgzMzFmY2QxNDg3ZGY1
15
+ ZjkwZTJkY2U0ZGVlZjg3NWI0OTAwNmQzZjQ1ZWM1MzYzNmQyODU=
@@ -12,14 +12,16 @@ class Hiera
12
12
  uri = URI(Puppet::Util::Puppetdb.config.server_urls.first)
13
13
  host = uri.host
14
14
  port = uri.port
15
+ ssl = uri.scheme == 'https'
15
16
  rescue
16
17
  host = 'puppetdb'
17
18
  port = 443
19
+ ssl = true
18
20
  end
19
21
 
20
22
  Hiera.debug('Hiera PuppetDB backend starting')
21
23
 
22
- @puppetdb = PuppetDB::Connection.new(host, port)
24
+ @puppetdb = PuppetDB::Connection.new(host, port, ssl)
23
25
  @parser = PuppetDB::Parser.new
24
26
  end
25
27
 
@@ -64,7 +64,7 @@ Puppet::Face.define(:query, '1.0.0') do
64
64
 
65
65
  arguments '<query>'
66
66
 
67
- option '--node_info BOOLEAN' do
67
+ option '--node_info' do
68
68
  summary 'return full info about each node or just name'
69
69
  description <<-EOT
70
70
  If true the full information about each host is returned including fact, report and catalog timestamps.
@@ -29,8 +29,8 @@ EOT
29
29
  PuppetDB::Connection.check_version
30
30
 
31
31
  uri = URI(Puppet::Util::Puppetdb.config.server_urls.first)
32
- puppetdb = PuppetDB::Connection.new(uri.host, uri.port)
32
+ puppetdb = PuppetDB::Connection.new(uri.host, uri.port, uri.scheme == 'https')
33
33
  parser = PuppetDB::Parser.new
34
34
  query = parser.facts_query query, facts if query.is_a? String
35
- puppetdb.query(:facts, query)
35
+ parser.facts_hash(puppetdb.query(:facts, query))
36
36
  end
@@ -26,7 +26,7 @@ EOT
26
26
  PuppetDB::Connection.check_version
27
27
 
28
28
  uri = URI(Puppet::Util::Puppetdb.config.server_urls.first)
29
- puppetdb = PuppetDB::Connection.new(uri.host, uri.port)
29
+ puppetdb = PuppetDB::Connection.new(uri.host, uri.port, uri.scheme == 'https')
30
30
  parser = PuppetDB::Parser.new
31
31
  if fact
32
32
  query = parser.facts_query query, [fact]
@@ -44,7 +44,7 @@ EOT
44
44
  PuppetDB::Connection.check_version
45
45
 
46
46
  uri = URI(Puppet::Util::Puppetdb.config.server_urls.first)
47
- puppetdb = PuppetDB::Connection.new(uri.host, uri.port)
47
+ puppetdb = PuppetDB::Connection.new(uri.host, uri.port, uri.scheme == 'https')
48
48
  parser = PuppetDB::Parser.new
49
49
  nodequery = parser.parse nodequery, :facts if nodequery and nodequery.is_a? String
50
50
  resquery = parser.parse resquery, :none if resquery and resquery.is_a? String
data/lib/puppetdb.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PuppetDB
2
2
  # Current version of this module
3
- VERSION = [2, 0, 2]
3
+ VERSION = [2, 0, 3]
4
4
  end
@@ -86,7 +86,7 @@ class PuppetDB::ASTNode
86
86
  [value.to_s, *evaluate_children(mode)]
87
87
  when :subquery
88
88
  mode.push :subquery
89
- ret = subquery(mode.last, value + 's', children[0].evaluate(mode))
89
+ ret = subquery(mode[-2], value + 's', children[0].evaluate(mode))
90
90
  mode.pop
91
91
  ret
92
92
  when :regexp_node_match
@@ -123,7 +123,7 @@ class PuppetDB::ASTNode
123
123
  else
124
124
  title = value[:title].evaluate
125
125
  end
126
- ret = subquery(mode.last, :resources,
126
+ ret = subquery(mode[-2], :resources,
127
127
  ['and',
128
128
  ['=', 'type', capitalize_class(value[:type])],
129
129
  [regexp ? '~' : '=', 'title', title],
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+ require 'puppetdb/connection'
5
+
6
+ describe 'query_facts' do
7
+ it do
8
+ PuppetDB::Connection.any_instance.stubs(:query).returns [
9
+ { 'certname' => 'apache4.puppetexplorer.io', 'environment' => 'production', 'name' => 'ipaddress', 'value' => '172.31.6.80' }
10
+ ]
11
+ should run.with_params('', ['ipaddress']).and_return('apache4.puppetexplorer.io' => { 'ipaddress' => '172.31.6.80' })
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'query_nodes' do
6
+ context 'without fact parameter' do
7
+ it do
8
+ PuppetDB::Connection.any_instance.expects(:query)
9
+ .with(:nodes, ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['hostname']], ['=', 'value', 'apache4']]]]])
10
+ .returns [
11
+ {
12
+ 'certname' => 'apache4.puppetexplorer.io',
13
+ 'deactivated' => nil,
14
+ 'latest_report_hash' => '4ff9fc5c1344c1c6ce47d923eb139a3409ef530d',
15
+ 'facts_environment' => 'production',
16
+ 'report_environment' => 'production',
17
+ 'catalog_environment' => 'production',
18
+ 'facts_timestamp' => '2015-10-13T05:35:32.511Z',
19
+ 'expired' => nil,
20
+ 'report_timestamp' => '2015-10-13T05:33:17.011Z',
21
+ 'catalog_timestamp' => '2015-10-13T05:35:38.661Z',
22
+ 'latest_report_status' => 'changed'
23
+ }
24
+ ]
25
+ should run.with_params('hostname="apache4"').and_return(['apache4.puppetexplorer.io'])
26
+ end
27
+ end
28
+
29
+ context 'with a fact parameter' do
30
+ it do
31
+ PuppetDB::Connection.any_instance.expects(:query)
32
+ .with(:facts, ['and', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['hostname']], ['=', 'value', 'apache4']]]]], ['or', ['=', 'name', 'ipaddress']]])
33
+ .returns [
34
+ {
35
+ 'certname' => 'apache4.puppetexplorer.io',
36
+ 'environment' => 'production',
37
+ 'name' => 'ipaddress',
38
+ 'value' => '172.31.6.80'
39
+ }
40
+ ]
41
+ should run.with_params('hostname="apache4"', 'ipaddress').and_return(['172.31.6.80'])
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'query_resources' do
6
+ it do
7
+ resource = { 'tags' => %w(apache package class __node_regexp__apache httpd node),
8
+ 'file' => '/etc/puppetlabs/code/environments/production/modules/apache/manifests/init.pp',
9
+ 'type' => 'Package',
10
+ 'title' => 'httpd',
11
+ 'line' => 103,
12
+ 'resource' => 'c239274125740582bc181dfcb7dcb3e476ada592',
13
+ 'environment' => 'production',
14
+ 'certname' => 'apache4.puppetexplorer.io',
15
+ 'parameters' => { 'ensure' => 'installed', 'name' => 'apache2', 'notify' => 'Class[Apache::Service]' },
16
+ 'exported' => false }
17
+ PuppetDB::Connection.any_instance.expects(:query)
18
+ .with(:resources, ['and', ['and', ['=', 'type', 'Package'], ['=', 'title', 'httpd'], ['=', 'exported', false]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['hostname']], ['=', 'value', 'apache4']]]]]])
19
+ .returns [resource]
20
+ should run.with_params('hostname=apache4', 'package[httpd]')
21
+ .and_return([resource])
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'uri'
2
+
3
+ # Minimal mock class for PuppetDB config
4
+ module Puppet::Util::Puppetdb
5
+ class Config
6
+ def server_urls
7
+ [URI('http://puppetdb.puppetexplorer.io')]
8
+ end
9
+ end
10
+
11
+ def self.config
12
+ Puppet::Util::Puppetdb::Config.new
13
+ end
14
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'rspec/expectations'
3
-
4
3
  require 'puppetlabs_spec_helper/module_spec_helper'
4
+ require 'rspec-puppet'
5
+
6
+ fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
7
+
8
+ RSpec.configure do |c|
9
+ c.module_path = File.join(fixture_path, 'modules')
10
+ c.manifest_dir = File.join(fixture_path, 'manifests')
11
+ end
@@ -184,6 +184,10 @@ describe PuppetDB::Parser do
184
184
  date = Time.new(2014, 9, 9).iso8601
185
185
  parser.parse('#node.report_timestamp<@"Sep 9, 2014"').should eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['<', 'report_timestamp', date]]]]
186
186
  end
187
+
188
+ it 'should not wrap it in a subquery if mode is :none' do
189
+ parser.parse('class[apache]', :none).should eq ["and", ["=", "type", "Class"], ["=", "title", "Apache"], ["=", "exported", false]]
190
+ end
187
191
  end
188
192
 
189
193
  context 'facts_query' do
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.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Dalen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-puppet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -182,9 +196,11 @@ files:
182
196
  - lib/puppetdb/lexer.rex
183
197
  - lib/puppetdb/parser.rb
184
198
  - lib/puppetdb/parser_helper.rb
199
+ - spec/functions/query_facts_spec.rb
200
+ - spec/functions/query_nodes_spec.rb
201
+ - spec/functions/query_resources_spec.rb
202
+ - spec/puppet/util/puppetdb.rb
185
203
  - spec/spec_helper.rb
186
- - spec/unit/puppet/parser/functions/query_facts_spec.rb
187
- - spec/unit/puppet/parser/functions/query_nodes_spec.rb
188
204
  - spec/unit/puppetdb/parser_spec.rb
189
205
  homepage: https://github.com/dalen/puppet-puppetdbquery
190
206
  licenses:
@@ -212,9 +228,11 @@ specification_version: 4
212
228
  summary: Query functions for PuppetDB
213
229
  test_files:
214
230
  - spec/unit/puppetdb/parser_spec.rb
215
- - spec/unit/puppet/parser/functions/query_nodes_spec.rb
216
- - spec/unit/puppet/parser/functions/query_facts_spec.rb
217
231
  - spec/spec_helper.rb
232
+ - spec/puppet/util/puppetdb.rb
233
+ - spec/functions/query_resources_spec.rb
234
+ - spec/functions/query_nodes_spec.rb
235
+ - spec/functions/query_facts_spec.rb
218
236
  - examples/query_resource_examples.pp
219
237
  - examples/query_node_examples.pp
220
238
  - examples/nova_functions.pp
@@ -1,11 +0,0 @@
1
- #! /usr/bin/env ruby -S rspec
2
-
3
- require 'spec_helper'
4
-
5
- describe "the query_facts function" do
6
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
-
8
- it "should exist" do
9
- Puppet::Parser::Functions.function("query_facts").should == "function_query_facts"
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- #! /usr/bin/env ruby -S rspec
2
-
3
- require 'spec_helper'
4
-
5
- describe "the query_nodes function" do
6
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7
-
8
- it "should exist" do
9
- Puppet::Parser::Functions.function("query_nodes").should == "function_query_nodes"
10
- end
11
- end