puppetdb-ruby 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +33 -0
- data/README.md +86 -14
- data/lib/puppetdb.rb +6 -3
- data/lib/puppetdb/client.rb +48 -28
- data/lib/puppetdb/query.rb +9 -9
- data/lib/puppetdb/response.rb +1 -1
- data/lib/puppetdb/version.rb +3 -0
- metadata +98 -20
- data/.gitignore +0 -3
- data/Gemfile +0 -8
- data/spec/spec_helper.rb +0 -3
- data/spec/unit/client_spec.rb +0 -179
- data/spec/unit/query_spec.rb +0 -179
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 282cff2e55783d3ee94a952746316ba91305e2a5
|
4
|
+
data.tar.gz: 2b6a524d1dc2c13d0525082e326052b3af1f275b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbac872da30cebe0f3f00e8262d8bb4451774b46cf0e66ef2c0934e4f8135446d296fc2b7a63647e07fd49adc3d3e7974f6c412c3eefed9601d32a293289faff
|
7
|
+
data.tar.gz: 2f6088df22bb0c7bf550d4f0eb1f6ce85b3d64893c1a8ae93a15031d3c1c471624b27f273fde1cb33596f7cdcb1249ebfa7e057395f84f729eec3f7cc956af9f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
Each new release typically also includes the latest modulesync defaults.
|
5
|
+
These should not impact the functionality of the module.
|
6
|
+
|
7
|
+
## [v1.0.0](https://github.com/voxpupuli/puppetdb-ruby/tree/v1.0.0) (2017-08-01)
|
8
|
+
**Implemented enhancements:**
|
9
|
+
|
10
|
+
- Preparatory cleanup for refactor [\#21](https://github.com/voxpupuli/puppetdb-ruby/pull/21) ([dhollinger](https://github.com/dhollinger))
|
11
|
+
- Allow usage of unauthenticated PuppetDB over SSL [\#14](https://github.com/voxpupuli/puppetdb-ruby/pull/14) ([cassianoleal](https://github.com/cassianoleal))
|
12
|
+
|
13
|
+
**Closed issues:**
|
14
|
+
|
15
|
+
- Refactor to support v4 endpoints [\#20](https://github.com/voxpupuli/puppetdb-ruby/issues/20)
|
16
|
+
- API V4 Example [\#13](https://github.com/voxpupuli/puppetdb-ruby/issues/13)
|
17
|
+
- 'summarize-by' parameter not supported [\#9](https://github.com/voxpupuli/puppetdb-ruby/issues/9)
|
18
|
+
- Thanks! [\#6](https://github.com/voxpupuli/puppetdb-ruby/issues/6)
|
19
|
+
- Only GET requests supported [\#4](https://github.com/voxpupuli/puppetdb-ruby/issues/4)
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- Update Docs for Release 1.0.0 [\#23](https://github.com/voxpupuli/puppetdb-ruby/pull/23) ([dhollinger](https://github.com/dhollinger))
|
24
|
+
- Add command API support [\#19](https://github.com/voxpupuli/puppetdb-ruby/pull/19) ([bekbulatov](https://github.com/bekbulatov))
|
25
|
+
- \(maint\) Transfer ownership to Vox Pupuli [\#18](https://github.com/voxpupuli/puppetdb-ruby/pull/18) ([rlinehan](https://github.com/rlinehan))
|
26
|
+
- "Voxpupulify" [\#17](https://github.com/voxpupuli/puppetdb-ruby/pull/17) ([nibalizer](https://github.com/nibalizer))
|
27
|
+
- Add Contributing Guidelines [\#7](https://github.com/voxpupuli/puppetdb-ruby/pull/7) ([rlinehan](https://github.com/rlinehan))
|
28
|
+
- Feature/fix readme [\#3](https://github.com/voxpupuli/puppetdb-ruby/pull/3) ([robinbowes](https://github.com/robinbowes))
|
29
|
+
- Update README with correct initialization of client [\#1](https://github.com/voxpupuli/puppetdb-ruby/pull/1) ([ccaum](https://github.com/ccaum))
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -3,54 +3,126 @@
|
|
3
3
|
a simple gem for interacting with the
|
4
4
|
[PuppetDB](https://github.com/puppetlabs/puppetdb) API.
|
5
5
|
|
6
|
+
This library was migrated from [puppetlabs](https://github.com/puppetlabs)
|
7
|
+
ownership to VoxPupuli on 19 October 2016.
|
8
|
+
|
6
9
|
## Installation
|
7
10
|
|
11
|
+
Installing from Ruby CLI:
|
12
|
+
```
|
8
13
|
gem install puppetdb-ruby
|
14
|
+
```
|
15
|
+
|
16
|
+
Include in Gemfile:
|
17
|
+
``` ruby
|
18
|
+
gem 'puppetdb-ruby'
|
19
|
+
```
|
9
20
|
|
10
21
|
## Usage
|
11
22
|
|
23
|
+
Require the puppetdb gem in your ruby code.
|
24
|
+
|
12
25
|
```ruby
|
13
26
|
require 'puppetdb'
|
14
27
|
|
15
28
|
# Defaults to latest API version.
|
29
|
+
```
|
16
30
|
|
17
|
-
|
18
|
-
client = PuppetDB::Client({:server => 'http://localhost:8080'})
|
31
|
+
#### Create a new connection:
|
19
32
|
|
20
|
-
|
21
|
-
|
33
|
+
Non-SSL:
|
34
|
+
``` ruby
|
35
|
+
client = PuppetDB::Client.new({:server => 'http://localhost:8080'})
|
36
|
+
```
|
37
|
+
|
38
|
+
SSL:
|
39
|
+
``` ruby
|
40
|
+
client = PuppetDB::Client.new({
|
22
41
|
:server => 'https://localhost:8081',
|
23
42
|
:pem => {
|
24
|
-
|
25
|
-
|
26
|
-
|
43
|
+
'key' => "keyfile",
|
44
|
+
'cert' => "certfile",
|
45
|
+
'ca_file' => "cafile"
|
27
46
|
}})
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Query API usage
|
50
|
+
|
51
|
+
The Query Feature allows the user to request data from PuppetDB using the Query endpoints. It defaults to the latest version of the Query Endpoint.
|
52
|
+
|
53
|
+
Currently, `puppetdb-ruby` only supports the [AST Query Language](https://docs.puppet.com/puppetdb/5.0/api/query/v4/ast.html).
|
54
|
+
|
55
|
+
Support for the [PQL Query Language](https://docs.puppet.com/puppetdb/5.0/api/query/tutorial-pql.html) is planned for a future release.
|
56
|
+
|
57
|
+
Example:
|
58
|
+
``` ruby
|
59
|
+
response = client.request(
|
60
|
+
'nodes',
|
61
|
+
[:and,
|
62
|
+
[:'=', ['fact', 'kernel'], 'Linux'],
|
63
|
+
[:>, ['fact', 'uptime_days'], 30]
|
64
|
+
],
|
65
|
+
{:limit => 10}
|
66
|
+
)
|
28
67
|
|
29
|
-
response = client.request([:and,
|
30
|
-
[:'=', ['fact', 'kernel'], 'Linux'],
|
31
|
-
[:>, ['fact', 'uptime_days'], 30]]], {:limit => 10})
|
32
68
|
nodes = response.data
|
33
69
|
|
34
70
|
# queries are composable
|
35
71
|
|
36
|
-
uptime = PuppetDB::Query[:>, [
|
37
|
-
redhat = PuppetDB::Query[:'=', [
|
38
|
-
debian = PuppetDB::Query[:'=', [
|
72
|
+
uptime = PuppetDB::Query[:>, [:fact, 'uptime_days'], 30]
|
73
|
+
redhat = PuppetDB::Query[:'=', [:fact, 'osfamily'], 'RedHat']
|
74
|
+
debian = PuppetDB::Query[:'=', [:fact, 'osfamily'], 'Debian']
|
39
75
|
|
40
76
|
client.request uptime.and(debian)
|
41
77
|
client.request uptime.and(redhat)
|
42
78
|
client.request uptime.and(debian.or(redhat))
|
43
79
|
```
|
44
80
|
|
45
|
-
|
81
|
+
See the [PuppetDB API Docs](https://docs.puppet.com/puppetdb/5.0/api/index.html) for more.
|
46
82
|
|
83
|
+
#### Command API Usage
|
84
|
+
|
85
|
+
The Command Feature allows the user to execute REST Commands against the PuppetDB Command API Endpoints. It defaults to the latest version of the Command Endpoint.
|
86
|
+
|
87
|
+
The command method takes three arguments:
|
88
|
+
|
89
|
+
* `command`: a string identifying the command
|
90
|
+
* `payload`: a valid JSON object of any sort. It’s up to an individual handler function to determine how to interpret that object.
|
91
|
+
* `version`: a JSON integer describing what version of the given command you’re attempting to invoke. The version of the command also indicates the version of the wire format to use for the command.
|
92
|
+
|
93
|
+
Example:
|
94
|
+
``` ruby
|
95
|
+
client.command(
|
96
|
+
'deactivate node',
|
97
|
+
{'certname' => 'test1', 'producer_timestamp' => '2015-01-01'},
|
98
|
+
3
|
99
|
+
)
|
100
|
+
```
|
101
|
+
|
102
|
+
See the PuppetDB [Commands Endpoint Docs](https://docs.puppet.com/puppetdb/5.0/api/command/v1/commands.html) for more information.
|
103
|
+
|
104
|
+
## Tests
|
105
|
+
|
106
|
+
```
|
47
107
|
bundle install
|
48
108
|
bundle exec rspec
|
109
|
+
```
|
110
|
+
|
111
|
+
## Issues & Contributions
|
112
|
+
|
113
|
+
File issues or feature requests using [GitHub
|
114
|
+
issues](https://github.com/voxpupuli/puppetdb-ruby/issues).
|
115
|
+
|
116
|
+
If you are interested in contributing to this project, please see the
|
117
|
+
[Contribution Guidelines](CONTRIBUTING.md)
|
49
118
|
|
50
119
|
## Authors
|
51
120
|
|
121
|
+
This module was donated to VoxPupuli by Puppet Inc on 10-19-2016.
|
122
|
+
|
52
123
|
Nathaniel Smith <nathaniel@puppetlabs.com>
|
53
124
|
Lindsey Smith <lindsey@puppetlabs.com>
|
125
|
+
Ruth Linehan <ruth@puppetlabs.com>
|
54
126
|
|
55
127
|
## License
|
56
128
|
|
data/lib/puppetdb.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'puppetdb/version'
|
2
|
+
require 'puppetdb/client'
|
3
|
+
require 'puppetdb/query'
|
4
|
+
require 'puppetdb/response'
|
5
|
+
|
6
|
+
module PuppetDB; end
|
data/lib/puppetdb/client.rb
CHANGED
@@ -2,7 +2,7 @@ require 'httparty'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
module PuppetDB
|
5
|
-
class APIError <
|
5
|
+
class APIError < RuntimeError
|
6
6
|
attr_reader :code, :response
|
7
7
|
def initialize(response)
|
8
8
|
@response = response
|
@@ -27,85 +27,105 @@ module PuppetDB
|
|
27
27
|
untouched = hash[key]
|
28
28
|
return untouched if untouched
|
29
29
|
|
30
|
-
sym = hash[key.to_sym
|
30
|
+
sym = hash[key.to_sym]
|
31
31
|
return sym if sym
|
32
32
|
|
33
|
-
str = hash[key.to_s
|
33
|
+
str = hash[key.to_s]
|
34
34
|
return str if str
|
35
35
|
|
36
36
|
nil
|
37
37
|
end
|
38
38
|
|
39
39
|
def hash_includes?(hash, *sought_keys)
|
40
|
-
sought_keys.each {|x| return false unless hash.include?(x)}
|
40
|
+
sought_keys.each { |x| return false unless hash.include?(x) }
|
41
41
|
true
|
42
42
|
end
|
43
43
|
|
44
44
|
def debug(msg)
|
45
|
-
if @logger
|
46
|
-
@logger.debug(msg)
|
47
|
-
end
|
45
|
+
@logger.debug(msg) if @logger
|
48
46
|
end
|
49
47
|
|
50
|
-
def initialize(settings,
|
51
|
-
@
|
48
|
+
def initialize(settings, query_api_version = 4, command_api_version = 1)
|
49
|
+
@query_api_version = query_api_version
|
50
|
+
@command_api_version = command_api_version
|
52
51
|
|
53
52
|
server = hash_get(settings, 'server')
|
54
53
|
pem = hash_get(settings, 'pem')
|
55
54
|
|
56
55
|
scheme = URI.parse(server).scheme
|
57
56
|
|
58
|
-
unless [
|
59
|
-
error_msg =
|
57
|
+
unless %w[http https].include? scheme
|
58
|
+
error_msg = 'Configuration error: :server must specify a protocol of either http or https'
|
60
59
|
raise error_msg
|
61
60
|
end
|
62
61
|
|
63
62
|
@use_ssl = scheme == 'https'
|
64
|
-
if @use_ssl
|
65
|
-
unless
|
63
|
+
if @use_ssl && pem
|
64
|
+
unless hash_includes?(pem, 'key', 'cert', 'ca_file')
|
66
65
|
error_msg = 'Configuration error: https:// specified but pem is missing or incomplete. It requires cert, key, and ca_file.'
|
67
66
|
raise error_msg
|
68
67
|
end
|
69
68
|
|
70
|
-
self.class.default_options = {:pem
|
69
|
+
self.class.default_options = { pem: pem }
|
71
70
|
self.class.connection_adapter(FixSSLConnectionAdapter)
|
72
71
|
end
|
73
72
|
|
74
|
-
self.class.base_uri(server
|
73
|
+
self.class.base_uri(server)
|
75
74
|
end
|
76
75
|
|
77
76
|
def raise_if_error(response)
|
78
|
-
if response.code.to_s
|
79
|
-
raise APIError.new(response)
|
80
|
-
end
|
77
|
+
raise APIError, response if response.code.to_s =~ %r{^[4|5]}
|
81
78
|
end
|
82
79
|
|
83
|
-
def request(endpoint, query, opts={})
|
80
|
+
def request(endpoint, query, opts = {})
|
84
81
|
query = PuppetDB::Query.maybe_promote(query)
|
85
|
-
json_query = query.build
|
82
|
+
json_query = query.build
|
86
83
|
|
87
|
-
path = "/" + endpoint
|
84
|
+
path = "/pdb/query/v#{@query_api_version}/" + endpoint
|
88
85
|
|
89
|
-
filtered_opts = {'query' => json_query}
|
90
|
-
opts.each do |k,v|
|
86
|
+
filtered_opts = { 'query' => json_query }
|
87
|
+
opts.each do |k, v|
|
91
88
|
if k == :counts_filter
|
92
89
|
filtered_opts['counts-filter'] = JSON.dump(v)
|
93
90
|
else
|
94
|
-
filtered_opts[k.to_s.sub(
|
91
|
+
filtered_opts[k.to_s.sub('_', '-')] = v
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
98
95
|
debug("#{path} #{json_query} #{opts}")
|
99
96
|
|
100
|
-
ret = self.class.get(path, :
|
97
|
+
ret = self.class.get(path, body: filtered_opts)
|
101
98
|
raise_if_error(ret)
|
102
99
|
|
103
100
|
total = ret.headers['X-Records']
|
104
|
-
if total.nil?
|
105
|
-
total = ret.parsed_response.length
|
106
|
-
end
|
101
|
+
total = ret.parsed_response.length if total.nil?
|
107
102
|
|
108
103
|
Response.new(ret.parsed_response, total)
|
109
104
|
end
|
105
|
+
|
106
|
+
def command(command, payload, version)
|
107
|
+
path = "/pdb/cmd/v#{@command_api_version}"
|
108
|
+
|
109
|
+
query = {
|
110
|
+
'command' => command,
|
111
|
+
'version' => version,
|
112
|
+
'certname' => payload['certname']
|
113
|
+
}
|
114
|
+
|
115
|
+
debug("#{path} #{query} #{payload}")
|
116
|
+
|
117
|
+
ret = self.class.post(
|
118
|
+
path,
|
119
|
+
query: query,
|
120
|
+
body: payload.to_json,
|
121
|
+
headers: {
|
122
|
+
'Accept' => 'application/json',
|
123
|
+
'Content-Type' => 'application/json'
|
124
|
+
}
|
125
|
+
)
|
126
|
+
raise_if_error(ret)
|
127
|
+
|
128
|
+
Response.new(ret.parsed_response)
|
129
|
+
end
|
110
130
|
end
|
111
131
|
end
|
data/lib/puppetdb/query.rb
CHANGED
@@ -4,7 +4,7 @@ module PuppetDB
|
|
4
4
|
class Query
|
5
5
|
attr_reader :sexpr
|
6
6
|
|
7
|
-
def initialize(query=[])
|
7
|
+
def initialize(query = [])
|
8
8
|
@sexpr = query
|
9
9
|
end
|
10
10
|
|
@@ -16,7 +16,7 @@ module PuppetDB
|
|
16
16
|
return Query.new(query) unless query.class == Query
|
17
17
|
query
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def empty?
|
21
21
|
@sexpr.empty?
|
22
22
|
end
|
@@ -28,11 +28,11 @@ module PuppetDB
|
|
28
28
|
# of the non-empty operand. If both operands are empty, the
|
29
29
|
# empty query is returned. If both operands are non-empty, the
|
30
30
|
# compose continues.
|
31
|
-
if query.empty? && !
|
31
|
+
if query.empty? && !empty?
|
32
32
|
Query.new(@sexpr)
|
33
|
-
elsif
|
34
|
-
Query.new(query.sexpr
|
35
|
-
elsif
|
33
|
+
elsif empty? && !query.empty?
|
34
|
+
Query.new(query.sexpr)
|
35
|
+
elsif empty? && query.empty?
|
36
36
|
Query.new([])
|
37
37
|
else
|
38
38
|
yield query
|
@@ -40,15 +40,15 @@ module PuppetDB
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def and(query)
|
43
|
-
compose(query) { |q| Query.new([:and, @sexpr, q.sexpr
|
43
|
+
compose(query) { |q| Query.new([:and, @sexpr, q.sexpr]) }
|
44
44
|
end
|
45
45
|
|
46
46
|
def or(query)
|
47
|
-
compose(query) { |q| Query.new([:or, @sexpr, q.sexpr
|
47
|
+
compose(query) { |q| Query.new([:or, @sexpr, q.sexpr]) }
|
48
48
|
end
|
49
49
|
|
50
50
|
def push(query)
|
51
|
-
compose(query) { |q| Query.new(@sexpr.dup.push(q.sexpr
|
51
|
+
compose(query) { |q| Query.new(@sexpr.dup.push(q.sexpr)) }
|
52
52
|
end
|
53
53
|
|
54
54
|
def build
|
data/lib/puppetdb/response.rb
CHANGED
metadata
CHANGED
@@ -1,73 +1,151 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetdb-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
7
|
+
- Vox Pupuli
|
8
8
|
- Nathaniel Smith
|
9
9
|
- Lindsey Smith
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
18
|
requirements:
|
20
|
-
- -
|
19
|
+
- - ">="
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
25
|
requirements:
|
28
|
-
- -
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: mocha
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rubocop
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.48.1
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.48.1
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rubocop-rspec
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 1.15.1
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.15.1
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: github_changelog_generator
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
29
111
|
- !ruby/object:Gem::Version
|
30
112
|
version: '0'
|
31
113
|
description:
|
32
|
-
email:
|
114
|
+
email: voxpupuli@groups.io
|
33
115
|
executables: []
|
34
116
|
extensions: []
|
35
117
|
extra_rdoc_files: []
|
36
118
|
files:
|
37
|
-
- .
|
38
|
-
- Gemfile
|
119
|
+
- CHANGELOG.md
|
39
120
|
- LICENSE
|
40
121
|
- README.md
|
41
122
|
- lib/puppetdb.rb
|
42
123
|
- lib/puppetdb/client.rb
|
43
124
|
- lib/puppetdb/query.rb
|
44
125
|
- lib/puppetdb/response.rb
|
45
|
-
-
|
46
|
-
|
47
|
-
- spec/unit/query_spec.rb
|
48
|
-
homepage: https://github.com/puppetlabs/puppetdb-ruby
|
126
|
+
- lib/puppetdb/version.rb
|
127
|
+
homepage: https://github.com/voxpupuli/puppetdb-ruby
|
49
128
|
licenses:
|
50
129
|
- apache
|
130
|
+
metadata: {}
|
51
131
|
post_install_message:
|
52
132
|
rdoc_options: []
|
53
133
|
require_paths:
|
54
134
|
- lib
|
55
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
136
|
requirements:
|
58
|
-
- -
|
137
|
+
- - ">="
|
59
138
|
- !ruby/object:Gem::Version
|
60
139
|
version: '0'
|
61
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
141
|
requirements:
|
64
|
-
- -
|
142
|
+
- - ">="
|
65
143
|
- !ruby/object:Gem::Version
|
66
144
|
version: '0'
|
67
145
|
requirements: []
|
68
146
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
147
|
+
rubygems_version: 2.4.5
|
70
148
|
signing_key:
|
71
|
-
specification_version:
|
149
|
+
specification_version: 4
|
72
150
|
summary: Simple Ruby client library for PuppetDB API
|
73
151
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/spec/spec_helper.rb
DELETED
data/spec/unit/client_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'puppetdb')
|
3
|
-
|
4
|
-
def make_mock_response
|
5
|
-
m = mock()
|
6
|
-
m.stubs(:code).returns(200)
|
7
|
-
m.expects(:parsed_response).returns(['foo'])
|
8
|
-
m
|
9
|
-
end
|
10
|
-
|
11
|
-
def make_mock_query
|
12
|
-
m = mock()
|
13
|
-
m.expects(:build)
|
14
|
-
m.expects(:summarize_by).returns(m)
|
15
|
-
m
|
16
|
-
end
|
17
|
-
|
18
|
-
def expect_include_total(mock_query)
|
19
|
-
mock_query.expects(:include_total).with(true)
|
20
|
-
mock_query
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'raise_if_error' do
|
24
|
-
settings = {'server' => 'http://localhost:8080'}
|
25
|
-
|
26
|
-
it 'works with 4xx' do
|
27
|
-
response = mock()
|
28
|
-
response.stubs(:code).returns(400)
|
29
|
-
|
30
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should raise_error
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'works with 5xx' do
|
34
|
-
response = mock()
|
35
|
-
response.stubs(:code).returns(500)
|
36
|
-
|
37
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores 2xx' do
|
41
|
-
response = mock()
|
42
|
-
response.stubs(:code).returns(200)
|
43
|
-
|
44
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should_not raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'ignores 3xx' do
|
48
|
-
response = mock()
|
49
|
-
response.stubs(:code).returns(300)
|
50
|
-
|
51
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should_not raise_error
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'SSL support' do
|
56
|
-
describe 'when http:// is specified' do
|
57
|
-
it 'does not use ssl' do
|
58
|
-
settings = {
|
59
|
-
'server' => 'http://localhost:8080'
|
60
|
-
}
|
61
|
-
|
62
|
-
r = PuppetDB::Client.new(settings)
|
63
|
-
expect(r.use_ssl).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'when https:// is specified' do
|
68
|
-
it 'uses ssl' do
|
69
|
-
settings = {
|
70
|
-
'server' => 'https://localhost:8081',
|
71
|
-
'pem' => {
|
72
|
-
'cert' => 'foo',
|
73
|
-
'key' => 'bar',
|
74
|
-
'ca_file' => 'baz'
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
r = PuppetDB::Client.new(settings)
|
79
|
-
expect(r.use_ssl).to eq(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'does not tolerate lack of pem' do
|
83
|
-
settings = {
|
84
|
-
:server => 'https://localhost:8081'
|
85
|
-
}
|
86
|
-
|
87
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'does not tolerate lack of key' do
|
91
|
-
settings = {
|
92
|
-
'server' => 'https://localhost:8081',
|
93
|
-
'pem' => {
|
94
|
-
'cert' => 'foo',
|
95
|
-
'ca_file' => 'bar'
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'does not tolerate lack of cert' do
|
103
|
-
settings = {
|
104
|
-
'server' => 'https://localhost:8081',
|
105
|
-
'pem' => {
|
106
|
-
'key' => 'foo',
|
107
|
-
'ca_file' => 'bar'
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'does not tolerate lack of ca_file' do
|
115
|
-
settings = {
|
116
|
-
'server' => 'https://localhost:8081',
|
117
|
-
'pem' => {
|
118
|
-
'key' => 'foo',
|
119
|
-
'cert' => 'bar'
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe 'when a protocol is missing from config file' do
|
128
|
-
it 'raises an exception' do
|
129
|
-
settings = {
|
130
|
-
'server' => 'localhost:8080'
|
131
|
-
}
|
132
|
-
|
133
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe 'request' do
|
139
|
-
settings = {:server => 'http://localhost'}
|
140
|
-
|
141
|
-
it 'works with array instead of Query' do
|
142
|
-
client = PuppetDB::Client.new(settings)
|
143
|
-
|
144
|
-
mock_response = mock()
|
145
|
-
mock_response.expects(:code).returns(200)
|
146
|
-
mock_response.expects(:headers).returns({'X-Records' => 0})
|
147
|
-
mock_response.expects(:parsed_response).returns([])
|
148
|
-
|
149
|
-
PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with() do |path, opts|
|
150
|
-
opts[:query] == {'query' => '[1,2,3]'}
|
151
|
-
end
|
152
|
-
client.request('/foo', [1,2,3])
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'processes options correctly' do
|
156
|
-
client = PuppetDB::Client.new(settings)
|
157
|
-
|
158
|
-
mock_response = mock()
|
159
|
-
mock_response.expects(:code).returns(200)
|
160
|
-
mock_response.expects(:headers).returns({'X-Records' => 0})
|
161
|
-
mock_response.expects(:parsed_response).returns([])
|
162
|
-
|
163
|
-
PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with() do |path, opts|
|
164
|
-
opts == {
|
165
|
-
:query => {
|
166
|
-
'query' => '[1,2,3]',
|
167
|
-
'limit' => 10,
|
168
|
-
'counts-filter' => '[4,5,6]',
|
169
|
-
'foo-bar' => 'foo'
|
170
|
-
}}
|
171
|
-
end
|
172
|
-
|
173
|
-
client.request('/foo', PuppetDB::Query[1,2,3], {
|
174
|
-
:limit => 10,
|
175
|
-
:counts_filter => [4,5,6],
|
176
|
-
:foo_bar => "foo"
|
177
|
-
})
|
178
|
-
end
|
179
|
-
end
|
data/spec/unit/query_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'puppetdb')
|
3
|
-
|
4
|
-
def make_mock_response
|
5
|
-
m = mock()
|
6
|
-
m.stubs(:code).returns(200)
|
7
|
-
m.expects(:parsed_response).returns(['foo'])
|
8
|
-
m
|
9
|
-
end
|
10
|
-
|
11
|
-
def make_mock_query
|
12
|
-
m = mock()
|
13
|
-
m.expects(:build)
|
14
|
-
m.expects(:summarize_by).returns(m)
|
15
|
-
m
|
16
|
-
end
|
17
|
-
|
18
|
-
def expect_include_total(mock_query)
|
19
|
-
mock_query.expects(:include_total).with(true)
|
20
|
-
mock_query
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'raise_if_error' do
|
24
|
-
settings = {'server' => 'http://localhost:8080'}
|
25
|
-
|
26
|
-
it 'works with 4xx' do
|
27
|
-
response = mock()
|
28
|
-
response.stubs(:code).returns(400)
|
29
|
-
|
30
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should raise_error
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'works with 5xx' do
|
34
|
-
response = mock()
|
35
|
-
response.stubs(:code).returns(500)
|
36
|
-
|
37
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores 2xx' do
|
41
|
-
response = mock()
|
42
|
-
response.stubs(:code).returns(200)
|
43
|
-
|
44
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should_not raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'ignores 3xx' do
|
48
|
-
response = mock()
|
49
|
-
response.stubs(:code).returns(300)
|
50
|
-
|
51
|
-
lambda { PuppetDB::Client.new(settings).raise_if_error(response) }.should_not raise_error
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'SSL support' do
|
56
|
-
describe 'when http:// is specified' do
|
57
|
-
it 'does not use ssl' do
|
58
|
-
settings = {
|
59
|
-
'server' => 'http://localhost:8080'
|
60
|
-
}
|
61
|
-
|
62
|
-
r = PuppetDB::Client.new(settings)
|
63
|
-
expect(r.use_ssl).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'when https:// is specified' do
|
68
|
-
it 'uses ssl' do
|
69
|
-
settings = {
|
70
|
-
'server' => 'https://localhost:8081',
|
71
|
-
'pem' => {
|
72
|
-
'cert' => 'foo',
|
73
|
-
'key' => 'bar',
|
74
|
-
'ca_file' => 'baz'
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
r = PuppetDB::Client.new(settings)
|
79
|
-
expect(r.use_ssl).to eq(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'does not tolerate lack of pem' do
|
83
|
-
settings = {
|
84
|
-
:server => 'https://localhost:8081'
|
85
|
-
}
|
86
|
-
|
87
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'does not tolerate lack of key' do
|
91
|
-
settings = {
|
92
|
-
'server' => 'https://localhost:8081',
|
93
|
-
'pem' => {
|
94
|
-
'cert' => 'foo',
|
95
|
-
'ca_file' => 'bar'
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'does not tolerate lack of cert' do
|
103
|
-
settings = {
|
104
|
-
'server' => 'https://localhost:8081',
|
105
|
-
'pem' => {
|
106
|
-
'key' => 'foo',
|
107
|
-
'ca_file' => 'bar'
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'does not tolerate lack of ca_file' do
|
115
|
-
settings = {
|
116
|
-
'server' => 'https://localhost:8081',
|
117
|
-
'pem' => {
|
118
|
-
'key' => 'foo',
|
119
|
-
'cert' => 'bar'
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe 'when a protocol is missing from config file' do
|
128
|
-
it 'raises an exception' do
|
129
|
-
settings = {
|
130
|
-
'server' => 'localhost:8080'
|
131
|
-
}
|
132
|
-
|
133
|
-
lambda { PuppetDB::Client.new(settings) }.should raise_error
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe 'request' do
|
139
|
-
settings = {:server => 'http://localhost'}
|
140
|
-
|
141
|
-
it 'works with array instead of Query' do
|
142
|
-
client = PuppetDB::Client.new(settings)
|
143
|
-
|
144
|
-
mock_response = mock()
|
145
|
-
mock_response.expects(:code).returns(200)
|
146
|
-
mock_response.expects(:headers).returns({'X-Records' => 0})
|
147
|
-
mock_response.expects(:parsed_response).returns([])
|
148
|
-
|
149
|
-
PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with() do |path, opts|
|
150
|
-
opts[:query] == {'query' => '[1,2,3]'}
|
151
|
-
end
|
152
|
-
client.request('/foo', [1,2,3])
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'processes options correctly' do
|
156
|
-
client = PuppetDB::Client.new(settings)
|
157
|
-
|
158
|
-
mock_response = mock()
|
159
|
-
mock_response.expects(:code).returns(200)
|
160
|
-
mock_response.expects(:headers).returns({'X-Records' => 0})
|
161
|
-
mock_response.expects(:parsed_response).returns([])
|
162
|
-
|
163
|
-
PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with() do |path, opts|
|
164
|
-
opts == {
|
165
|
-
:query => {
|
166
|
-
'query' => '[1,2,3]',
|
167
|
-
'limit' => 10,
|
168
|
-
'counts-filter' => '[4,5,6]',
|
169
|
-
'foo-bar' => 'foo'
|
170
|
-
}}
|
171
|
-
end
|
172
|
-
|
173
|
-
client.request('/foo', PuppetDB::Query[1,2,3], {
|
174
|
-
:limit => 10,
|
175
|
-
:counts_filter => [4,5,6],
|
176
|
-
:foo_bar => "foo"
|
177
|
-
})
|
178
|
-
end
|
179
|
-
end
|