chef-api 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef-api/version.rb +1 -1
  3. metadata +6 -70
  4. data/.gitignore +0 -21
  5. data/.travis.yml +0 -18
  6. data/CHANGELOG.md +0 -63
  7. data/Gemfile +0 -12
  8. data/README.md +0 -352
  9. data/Rakefile +0 -11
  10. data/chef-api.gemspec +0 -25
  11. data/spec/integration/resources/client_spec.rb +0 -62
  12. data/spec/integration/resources/environment_spec.rb +0 -8
  13. data/spec/integration/resources/node_spec.rb +0 -8
  14. data/spec/integration/resources/partial_search_spec.rb +0 -23
  15. data/spec/integration/resources/role_spec.rb +0 -8
  16. data/spec/integration/resources/search_spec.rb +0 -21
  17. data/spec/integration/resources/user_spec.rb +0 -8
  18. data/spec/spec_helper.rb +0 -32
  19. data/spec/support/chef_server.rb +0 -198
  20. data/spec/support/cookbook.tar.gz +0 -0
  21. data/spec/support/shared/chef_api_resource.rb +0 -91
  22. data/spec/support/user.pem +0 -27
  23. data/spec/unit/authentication_spec.rb +0 -70
  24. data/spec/unit/defaults_spec.rb +0 -60
  25. data/spec/unit/errors_spec.rb +0 -294
  26. data/spec/unit/resources/base_spec.rb +0 -49
  27. data/spec/unit/resources/client_spec.rb +0 -53
  28. data/spec/unit/resources/connection_spec.rb +0 -53
  29. data/templates/errors/abstract_method.erb +0 -5
  30. data/templates/errors/cannot_regenerate_key.erb +0 -1
  31. data/templates/errors/chef_api_error.erb +0 -1
  32. data/templates/errors/file_not_found.erb +0 -1
  33. data/templates/errors/http_bad_request.erb +0 -3
  34. data/templates/errors/http_forbidden_request.erb +0 -3
  35. data/templates/errors/http_gateway_timeout.erb +0 -3
  36. data/templates/errors/http_method_not_allowed.erb +0 -3
  37. data/templates/errors/http_not_acceptable.erb +0 -3
  38. data/templates/errors/http_not_found.erb +0 -3
  39. data/templates/errors/http_server_unavailable.erb +0 -1
  40. data/templates/errors/http_unauthorized_request.erb +0 -3
  41. data/templates/errors/insufficient_file_permissions.erb +0 -1
  42. data/templates/errors/invalid_resource.erb +0 -1
  43. data/templates/errors/invalid_validator.erb +0 -1
  44. data/templates/errors/missing_url_parameter.erb +0 -1
  45. data/templates/errors/not_a_directory.erb +0 -1
  46. data/templates/errors/resource_already_exists.erb +0 -1
  47. data/templates/errors/resource_not_found.erb +0 -1
  48. data/templates/errors/resource_not_mutable.erb +0 -1
  49. data/templates/errors/unknown_attribute.erb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bcf51b085093e35d5a5530be9c9a9cd0cf39f6d1ff91a926ae1cdd769728a47
4
- data.tar.gz: b625563e99b004213a2d122639cf056a1865ca53d5068b2f935f08595589f12e
3
+ metadata.gz: ee8604bcf5bcfe321caabd69eaf49850a1cb3a2a2e64f4ba3f1f9f19dbe23b70
4
+ data.tar.gz: 792c8bf1f685f45317e80b13b389fd5898e57db767f447bacc5bf5711a47d3af
5
5
  SHA512:
6
- metadata.gz: abc470931db747708c4f10b42c5481a0648e671f9121468cedad898b6305444f7e4131e8104c6ef49d168bdcb57dee5a36a5e4adc1d5c471627d430530f27d81
7
- data.tar.gz: 25baa85de8cc2c1145028c83b61bc8cbaf53a9ef994e22676c334befcee145f9c715e52e4f94bc2d8943fdd4b37df83918071a96ab18931557b423715303b161
6
+ metadata.gz: e0ec7e3b00bbfee5ccb9774803f1db57b8c326e0ba4f63d61e4dceebadd921ff6281f560873ef4a31372e0158fdda4173b0380162e16014171bbf817eaf6d7db
7
+ data.tar.gz: a346455a325f6454efd34a6b4fe370e8f37734886e8ad85f00118cc67467c0d473a3140b87d1ca86f2fa9c003159679b5debd5a3527a6e8fdb9ab65d89a7e8ba
@@ -1,3 +1,3 @@
1
1
  module ChefAPI
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.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.8.0
4
+ version: 0.9.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: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logify
@@ -45,14 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".gitignore"
49
- - ".travis.yml"
50
- - CHANGELOG.md
51
- - Gemfile
52
48
  - LICENSE
