chef-api 0.7.1 → 0.8.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
- SHA1:
3
- metadata.gz: 1e22717c3690474e0b8d8dc2e49662ae7541c9dd
4
- data.tar.gz: b77f6c57956db9b6b9e06ee677171fa26bf39ced
2
+ SHA256:
3
+ metadata.gz: 2bcf51b085093e35d5a5530be9c9a9cd0cf39f6d1ff91a926ae1cdd769728a47
4
+ data.tar.gz: b625563e99b004213a2d122639cf056a1865ca53d5068b2f935f08595589f12e
5
5
  SHA512:
6
- metadata.gz: 20c1d17608e4670595086eef399b4ee6108f987546f6124c82ffe7e7a3bbd16fce2015bda69e2f860ea4cc1275e07d7ecfd2d88834fb521ebf391dfe230703d8
7
- data.tar.gz: dfa5c1c5a75e2f75c1b7dc6c4e0346774aecd664f6ea4103b8d12dd531338f091628b1ac7e7829a3cea59db5b53266f77f55c145c16cee41adee684e6dd5cd3b
6
+ metadata.gz: abc470931db747708c4f10b42c5481a0648e671f9121468cedad898b6305444f7e4131e8104c6ef49d168bdcb57dee5a36a5e4adc1d5c471627d430530f27d81
7
+ data.tar.gz: 25baa85de8cc2c1145028c83b61bc8cbaf53a9ef994e22676c334befcee145f9c715e52e4f94bc2d8943fdd4b37df83918071a96ab18931557b423715303b161
@@ -2,9 +2,10 @@ sudo: false
2
2
  dist: trusty
3
3
 
4
4
  rvm:
5
- - 2.2.5
6
- - 2.3.1
7
- - 2.4.1
5
+ - 2.2.9
6
+ - 2.3.6
7
+ - 2.4.3
8
+ - 2.5.0
8
9
 
9
10
  # Don't install local development gems on Travis, use parallel gem downloads
10
11
  bundler_args: --without development --jobs 7
@@ -1,5 +1,10 @@
1
1
  # ChefAPI Changelog
2
2
 
3
+ ## v0.8.0 (2018-03-02)
4
+
5
+ - support `filter_result` in chef queries
6
+ - support a configurable read_timeout
7
+
3
8
  ## v0.7.1 (2017-08-06)
4
9
 
5
10
  - Don't set nil `JSON.create_id` as it's unnecessary in recent versions
