chef-api 0.2.1 → 0.3.0
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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile +3 -3
- data/README.md +28 -1
- data/lib/chef-api/connection.rb +33 -23
- data/lib/chef-api/resource.rb +2 -0
- data/lib/chef-api/resources/data_bag_item.rb +18 -0
- data/lib/chef-api/resources/partial_search.rb +44 -0
- data/lib/chef-api/resources/search.rb +41 -0
- data/lib/chef-api/version.rb +1 -1
- data/spec/integration/resources/client_spec.rb +4 -4
- data/spec/integration/resources/partial_search_spec.rb +23 -0
- data/spec/integration/resources/search_spec.rb +21 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/chef_server.rb +108 -26
- data/spec/support/shared/chef_api_resource.rb +2 -2
- data/spec/unit/resources/base_spec.rb +2 -2
- data/spec/unit/resources/connection_spec.rb +9 -7
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89bca373e08eb29df75521fe78473fb1a566e9af
|
4
|
+
data.tar.gz: 4565d8fa17cfe68bbe4d204045a5f5d114ff5f92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee5206c83877648adfda095c52d688b46fd1e4a46b7745c8e9cfdf3db8e6ed4f014d353fb91e6dc38549671ff5acaa6632ee6da1edabc0b9aba9dfd77db3c0f1
|
7
|
+
data.tar.gz: 46561de5a2908f9cd2dbe6781de8c67b9b625153aad5a964b532337ea775efef99408176913e9dd6d31d7440ea7c36a74bef53b725fce019f98b412ba8924078
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
ChefAPI Changelog
|
2
2
|
=================
|
3
3
|
|
4
|
+
|
5
|
+
v0.3.0 (2014-06-18)
|
6
|
+
-------------------
|
7
|
+
- Add search functionality
|
8
|
+
- Add partial search
|
9
|
+
- Update testing harness
|
10
|
+
|
11
|
+
|
4
12
|
v0.2.1 (2014-04-17)
|
5
13
|
-------------------
|
6
14
|
- Fix a series of typographical errors
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
ChefAPI Client
|
2
2
|
==============
|
3
|
-
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][gittip]
|
6
|
+
|
7
|
+
[gem]: https://rubygems.org/gems/chef-api
|
8
|
+
[travis]: http://travis-ci.org/sethvargo/chef-api
|
9
|
+
[gittip]: https://www.gittip.com/sethvargo
|
4
10
|
|
5
11
|
**ChefAPI is currently in rapid development!** You should not consider this API stable until the official 1.0.0 release.
|
6
12
|
|
@@ -266,6 +272,27 @@ client = Client.from_file('~/.chef/bacon.pem') #=> #<Resource::Client name: "bac
|
|
266
272
|
```
|
267
273
|
|
268
274
|
|
275
|
+
Searching
|
276
|
+
---------
|
277
|
+
ChefAPI employs both search and partial search functionality.
|
278
|
+
|
279
|
+
```ruby
|
280
|
+
# Using regular search
|
281
|
+
results = Search.query(:node, '*:*', start: 1)
|
282
|
+
results.total #=> 5_000
|
283
|
+
results.rows.each do |result|
|
284
|
+
puts result
|
285
|
+
end
|
286
|
+
|
287
|
+
# Using partial search
|
288
|
+
results = PartialSearch.query(:node, { data: ['fqdn'] }, start: 1)
|
289
|
+
results.total #=> 2
|
290
|
+
results.rows.each do |result|
|
291
|
+
puts result
|
292
|
+
end
|
293
|
+
```
|
294
|
+
|
295
|
+
|
269
296
|
FAQ
|
270
297
|
---
|
271
298
|
**Q: How is this different than [Ridley](https://github.com/RiotGames/ridley)?**<br>
|
data/lib/chef-api/connection.rb
CHANGED
@@ -37,14 +37,16 @@ module ChefAPI
|
|
37
37
|
include Logify
|
38
38
|
include ChefAPI::Configurable
|
39
39
|
|
40
|
-
proxy :clients,
|
41
|
-
proxy :cookbooks,
|
42
|
-
proxy :data_bags,
|
43
|
-
proxy :environments,
|
44
|
-
proxy :nodes,
|
45
|
-
proxy :
|
46
|
-
proxy :
|
47
|
-
proxy :
|
40
|
+
proxy :clients, 'Resource::Client'
|
41
|
+
proxy :cookbooks, 'Resource::Cookbook'
|
42
|
+
proxy :data_bags, 'Resource::DataBag'
|
43
|
+
proxy :environments, 'Resource::Environment'
|
44
|
+
proxy :nodes, 'Resource::Node'
|
45
|
+
proxy :partial_search, 'Resource::PartialSearch'
|
46
|
+
proxy :principals, 'Resource::Principal'
|
47
|
+
proxy :roles, 'Resource::Role'
|
48
|
+
proxy :search, 'Resource::Search'
|
49
|
+
proxy :users, 'Resource::User'
|
48
50
|
|
49
51
|
#
|
50
52
|
# Create a new ChefAPI Connection with the given options. Any options
|
@@ -110,12 +112,14 @@ module ChefAPI
|
|
110
112
|
# @param path (see Connection#request)
|
111
113
|
# @param [String, #read] data
|
112
114
|
# the body to use for the request
|
115
|
+
# @param [Hash] params
|
116
|
+
# the list of query params
|
113
117
|
#
|
114
118
|
# @raise (see Connection#request)
|
115
119
|
# @return (see Connection#request)
|
116
120
|
#
|
117
|
-
def post(path, data)
|
118
|
-
request(:post, path, data)
|
121
|
+
def post(path, data, params = {})
|
122
|
+
request(:post, path, data, params)
|
119
123
|
end
|
120
124
|
|
121
125
|
#
|
@@ -123,12 +127,13 @@ module ChefAPI
|
|
123
127
|
#
|
124
128
|
# @param path (see Connection#request)
|
125
129
|
# @param data (see Connection#post)
|
130
|
+
# @param params (see Connection#post)
|
126
131
|
#
|
127
132
|
# @raise (see Connection#request)
|
128
133
|
# @return (see Connection#request)
|
129
134
|
#
|
130
|
-
def put(path, data)
|
131
|
-
request(:put, path, data)
|
135
|
+
def put(path, data, params = {})
|
136
|
+
request(:put, path, data, params)
|
132
137
|
end
|
133
138
|
|
134
139
|
#
|
@@ -136,12 +141,13 @@ module ChefAPI
|
|
136
141
|
#
|
137
142
|
# @param path (see Connection#request)
|
138
143
|
# @param data (see Connection#post)
|
144
|
+
# @param params (see Connection#post)
|
139
145
|
#
|
140
146
|
# @raise (see Connection#request)
|
141
147
|
# @return (see Connection#request)
|
142
148
|
#
|
143
|
-
def patch(path, data)
|
144
|
-
request(:patch, path, data)
|
149
|
+
def patch(path, data, params = {})
|
150
|
+
request(:patch, path, data, params)
|
145
151
|
end
|
146
152
|
|
147
153
|
#
|
@@ -172,16 +178,22 @@ module ChefAPI
|
|
172
178
|
# request against
|
173
179
|
# @param [#read, Hash, nil] data
|
174
180
|
# the data to use (varies based on the +verb+)
|
181
|
+
# @param [Hash] params
|
182
|
+
# the params to use for :patch, :post, :put
|
175
183
|
#
|
176
184
|
# @return [String, Hash]
|
177
185
|
# the response body
|
178
186
|
#
|
179
|
-
def request(verb, path, data = {})
|
187
|
+
def request(verb, path, data = {}, params = {})
|
180
188
|
log.info "#{verb.to_s.upcase} #{path}..."
|
181
189
|
log.debug "Chef flavor: #{flavor.inspect}"
|
182
190
|
|
183
191
|
# Build the URI and request object from the given information
|
184
|
-
|
192
|
+
if [:delete, :get].include?(verb)
|
193
|
+
uri = build_uri(verb, path, data)
|
194
|
+
else
|
195
|
+
uri = build_uri(verb, path, params)
|
196
|
+
end
|
185
197
|
request = class_for_request(verb).new(uri.request_uri)
|
186
198
|
|
187
199
|
# Add request headers
|
@@ -278,13 +290,11 @@ module ChefAPI
|
|
278
290
|
log.info "Building URI..."
|
279
291
|
|
280
292
|
# Add any query string parameters
|
281
|
-
if
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
path = [path, querystring].compact.join('?')
|
287
|
-
end
|
293
|
+
if querystring = to_query_string(params)
|
294
|
+
log.debug "Detected verb deserves a querystring"
|
295
|
+
log.debug "Building querystring using #{params.inspect}"
|
296
|
+
log.debug "Compiled querystring is #{querystring.inspect}"
|
297
|
+
path = [path, querystring].compact.join('?')
|
288
298
|
end
|
289
299
|
|
290
300
|
# Parse the URI
|
data/lib/chef-api/resource.rb
CHANGED
@@ -10,8 +10,10 @@ module ChefAPI
|
|
10
10
|
autoload :Environment, 'chef-api/resources/environment'
|
11
11
|
autoload :Node, 'chef-api/resources/node'
|
12
12
|
autoload :Organization, 'chef-api/resources/organization'
|
13
|
+
autoload :PartialSearch, 'chef-api/resources/partial_search'
|
13
14
|
autoload :Principal, 'chef-api/resources/principal'
|
14
15
|
autoload :Role, 'chef-api/resources/role'
|
16
|
+
autoload :Search, 'chef-api/resources/search'
|
15
17
|
autoload :User, 'chef-api/resources/user'
|
16
18
|
end
|
17
19
|
end
|
@@ -31,5 +31,23 @@ module ChefAPI
|
|
31
31
|
id = attributes.delete(:id) || attributes.delete('id')
|
32
32
|
super({ id: id, data: attributes }, prefix)
|
33
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
#
|
37
|
+
# Override the to_hash method to move data to the upper scope.
|
38
|
+
#
|
39
|
+
# @see (Resource::Base#to_hash)
|
40
|
+
#
|
41
|
+
def to_hash
|
42
|
+
{}.tap do |hash|
|
43
|
+
_attributes.each do |key, value|
|
44
|
+
if key == :data
|
45
|
+
hash.merge!(value)
|
46
|
+
else
|
47
|
+
hash[key] = value.respond_to?(:to_hash) ? value.to_hash : value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
34
52
|
end
|
35
53
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
class Resource::PartialSearch < Resource::Base
|
3
|
+
collection_path '/search/:index'
|
4
|
+
|
5
|
+
schema do
|
6
|
+
attribute :total, type: Integer
|
7
|
+
attribute :start, type: Integer
|
8
|
+
attribute :rows, type: Array
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
#
|
13
|
+
# About search : http://docs.opscode.com/essentials_search.html
|
14
|
+
#
|
15
|
+
# @param [String] index
|
16
|
+
# the name of the index to search
|
17
|
+
# @param [Hash] keys
|
18
|
+
# key paths for the attributes to be returned
|
19
|
+
# @param [String] query
|
20
|
+
# the query string
|
21
|
+
# @param [Hash] options
|
22
|
+
# the query string
|
23
|
+
#
|
24
|
+
# @return [self]
|
25
|
+
# the current resource
|
26
|
+
#
|
27
|
+
def query(index, keys, query = '*:*', options = {})
|
28
|
+
return nil if index.nil?
|
29
|
+
|
30
|
+
params = {}.tap do |o|
|
31
|
+
o[:q] = query
|
32
|
+
o[:rows] = options[:rows] || 1000
|
33
|
+
o[:sort] = options[:sort] || 'X_CHEF_id_CHEF_X'
|
34
|
+
o[:start] = options[:start] || 0
|
35
|
+
end
|
36
|
+
|
37
|
+
path = expanded_collection_path(index: index.to_s)
|
38
|
+
response = connection.post(path, keys.to_json, params)
|
39
|
+
response['rows'].map! { |row| row['data'] }
|
40
|
+
from_json(response, index: index.to_s)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
class Resource::Search < Resource::Base
|
3
|
+
collection_path '/search/:index'
|
4
|
+
|
5
|
+
schema do
|
6
|
+
attribute :total, type: Integer
|
7
|
+
attribute :start, type: Integer
|
8
|
+
attribute :rows, type: Array
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
#
|
13
|
+
# About search : http://docs.opscode.com/essentials_search.html
|
14
|
+
#
|
15
|
+
# @param [String] index
|
16
|
+
# the name of the index to search
|
17
|
+
# @param [String] query
|
18
|
+
# the query string
|
19
|
+
# @param [Hash] options
|
20
|
+
# the query string
|
21
|
+
#
|
22
|
+
# @return [self]
|
23
|
+
# the current resource
|
24
|
+
#
|
25
|
+
def query(index, query = '*:*', options = {})
|
26
|
+
return nil if index.nil?
|
27
|
+
|
28
|
+
params = {}.tap do |o|
|
29
|
+
o[:q] = query
|
30
|
+
o[:rows] = options[:rows] || 1000
|
31
|
+
o[:sort] = options[:sort] || 'X_CHEF_id_CHEF_X'
|
32
|
+
o[:start] = options[:start] || 0
|
33
|
+
end
|
34
|
+
|
35
|
+
path = expanded_collection_path(index: index.to_s)
|
36
|
+
response = connection.get(path, params)
|
37
|
+
from_json(response, index: index.to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/chef-api/version.rb
CHANGED
@@ -41,7 +41,7 @@ module ChefAPI
|
|
41
41
|
let(:client) { described_class.from_file('/path/to/bacon.pem') }
|
42
42
|
|
43
43
|
before do
|
44
|
-
File.
|
44
|
+
allow(File).to receive(:read).and_return(private_key)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'loads the client from the server' do
|
@@ -49,13 +49,13 @@ module ChefAPI
|
|
49
49
|
|
50
50
|
expect(client.name).to eq('bacon')
|
51
51
|
expect(client.private_key).to eq(private_key)
|
52
|
-
expect(client.validator).to
|
52
|
+
expect(client.validator).to be_truthy
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'creates a new instance when the client does not exist' do
|
56
56
|
expect(client.name).to eq('bacon')
|
57
|
-
expect(client.validator).to
|
58
|
-
expect(client.new_resource?).to
|
57
|
+
expect(client.validator).to be_falsey
|
58
|
+
expect(client.new_resource?).to be_truthy
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ChefAPI
|
4
|
+
describe Resource::PartialSearch do
|
5
|
+
describe '.query' do
|
6
|
+
it 'returns a partial search resource' do
|
7
|
+
chef_server.send('create_client', 'bacon')
|
8
|
+
results = described_class.query(:client, { name: ['name'] })
|
9
|
+
expect(results).to be_a(described_class)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns partial data' do
|
13
|
+
chef_server.send('create_node', 'bacon1', { foo: :bar })
|
14
|
+
chef_server.send('create_node', 'bacon2', { foo: :baz, bar: :foo })
|
15
|
+
keys = { data: ['bar'] }
|
16
|
+
results = described_class.query(:node, keys, '*:*', start: 1)
|
17
|
+
expect(results.total).to be == 2
|
18
|
+
expect(results.rows.size).to be == 1
|
19
|
+
expect(results.rows.first).to be == { 'data' => 'foo' }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ChefAPI
|
4
|
+
describe Resource::Search do
|
5
|
+
describe '.query' do
|
6
|
+
it 'returns a search resource' do
|
7
|
+
chef_server.send('create_client', 'bacon')
|
8
|
+
results = described_class.query(:client)
|
9
|
+
expect(results).to be_a(described_class)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'options are passed to the chef-server' do
|
13
|
+
chef_server.send('create_node', 'bacon1', { foo: :bar })
|
14
|
+
chef_server.send('create_node', 'bacon2', { foo: :baz })
|
15
|
+
results = described_class.query(:node, '*:*', start: 1)
|
16
|
+
expect(results.total).to be == 2
|
17
|
+
expect(results.rows.size).to be == 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,6 @@ RSpec.configure do |config|
|
|
9
9
|
Dir[ChefAPI.root.join('spec/support/shared/**/*.rb')].each { |file| require file }
|
10
10
|
|
11
11
|
# Basic configuraiton
|
12
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
12
|
config.run_all_when_everything_filtered = true
|
14
13
|
config.filter_run(:focus)
|
15
14
|
|
data/spec/support/chef_server.rb
CHANGED
@@ -9,11 +9,94 @@ module RSpec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class << self
|
12
|
+
#
|
13
|
+
# Delegate all methods to the singleton instance.
|
14
|
+
#
|
12
15
|
def method_missing(m, *args, &block)
|
13
16
|
instance.send(m, *args, &block)
|
14
17
|
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# RSpec 3 checks +respond_to?+
|
21
|
+
#
|
22
|
+
def respond_to_missing?(m, include_private = false)
|
23
|
+
instance.respond_to?(m, include_private) || super
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# @macro entity
|
28
|
+
# @method create_$1(name, data = {})
|
29
|
+
# Create a new $1 on the Chef Server
|
30
|
+
#
|
31
|
+
# @param [String] name
|
32
|
+
# the name of the $1
|
33
|
+
# @param [Hash] data
|
34
|
+
# the list of data to load
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# @method $1(name)
|
38
|
+
# Find a $1 at the given name
|
39
|
+
#
|
40
|
+
# @param [String] name
|
41
|
+
# the name of the $1
|
42
|
+
#
|
43
|
+
# @return [$2, nil]
|
44
|
+
#
|
45
|
+
#
|
46
|
+
# @method $3
|
47
|
+
# The list of $1 on the Chef Server
|
48
|
+
#
|
49
|
+
# @return [Array<Hash>]
|
50
|
+
# all the $1 on the Chef Server
|
51
|
+
#
|
52
|
+
#
|
53
|
+
# @method has_$1?(name)
|
54
|
+
# Determine if the Chef Server has the given $1
|
55
|
+
#
|
56
|
+
# @param [String] name
|
57
|
+
# the name of the $1 to find
|
58
|
+
#
|
59
|
+
# @return [Boolean]
|
60
|
+
#
|
61
|
+
def entity(method, key)
|
62
|
+
class_eval <<-EOH, __FILE__, __LINE__ + 1
|
63
|
+
def create_#{method}(name, data = {})
|
64
|
+
# Automatically set the "name" if no explicit one was given
|
65
|
+
data[:name] ||= name
|
66
|
+
|
67
|
+
# Convert it to JSON
|
68
|
+
data = JSON.fast_generate(data)
|
69
|
+
|
70
|
+
load_data(name, '#{key}', data)
|
71
|
+
end
|
72
|
+
|
73
|
+
def #{method}(name)
|
74
|
+
data = get('#{key}', name)
|
75
|
+
JSON.parse(data)
|
76
|
+
rescue ChefZero::DataStore::DataNotFoundError
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def #{key}
|
81
|
+
get('#{key}')
|
82
|
+
end
|
83
|
+
|
84
|
+
def has_#{method}?(name)
|
85
|
+
!get('#{key}', name).nil?
|
86
|
+
rescue ChefZero::DataStore::DataNotFoundError
|
87
|
+
false
|
88
|
+
end
|
89
|
+
EOH
|
90
|
+
end
|
15
91
|
end
|
16
92
|
|
93
|
+
entity :client, :clients
|
94
|
+
entity :data_bag, :data
|
95
|
+
entity :environment, :environments
|
96
|
+
entity :node, :nodes
|
97
|
+
entity :role, :roles
|
98
|
+
entity :user, :users
|
99
|
+
|
17
100
|
require 'singleton'
|
18
101
|
include Singleton
|
19
102
|
|
@@ -22,8 +105,16 @@ module RSpec
|
|
22
105
|
#
|
23
106
|
def initialize
|
24
107
|
@server = ChefZero::Server.new({
|
108
|
+
# This uses a random port
|
25
109
|
port: port,
|
110
|
+
|
111
|
+
# Shut up
|
26
112
|
log_level: :fatal,
|
113
|
+
|
114
|
+
# Disable the "old" way - this is actually +multi_tenant: true+
|
115
|
+
single_org: false,
|
116
|
+
|
117
|
+
# Don't generate real keys for faster test
|
27
118
|
generate_real_keys: false,
|
28
119
|
})
|
29
120
|
|
@@ -55,38 +146,29 @@ module RSpec
|
|
55
146
|
end
|
56
147
|
|
57
148
|
#
|
149
|
+
# Get the path to an item in the data store.
|
58
150
|
#
|
59
|
-
|
60
|
-
|
61
|
-
|
151
|
+
def get(*args)
|
152
|
+
if args.size == 1
|
153
|
+
@server.data_store.list(args)
|
154
|
+
else
|
155
|
+
@server.data_store.get(args)
|
156
|
+
end
|
62
157
|
end
|
63
158
|
|
64
159
|
#
|
160
|
+
# Shortcut method for loading data into Chef Zero.
|
65
161
|
#
|
162
|
+
# @param [String] name
|
163
|
+
# the name or id of the item to load
|
164
|
+
# @param [String, Symbol] key
|
165
|
+
# the key to load
|
166
|
+
# @param [Hash] data
|
167
|
+
# the data for the object, which will be converted to JSON and uploaded
|
168
|
+
# to the server
|
66
169
|
#
|
67
|
-
|
68
|
-
|
69
|
-
['cookbooks', 'cookbook'],
|
70
|
-
['environments', 'environment'],
|
71
|
-
['nodes', 'node'],
|
72
|
-
['roles', 'role'],
|
73
|
-
['users', 'user'],
|
74
|
-
].each do |plural, singular|
|
75
|
-
define_method(plural) do
|
76
|
-
@server.data_store.list([plural])
|
77
|
-
end
|
78
|
-
|
79
|
-
define_method(singular) do |id|
|
80
|
-
JSON.parse(@server.data_store.get([plural, id]))
|
81
|
-
end
|
82
|
-
|
83
|
-
define_method("create_#{singular}") do |id, data = {}|
|
84
|
-
load_data(plural, id, data)
|
85
|
-
end
|
86
|
-
|
87
|
-
define_method("has_#{singular}?") do |id|
|
88
|
-
send(plural).include?(id)
|
89
|
-
end
|
170
|
+
def load_data(name, key, data = {})
|
171
|
+
@server.load_data({ key => { name => data } })
|
90
172
|
end
|
91
173
|
|
92
174
|
private
|
@@ -40,12 +40,12 @@ shared_examples_for 'a Chef API resource' do |type, options = {}|
|
|
40
40
|
|
41
41
|
describe '.exists?' do
|
42
42
|
it 'returns false when the resource does not exist' do
|
43
|
-
expect(described_class.exists?(resource_id)).to
|
43
|
+
expect(described_class.exists?(resource_id)).to be_falsey
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'returns true when the resource exists' do
|
47
47
|
chef_server.send("create_#{type}", resource_id)
|
48
|
-
expect(described_class.exists?(resource_id)).to
|
48
|
+
expect(described_class.exists?(resource_id)).to be_truthy
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -36,8 +36,8 @@ module ChefAPI
|
|
36
36
|
|
37
37
|
describe '.build' do
|
38
38
|
it 'creates a new instance' do
|
39
|
-
described_class.
|
40
|
-
described_class.
|
39
|
+
allow(described_class).to receive(:new)
|
40
|
+
allow(described_class).to receive(:schema).and_return(double(attributes: {}))
|
41
41
|
|
42
42
|
expect(described_class).to receive(:new).with({foo: 'bar'}, {})
|
43
43
|
described_class.build(foo: 'bar')
|
@@ -18,13 +18,15 @@ module ChefAPI
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it_behaves_like 'a proxy for', :clients,
|
22
|
-
it_behaves_like 'a proxy for', :data_bags,
|
23
|
-
it_behaves_like 'a proxy for', :environments,
|
24
|
-
it_behaves_like 'a proxy for', :nodes,
|
25
|
-
it_behaves_like 'a proxy for', :
|
26
|
-
it_behaves_like 'a proxy for', :
|
27
|
-
it_behaves_like 'a proxy for', :
|
21
|
+
it_behaves_like 'a proxy for', :clients, 'Resource::Client'
|
22
|
+
it_behaves_like 'a proxy for', :data_bags, 'Resource::DataBag'
|
23
|
+
it_behaves_like 'a proxy for', :environments, 'Resource::Environment'
|
24
|
+
it_behaves_like 'a proxy for', :nodes, 'Resource::Node'
|
25
|
+
it_behaves_like 'a proxy for', :partial_search, 'Resource::PartialSearch'
|
26
|
+
it_behaves_like 'a proxy for', :principals, 'Resource::Principal'
|
27
|
+
it_behaves_like 'a proxy for', :roles, 'Resource::Role'
|
28
|
+
it_behaves_like 'a proxy for', :search, 'Resource::Search'
|
29
|
+
it_behaves_like 'a proxy for', :users, 'Resource::User'
|
28
30
|
|
29
31
|
context '#initialize' do
|
30
32
|
context 'when options are given' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logify
|
@@ -71,8 +71,10 @@ files:
|
|
71
71
|
- lib/chef-api/resources/environment.rb
|
72
72
|
- lib/chef-api/resources/node.rb
|
73
73
|
- lib/chef-api/resources/organization.rb
|
74
|
+
- lib/chef-api/resources/partial_search.rb
|
74
75
|
- lib/chef-api/resources/principal.rb
|
75
76
|
- lib/chef-api/resources/role.rb
|
77
|
+
- lib/chef-api/resources/search.rb
|
76
78
|
- lib/chef-api/resources/user.rb
|
77
79
|
- lib/chef-api/schema.rb
|
78
80
|
- lib/chef-api/util.rb
|
@@ -84,7 +86,9 @@ files:
|
|
84
86
|
- spec/integration/resources/client_spec.rb
|
85
87
|
- spec/integration/resources/environment_spec.rb
|
86
88
|
- spec/integration/resources/node_spec.rb
|
89
|
+
- spec/integration/resources/partial_search_spec.rb
|
87
90
|
- spec/integration/resources/role_spec.rb
|
91
|
+
- spec/integration/resources/search_spec.rb
|
88
92
|
- spec/integration/resources/user_spec.rb
|
89
93
|
- spec/spec_helper.rb
|
90
94
|
- spec/support/chef_server.rb
|
@@ -142,7 +146,9 @@ test_files:
|
|
142
146
|
- spec/integration/resources/client_spec.rb
|
143
147
|
- spec/integration/resources/environment_spec.rb
|
144
148
|
- spec/integration/resources/node_spec.rb
|
149
|
+
- spec/integration/resources/partial_search_spec.rb
|
145
150
|
- spec/integration/resources/role_spec.rb
|
151
|
+
- spec/integration/resources/search_spec.rb
|
146
152
|
- spec/integration/resources/user_spec.rb
|
147
153
|
- spec/spec_helper.rb
|
148
154
|
- spec/support/chef_server.rb
|