53
- - README.md
54
- - Rakefile
55
- - chef-api.gemspec
56
49
  - lib/chef-api.rb
57
50
  - lib/chef-api/authentication.rb
58
51
  - lib/chef-api/boolean.rb
@@ -85,48 +78,9 @@ files:
85
78
  - lib/chef-api/validators/required.rb
86
79
  - lib/chef-api/validators/type.rb
87
80
  - lib/chef-api/version.rb
88
- - spec/integration/resources/client_spec.rb
89
- - spec/integration/resources/environment_spec.rb
90
- - spec/integration/resources/node_spec.rb
91
- - spec/integration/resources/partial_search_spec.rb
92
- - spec/integration/resources/role_spec.rb
93
- - spec/integration/resources/search_spec.rb
94
- - spec/integration/resources/user_spec.rb
95
- - spec/spec_helper.rb
96
- - spec/support/chef_server.rb
97
- - spec/support/cookbook.tar.gz
98
- - spec/support/shared/chef_api_resource.rb
99
- - spec/support/user.pem
100
- - spec/unit/authentication_spec.rb
101
- - spec/unit/defaults_spec.rb
102
- - spec/unit/errors_spec.rb
103
- - spec/unit/resources/base_spec.rb
104
- - spec/unit/resources/client_spec.rb
105
- - spec/unit/resources/connection_spec.rb
106
- - templates/errors/abstract_method.erb
107
- - templates/errors/cannot_regenerate_key.erb
108
- - templates/errors/chef_api_error.erb
109
- - templates/errors/file_not_found.erb
110
- - templates/errors/http_bad_request.erb
111
- - templates/errors/http_forbidden_request.erb
112
- - templates/errors/http_gateway_timeout.erb
113
- - templates/errors/http_method_not_allowed.erb
114
- - templates/errors/http_not_acceptable.erb
115
- - templates/errors/http_not_found.erb
116
- - templates/errors/http_server_unavailable.erb
117
- - templates/errors/http_unauthorized_request.erb
118
- - templates/errors/insufficient_file_permissions.erb
119
- - templates/errors/invalid_resource.erb
120
- - templates/errors/invalid_validator.erb
121
- - templates/errors/missing_url_parameter.erb
122
- - templates/errors/not_a_directory.erb
123
- - templates/errors/resource_already_exists.erb
124
- - templates/errors/resource_not_found.erb
125
- - templates/errors/resource_not_mutable.erb
126
- - templates/errors/unknown_attribute.erb
127
81
  homepage: https://github.com/sethvargo/chef-api
128
82
  licenses:
129
- - Apache 2.0
83
+ - Apache-2.0
130
84
  metadata: {}
131
85
  post_install_message:
132
86
  rdoc_options: []
@@ -136,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
90
  requirements:
137
91
  - - ">="
138
92
  - !ruby/object:Gem::Version
139
- version: '2.1'
93
+ version: '2.2'
140
94
  required_rubygems_version: !ruby/object:Gem::Requirement
141
95
  requirements:
142
96
  - - ">="
@@ -144,26 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
98
  version: '0'
145
99
  requirements: []
146
100
  rubyforge_project:
147
- rubygems_version: 2.7.5
101
+ rubygems_version: 2.7.8
148
102
  signing_key:
149
103
  specification_version: 4
150
104
  summary: A Chef API client in Ruby