data/README.md CHANGED
@@ -1,21 +1,18 @@
1
- ChefAPI Client
2
- ==============
3
- [![Gem Version](http://img.shields.io/gem/v/chef-api.svg)][gem]
4
- [![Build Status](http://img.shields.io/travis/sethvargo/chef-api.svg)][travis]
1
+ # ChefAPI Client
5
2
 
6
- [gem]: https://rubygems.org/gems/chef-api
7
- [travis]: http://travis-ci.org/sethvargo/chef-api
3
+ [![Gem Version](http://img.shields.io/gem/v/chef-api.svg)][gem] [![Build Status](http://img.shields.io/travis/sethvargo/chef-api.svg)][travis]
8
4
 
9
5
  **ChefAPI is currently in rapid development!** You should not consider this API stable until the official 1.0.0 release.
10
6
 
11
7
  ChefAPI is a dependency-minimal Ruby client for interacting with a Chef Server. It adopts many patterns and principles from Rails
12
8
 
9
+ ## Quick start
13
10
 
14
- Quick start
15
- -----------
16
11
  Install via Rubygems:
17
12
 
18
- $ gem install chef-api
13
+ ```
14
+ $ gem install chef-api
15
+ ```
19
16
 
20
17
  or add it to your Gemfile if you are using Bundler:
21
18
 
@@ -44,6 +41,7 @@ ChefAPI::Resource::Node.all
44
41
  ```
45
42
 
46
43
  ### Create a connection
44
+
47
45
  Before you can make a request, you must give the ChefAPI your connection information and credentials.
48
46
 
49
47
  ```ruby
@@ -84,6 +82,11 @@ ChefAPI.configure do |config|
84
82
  config.proxy_password = 'password'
85
83
  config.proxy_address = 'my.proxy.server' # or 10.0.0.50
86
84
  config.proxy_port = '8080'
85
+
86
+ # If you want to make queries that return a very large result chef, you might
87
+ # need to adjust the timeout limits for the network request. (NOTE: time is
88
+ # given in seconds).
89
+ config.read_timeout = 120
87
90
  end
88
91
  ```
89
92
 
@@ -140,11 +143,13 @@ end
140
143
  ```
141
144
 
142
145
  ### Making Requests
146
+
143
147
  The ChefAPI gem attempts to wrap the Chef Server API in an object-oriented and Rubyesque way. All of the methods and API calls are heavily documented inline using YARD. For a full list of every possible option, please see the inline documentation.
144
148
 
145
149
  Most resources can be listed, retrieved, created, updated, and destroyed. In programming, this is commonly referred to as "CRUD".
146
150
 
147
151
  #### Create
152
+
148
153
  There are multiple ways to create a new Chef resource on the remote Chef Server. You can use the native `create` method. It accepts a list of parameters as a hash:
149
154
 
150
155
  ```ruby
@@ -169,12 +174,14 @@ client.save #=> #<Resource::Client name: "new-client", admin: false, ...>
169
174
  ```
170
175
 
171
176
  #### Read
177
+
172
178
  Most resources have the following "read" functions:
173
179
 
174
180
  - `.list`, `.all`, and `.each` for listing Chef resources
175
181
  - `.fetch` for getting a single Chef resource with the given identifier
176
182
 
177
183
  ##### Listing
184
+
178
185
  You can get a list of all the identifiers for a given type of resource using the `.list` method. This is especially useful when you only want to list items by their identifier, since it only issues a single API request. For example, to get the names of all of the Client resources:
179
186
 
180
187
  ```ruby
@@ -205,6 +212,7 @@ Client.map(&:public_key) #=> ["-----BEGIN PUBLIC KEY-----\nMIGfMA...", "-----BEG
205
212
  ```
206
213
 
207
214
  ##### Fetching
215
+
208
216
  You can also fetch a single resource from the Chef Server using the given identifier. Each Chef resource has a unique identifier; internally this is called the "primary key". For most resources, this attribute is "name". You can fetch a resource by it's primary key using the `.fetch` method:
209
217
 
210
218
  ```ruby
@@ -218,6 +226,7 @@ Client.fetch('not-a-real-client') #=> nil
218
226
  ```
219
227
 
220
228
  #### Update
229
+
221
230
  You can update a resource using it's unique identifier and a list of hash attributes:
222
231
 
223
232
  ```ruby
@@ -233,6 +242,7 @@ client.save
233
242
  ```
234
243
 
235
244
  #### Delete
245
+
236
246
  You can destroy a resource using it's unique identifier:
237
247
 
238
248
  ```ruby
@@ -247,6 +257,7 @@ client.destroy #=> true
247
257
  ```
248
258
 
249
259
  ### Validations
260
+
250
261
  Each resource includes its own validations. If these validations fail, they exhibit custom errors messages that are added to the resource. For example, Chef clients **must** have a name attribute. This is validated on the client side:
251
262
 
252
263
  ```ruby
@@ -273,15 +284,15 @@ client.save! #=> InvalidResource: There were errors saving your resource: `name'
273
284
  ```
274
285
 
275
286
  ### Objects on Disk
287
+
276
288
  ChefAPI also has the ability to read and manipulate objects on disk. This varies from resource-to-resource, but the `.from_file` method accepts a path to a resource on disk and loads as much information about the object on disk as it can. The attributes are then merged with the remote resource, if one exists. For example, you can read a Client resource from disk:
277
289
 
278
290
  ```ruby
279
291
  client = Client.from_file('~/.chef/bacon.pem') #=> #<Resource::Client name: "bacon", admin: false, public_key: nil, private_key: "..." ...>
280
292
  ```
281
293
 
294
+ ## Searching
282
295
 
283
- Searching
284
- ---------
285
296
  ChefAPI employs both search and partial search functionality.
286
297
 
287
298
  ```ruby
@@ -300,15 +311,13 @@ results.rows.each do |result|
300
311
  end
301
312
  ```
302
313
 
314
+ ## FAQ
303
315
 
304
- FAQ
305
- ---
306
316
  **Q: How is this different than [Ridley](https://github.com/RiotGames/ridley)?**<br>
307
317
  A: Ridley is optimized for highly concurrent connections with support for multiple Chef Servers. ChefAPI is designed for the "average user" who does not need the advanced use cases that Ridley provides. For this reason, the ChefAPI is incredibly opinionated about the features it will include. If you need complex features, take a look at [Ridley](https://github.com/RiotGames/ridley).
308
318
 
319
+ ## Development
309
320
 
310
- Development
311
- -----------
312
321
  1. Clone the project on GitHub
313
322
  2. Create a feature branch
314
323
  3. Submit a Pull Request
@@ -319,10 +328,9 @@ Important Notes:
319
328
  - **The tests must be be idempotent.** The HTTP calls made during a test should be able to be run over and over.
320
329
  - **Tests are order independent.** The default RSpec configuration randomizes the test order, so this should not be a problem.
321
330
 
331
+ ## License & Authors
322
332
 
323
- License & Authors
324
- -----------------
325
- - Author: Seth Vargo <sethvargo@gmail.com>
333
+ - Author: Seth Vargo [sethvargo@gmail.com](mailto:sethvargo@gmail.com)
326
334
 
327
335
  ```text
328
336
  Copyright 2013-2014 Seth Vargo
@@ -339,3 +347,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
339
347
  See the License for the specific language governing permissions and
340
348
  limitations under the License.
341
349
  ```
350
+
351
+ [gem]: https://rubygems.org/gems/chef-api
352
+ [travis]: http://travis-ci.org/sethvargo/chef-api
@@ -23,6 +23,7 @@ module ChefAPI
23
23
  :ssl_pem_file,
24
24
  :ssl_verify,
25
25
  :user_agent,
26
+ :read_timeout,
26
27
  ]
27
28
  end
28
29
  end
@@ -253,6 +253,11 @@ module ChefAPI
253
253
  connection = Net::HTTP.new(uri.host, uri.port,
254
254
  proxy_address, proxy_port, proxy_username, proxy_password)
255
255
 
256
+ # Large or filtered result sets can take a long time to return, so allow
257
+ # setting a longer read_timeout for our client if we want to make an
258
+ # expensive request.
259
+ connection.read_timeout = read_timeout if read_timeout
260
+
256
261
  # Apply SSL, if applicable
257
262
  if uri.scheme == 'https'
258
263
  # Turn on SSL
@@ -181,6 +181,17 @@ module ChefAPI
181
181
  %w[t y].include?(ENV['CHEF_API_SSL_VERIFY'].downcase[0]) || config['CHEF_API_SSL_VERIFY']
182
182
  end
183
183
  end
184
+
185
+ #
186
+ # Network request read timeout in seconds (default: 60)
187
+ #
188
+ # @return [Integer, nil]
189
+ #
190
+ def read_timeout
191
+ timeout_from_env = ENV['CHEF_API_READ_TIMEOUT'] || config['CHEF_API_READ_TIMEOUT']
192
+
193
+ Integer(timeout_from_env) unless timeout_from_env.nil?
194
+ end
184
195
  end
185
196
  end
186
197
  end
@@ -33,7 +33,13 @@ module ChefAPI
33
33
  end
34
34
 
35
35
  path = expanded_collection_path(index: index.to_s)
36
- response = connection.get(path, params)
36
+
37
+ response = if filter_result = options[:filter_result]
38
+ connection.post(path, filter_result.to_json, params)
39
+ else
40
+ connection.get(path, params)
41
+ end
42
+
37
43
  from_json(response, index: index.to_s)
38
44
  end
39
45
  end
@@ -1,3 +1,3 @@
1
1
  module ChefAPI
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.0'
3
3
  end
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.7.1
4
+ version: 0.8.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: 2017-08-06 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logify
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.6.12
147
+ rubygems_version: 2.7.5
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: A Chef API client in Ruby