151
- test_files:
152
- - spec/integration/resources/client_spec.rb
153
- - spec/integration/resources/environment_spec.rb
154
- - spec/integration/resources/node_spec.rb
155
- - spec/integration/resources/partial_search_spec.rb
156
- - spec/integration/resources/role_spec.rb
157
- - spec/integration/resources/search_spec.rb
158
- - spec/integration/resources/user_spec.rb
159
- - spec/spec_helper.rb
160
- - spec/support/chef_server.rb
161
- - spec/support/cookbook.tar.gz
162
- - spec/support/shared/chef_api_resource.rb
163
- - spec/support/user.pem
164
- - spec/unit/authentication_spec.rb
165
- - spec/unit/defaults_spec.rb
166
- - spec/unit/errors_spec.rb
167
- - spec/unit/resources/base_spec.rb
168
- - spec/unit/resources/client_spec.rb
169
- - spec/unit/resources/connection_spec.rb
105
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- bin
19
- .rspec
20
- .ruby-version
21
- vendor/
@@ -1,18 +0,0 @@
1
- sudo: false
2
- dist: trusty
3
-
4
- rvm:
5
- - 2.2.9
6
- - 2.3.6
7
- - 2.4.3
8
- - 2.5.0
9
-
10
- # Don't install local development gems on Travis, use parallel gem downloads
11
- bundler_args: --without development --jobs 7
12
-
13
- # Only test master
14
- branches:
15
- only:
16
- - master
17
-
18
- script: bundle exec rake
@@ -1,63 +0,0 @@
1
- # ChefAPI Changelog
2
-
3
- ## v0.8.0 (2018-03-02)
4
-
5
- - support `filter_result` in chef queries
6
- - support a configurable read_timeout
7
-
8
- ## v0.7.1 (2017-08-06)
9
-
10
- - Don't set nil `JSON.create_id` as it's unnecessary in recent versions
11
- of the JSON library
12
- - Avoid ArgumentError when no HOME environment variable is set
13
- - Add Resource::Organization proxy
14
- - Update all comments to point to the correct Docs site URLs
15
-
16
- ## v0.6.0 (2016-05-05)
17
-
18
- - Remove support for Ruby 1.9
19
- - Add the ability to disable signing on a request
20
- - Always send JSON when authenticating a user
21
- - Fix to_json method contract
22
- - Add config file support. See the readme for an example
23
- - Add required fields to role schema
24
- - Do not symbolize keys in the config
25
- - Fix boolean logic in determining if SSL should be verified
26
-
27
- ## v0.5.0 (2014-07-10)
28
-
29
- - Relax the dependency on mime-types
30
- - When searching for the file object of a multipart filepart, find the first IO that not a StringIO
31
- - Rewind IO objects after digesting them
32
-
33
- ## v0.4.1 (2014-07-07)
34
-
35
- - Remove dependency on mixlib-authentication
36
- - Fix a bug where Content-Type headers were not sent properly
37
- - Switch to rake for test running
38
- - Improve test coverage with fixtures
39
-
40
- ## v0.4.0 (2014-07-05)
41
-
42
- - Support multipart POST
43
-
44
- ## v0.3.0 (2014-06-18)
45
-
46
- - Add search functionality
47
- - Add partial search
48
- - Update testing harness
49
-
50
- ## v0.2.1 (2014-04-17)
51
-
52
- - Fix a series of typographical errors
53
- - Improved documentation for loading resources from disk
54
- - Improved spec coverage
55
- - Switch to Logify for logging
56
- - Add HEC endpoint for authenticating users
57
- - Change the default options for Hosted Chef
58
- - Implement HTTPGatewayTimeout (504)
59
- - Do not automatically inflate JSON objects
60
- - Improved logging awesomeness
61
- - Add "flavors" when defining the schema (OSC is different than HEC)
62
- - Remove i18n in favor of ERB
63
- - Fix an issue when providing a key at an unexpanded path
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- group :development do
5
- gem 'pry'
6
- end
7
-
8
- group :test do
9
- gem 'chef-zero', '~> 2.0.0'
10
- gem 'rake'
11
- gem 'rspec', '~> 3.0'
12
- end
data/README.md DELETED
@@ -1,352 +0,0 @@
1
- # ChefAPI Client
2
-
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]
4
-
5
- **ChefAPI is currently in rapid development!** You should not consider this API stable until the official 1.0.0 release.
6
-
7
- ChefAPI is a dependency-minimal Ruby client for interacting with a Chef Server. It adopts many patterns and principles from Rails
8
-
9
- ## Quick start
10
-
11
- Install via Rubygems:
12
-
13
- ```
14
- $ gem install chef-api
15
- ```
16
-
17
- or add it to your Gemfile if you are using Bundler:
18
-
19
- ```ruby
20
- gem 'chef-api', '~> 0.1'
21
- ```
22
-
23
- In your library or project, you will likely want to include the `ChefAPI::Resource` namespace:
24
-
25
- ```ruby
26
- include ChefAPI::Resource
27
- ```
28
-
29
- This will give you "Rails-like" access to the top-level Chef resources like:
30
-
31
- ```ruby
32
- Client.all
33
- Node.all
34
- ```
35
-
36
- If you choose not to include the module, you will need to specify the full module path to access resources:
37
-
38
- ```ruby
39
- ChefAPI::Resource::Client.all
40
- ChefAPI::Resource::Node.all
41
- ```
42
-
43
- ### Create a connection
44
-
45
- Before you can make a request, you must give the ChefAPI your connection information and credentials.
46
-
47
- ```ruby
48
- ChefAPI.configure do |config|
49
- # The endpoint for the Chef Server. This can be an Open Source Chef Server,
50
- # Hosted Chef Server, or Enterprise Chef Server.
51
- config.endpoint = 'https://api.opscode.com/organizations/meats'
52
-
53
- # ChefAPI will try to determine if you are running on an Enterprise Chef
54
- # Server or Open Source Chef depending on the URL you provide for the
55
- # +endpoint+ attribute. However, it may be incorrect. If is seems like the
56
- # generated schema does not match the response from the server, it is
57
- # possible this value was calculated incorrectly. Thus, you should set it
58
- # manually. Possible values are +:enterprise+ and +:open_source+.
59
- config.flavor = :enterprise
60
-
61
- # The client and key must also be specified (unless you are running Chef Zero
62
- # in no-authentication mode). The +key+ attribute may be the raw private key,
63
- # the path to the private key on disk, or an +OpenSSLL::PKey+ object.
64
- config.client = 'bacon'
65
- config.key = '~/.chef/bacon.pem'
66
-
67
- # If you are running your own Chef Server with a custom SSL certificate, you
68
- # will need to specify the path to a pem file with your custom certificates
69
- # and ChefAPI will wire everything up correctly. (NOTE: it must be a valid
70
- # PEM file).
71
- config.ssl_pem_file = '/path/to/my.pem'
72
-
73
- # If you would like to be vulnerable to MITM attacks, you can also turn off
74
- # SSL verification. Despite what Internet blog posts may suggest, you should
75
- # exhaust other methods before disabling SSL verification. ChefAPI will emit
76
- # a warning message for every request issued with SSL verification disabled.
77
- config.ssl_verify = false
78
-
79
- # If you are behind a proxy, Chef API can run requests through the proxy as
80
- # well. Just set the following configuration parameters as needed.
81
- config.proxy_username = 'user'
82
- config.proxy_password = 'password'
83
- config.proxy_address = 'my.proxy.server' # or 10.0.0.50
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
90
- end
91
- ```
92
-
93
- All of these configuration options are available via the top-level `ChefAPI` object.
94
-
95
- ```ruby
96
- ChefAPI.endpoint = '...'
97
- ```
98
-
99
- You can also configure everything via environment variables (great solution for Docker-based usage). All the environment variables are of the format `CHEF_API_{key}`, where `key` is the uppercase equivalent of the item in the configuration object.
100
-
101
- ```bash
102
- # ChefAPI will use these values
103
- export CHEF_API_ENDPOINT=https://api.opscode.com/organizations/meats
104
- export CHEF_API_CLIENT=bacon
105
- export CHEF_API_KEY=~/.chef/bacon.pem
106
- ```
107
-
108
- In addition, you can configure the environment variables in a JSON-formatted config file either placed in ~/.chef-api or placed in a location configured via the environment variable `CHEF_API_CONFIG`. For example:
109
-
110
- ```json
111
- {
112
- "CHEF_API_ENDPOINT": "https://api.opscode.com/organizations/meats",
113
- "CHEF_API_CLIENT": "bacon",
114
- "CHEF_API_KEY": "~/.chef/bacon.pem"
115
- }
116
- ```
117
-
118
- If you prefer a more object-oriented approach (or if you want to support multiple simultaneous connections), you can create a raw `ChefAPI::Connection` object. All of the options that are available on the `ChefAPI` object are also available on a raw connection:
119
-
120
- ```ruby
121
- connection = ChefAPI::Connection.new(
122
- endpoint: 'https://api.opscode.com/organizations/meats',
123
- client: 'bacon',
124
- key: '~/.chef/bacon.pem'
125
- )
126
-
127
- connection.clients.fetch('chef-webui')
128
- connection.environments.delete('production')
129
- ```
130
-
131
- If you do not want to manage a `ChefAPI::Connection` object, or if you just prefer an alternative syntax, you can use the block-form:
132
-
133
- ```ruby
134
- ChefAPI::Connection.new do |connection|
135
- connection.endpoint = 'https://api.opscode.com/organizations/meats'
136
- connection.client = 'bacon'
137
- connection.key = '~/.chef/bacon.pem'
138
-
139
- # The connection object is now setup, so you can use it directly:
140
- connection.clients.fetch('chef-webui')
141
- connection.environments.delete('production')
142
- end
143
- ```
144
-
145
- ### Making Requests
146
-
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.
148
-
149
- Most resources can be listed, retrieved, created, updated, and destroyed. In programming, this is commonly referred to as "CRUD".
150
-
151
- #### Create
152
-
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:
154
-
155
- ```ruby
156
- Client.create(name: 'new-client') #=> #<Resource::Client name: "new-client", admin: false, ...>
157
- ```
158
-
159
- Or you can create an instance of the object, setting parameters as you go.
160
-
161
- ```ruby
162
- client = Client.new
163
- client.name = 'new-client'
164
- client.save #=> #<Resource::Client name: "new-client", admin: false, ...>
165
- ```
166
-
167
- You can also mix-and-match the hash and object initialization:
168
-
169
- ```ruby
170
- client = Client.new(name: 'new-client')
171
- client.validator = true
172
- client.admin = true
173
- client.save #=> #<Resource::Client name: "new-client", admin: false, ...>
174
- ```
175
-
176
- #### Read
177
-
178
- Most resources have the following "read" functions:
179
-
180
- - `.list`, `.all`, and `.each` for listing Chef resources
181
- - `.fetch` for getting a single Chef resource with the given identifier
182
-
183
- ##### Listing
184
-
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:
186
-
187
- ```ruby
188
- Client.list #=> ["chef-webui", "validator"]
189
- ```
190
-
191
- You can also get the full collection of Chef resources using the `.all` method:
192
-
193
- ```ruby
194
- Client.all #=> [#<Resource::Client name: "chef-webui", admin: false ...>,
195
- #<Resource::Client name: "validator", admin: false ...>]
196
- ```
197
-
198
- However, this is incredibly inefficient. Because of the way the Chef Server serves requests, this will make N+1 queries to the Chef Server. Unless you absolutely need every resource in the collection, you are much better using the lazy enumerable:
199
-
200
- ```ruby
201
- Client.each do |client|
202
- puts client.name
203
- end
204
- ```
205
-
206
- Because the resources include Ruby's custom Enumerable, you can treat the top-level resources as if they were native Ruby enumerable objects. Here are just a few examples:
207
-
208
- ```ruby
209
- Client.first #=> #<Resource::Client name: "chef-webui" ...>
210
- Client.first(3) #=> [#<Resource::Client name: "chef-webui" ...>, ...]
211
- Client.map(&:public_key) #=> ["-----BEGIN PUBLIC KEY-----\nMIGfMA...", "-----BEGIN PUBLIC KEY-----\nMIIBI..."]
212
- ```
213
-
214
- ##### Fetching
215
-
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:
217
-
218
- ```ruby
219
- Client.fetch('chef-webui') #=> #<Resource::Client name: "chef-webui" ...>
220
- ```
221
-
222
- If a resource with the given identifier does not exist, it will return `nil`:
223
-
224
- ```ruby
225
- Client.fetch('not-a-real-client') #=> nil
226
- ```
227
-
228
- #### Update
229
-
230
- You can update a resource using it's unique identifier and a list of hash attributes:
231
-
232
- ```ruby
233
- Client.update('chef-webui', admin: true)
234
- ```
235
-
236
- Or you can get an instance of the object and update the attributes manually:
237
-
238
- ```ruby
239
- client = Client.fetch('chef-webui')
240
- client.admin = true
241
- client.save
242
- ```
243
-
244
- #### Delete
245
-
246
- You can destroy a resource using it's unique identifier:
247
-
248
- ```ruby
249
- Client.destroy('chef-webui') #=> true
250
- ```
251
-
252
- Or you can get an instance of the object and delete it manually:
253
-
254
- ```ruby
255
- client = Client.fetch('chef-webui')
256
- client.destroy #=> true
257
- ```
258
-
259
- ### Validations
260
-
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:
262
-
263
- ```ruby
264
- client = Client.new
265
- client.save #=> false
266
- ```
267
-
268
- Notice that the `client.save` call returned `false`? This is an indication that the resource did not commit back to the server because of a failed validation. You can get the error(s) that prevented the object from saving using the `.errors` method on an instance:
269
-
270
- ```ruby
271
- client.errors #=> { :name => ["must be present"] }
272
- ```
273
-
274
- Just like Rails, you can also get the human-readable list of these errors by calling `#full_messages` on the errors hash. This is useful if you are using ChefAPI as a library and want to give developers a semantic error:
275
-
276
- ```ruby
277
- client.errors.full_messages #=> ["`name' must be present"]
278
- ```
279
-
280
- You can also force ChefAPI to raise an exception if the validations fail, using the "bang" version of save - `save!`:
281
-
282
- ```ruby
283
- client.save! #=> InvalidResource: There were errors saving your resource: `name' must be present
284
- ```
285
-
286
- ### Objects on Disk
287
-
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:
289
-
290
- ```ruby
291
- client = Client.from_file('~/.chef/bacon.pem') #=> #<Resource::Client name: "bacon", admin: false, public_key: nil, private_key: "..." ...>
292
- ```
293
-
294
- ## Searching
295
-
296
- ChefAPI employs both search and partial search functionality.
297
-
298
- ```ruby
299
- # Using regular search
300
- results = Search.query(:node, '*:*', start: 1)
301
- results.total #=> 5_000
302
- results.rows.each do |result|
303
- puts result
304
- end
305
-
306
- # Using partial search
307
- results = PartialSearch.query(:node, { data: ['fqdn'] }, start: 1)
308
- results.total #=> 2
309
- results.rows.each do |result|
310
- puts result
311
- end
312
- ```
313
-
314
- ## FAQ
315
-
316
- **Q: How is this different than [Ridley](https://github.com/RiotGames/ridley)?**<br>
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).
318
-
319
- ## Development
320
-
321
- 1. Clone the project on GitHub
322
- 2. Create a feature branch
323
- 3. Submit a Pull Request
324
-
325
- Important Notes:
326
-
327
- - **All new features must include test coverage.** At a bare minimum, Unit tests are required. It is preferred if you include acceptance tests as well.
328
- - **The tests must be be idempotent.** The HTTP calls made during a test should be able to be run over and over.
329
- - **Tests are order independent.** The default RSpec configuration randomizes the test order, so this should not be a problem.
330
-
331
- ## License & Authors
332
-
333
- - Author: Seth Vargo [sethvargo@gmail.com](mailto:sethvargo@gmail.com)
334
-
335
- ```text
336
- Copyright 2013-2014 Seth Vargo
337
-
338
- Licensed under the Apache License, Version 2.0 (the "License");
339
- you may not use this file except in compliance with the License.
340
- You may obtain a copy of the License at
341
-
342
- http://www.apache.org/licenses/LICENSE-2.0
343
-
344
- Unless required by applicable law or agreed to in writing, software
345
- distributed under the License is distributed on an "AS IS" BASIS,
346
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
347
- See the License for the specific language governing permissions and
348
- limitations under the License.
349
- ```
350
-
351
- [gem]: https://rubygems.org/gems/chef-api
352
- [travis]: http://travis-ci.org/sethvargo/chef-api