chef-api 0.2.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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +201 -0
  6. data/README.md +264 -0
  7. data/Rakefile +1 -0
  8. data/chef-api.gemspec +25 -0
  9. data/lib/chef-api/boolean.rb +6 -0
  10. data/lib/chef-api/configurable.rb +78 -0
  11. data/lib/chef-api/connection.rb +466 -0
  12. data/lib/chef-api/defaults.rb +130 -0
  13. data/lib/chef-api/error_collection.rb +44 -0
  14. data/lib/chef-api/errors.rb +35 -0
  15. data/lib/chef-api/logger.rb +160 -0
  16. data/lib/chef-api/proxy.rb +72 -0
  17. data/lib/chef-api/resource.rb +16 -0
  18. data/lib/chef-api/resources/base.rb +951 -0
  19. data/lib/chef-api/resources/client.rb +85 -0
  20. data/lib/chef-api/resources/collection_proxy.rb +217 -0
  21. data/lib/chef-api/resources/cookbook.rb +24 -0
  22. data/lib/chef-api/resources/cookbook_version.rb +23 -0
  23. data/lib/chef-api/resources/data_bag.rb +136 -0
  24. data/lib/chef-api/resources/data_bag_item.rb +35 -0
  25. data/lib/chef-api/resources/environment.rb +16 -0
  26. data/lib/chef-api/resources/node.rb +17 -0
  27. data/lib/chef-api/resources/principal.rb +11 -0
  28. data/lib/chef-api/resources/role.rb +16 -0
  29. data/lib/chef-api/resources/user.rb +11 -0
  30. data/lib/chef-api/schema.rb +112 -0
  31. data/lib/chef-api/util.rb +119 -0
  32. data/lib/chef-api/validator.rb +16 -0
  33. data/lib/chef-api/validators/base.rb +82 -0
  34. data/lib/chef-api/validators/required.rb +11 -0
  35. data/lib/chef-api/validators/type.rb +23 -0
  36. data/lib/chef-api/version.rb +3 -0
  37. data/lib/chef-api.rb +76 -0
  38. data/locales/en.yml +89 -0
  39. data/spec/integration/resources/client_spec.rb +8 -0
  40. data/spec/integration/resources/environment_spec.rb +8 -0
  41. data/spec/integration/resources/node_spec.rb +8 -0
  42. data/spec/integration/resources/role_spec.rb +8 -0
  43. data/spec/spec_helper.rb +26 -0
  44. data/spec/support/chef_server.rb +115 -0
  45. data/spec/support/shared/chef_api_resource.rb +91 -0
  46. data/spec/unit/resources/base_spec.rb +47 -0
  47. data/spec/unit/resources/client_spec.rb +69 -0
  48. metadata +128 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9d6c6244de045894dffca646b3cea3696645629
4
+ data.tar.gz: 3e5a947c02535d537733ee9009906964d423af88
5
+ SHA512:
6
+ metadata.gz: 0e4c4aa13d550e8ffeabf24e0dae0bbd9695a276eb85097e265cf121137f9ef19ed96712f3b172b80716789c60504961760f2ee722b6c459731ef6b0e48121d2
7
+ data.tar.gz: ade2f5cc5dfada170a6922aecf6a6acfe2b23a071a21bca2d062aa86f7d15f4dde1e5caa12e34cf28af7ee8f3c8faaff28b9aa7eb312bab1cff1d3b775f01edb
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+
6
+ # Don't install local development gems on Travis
7
+ bundler_args: --without development
8
+
9
+ # Only test master
10
+ branches:
11
+ only:
12
+ - master
13
+
14
+ script: bundle exec rspec --color --format progress
data/Gemfile ADDED
@@ -0,0 +1,12 @@
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'
10
+ gem 'rake', '~> 10.1'
11
+ gem 'rspec', '~> 2.14'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2013 Seth Vargo <sethvargo@gmail.com>
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,264 @@
1
+ ChefAPI Client
2
+ ==============
3
+ [![Build Status](https://secure.travis-ci.org/sethvargo/chef-api.png?branch=master)](http://travis-ci.org/sethvargo/chef-api)
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
+
10
+ Quick start
11
+ -----------
12
+ Install via Rubygems:
13
+
14
+ $ gem install chef-api
15
+
16
+ or add it to your Gemfile if you are using Bundler:
17
+
18
+ ```ruby
19
+ gem 'chef-api', '~> 0.1'
20
+ ```
21
+
22
+ In your library or project, you will likely want to include the `ChefAPI::Resource` namespace:
23
+
24
+ ```ruby
25
+ include ChefAPI::Resource
26
+ ```
27
+
28
+ This will give you "Rails-like" access to the top-level Chef resources like:
29
+
30
+ ```ruby
31
+ Client.all
32
+ Node.all
33
+ ```
34
+
35
+ If you choose not to include the module, you will need to specify the full module path to access resources:
36
+
37
+ ```ruby
38
+ ChefAPI::Resource::Client.all
39
+ ChefAPI::Resource::Node.all
40
+ ```
41
+
42
+ ### Create a connection
43
+ Before you can make a request, you must give the ChefAPI your connection information and credentials.
44
+
45
+ ```ruby
46
+ ChefAPI.configure do |config|
47
+ # The endpoint for the Chef Server. This can be an Open Source Chef Server,
48
+ # Hosted Chef Server, or Enterprise Chef Server.
49
+ config.endpoint = 'https://api.opscode.com/organizations/meats'
50
+
51
+ # The client and key must also be specified (unless you are running Chef Zero
52
+ # in no-authentication mode). The +key+ attribute may be the raw private key,
53
+ # the path to the private key on disk, or an +OpenSSLL::PKey+ object.
54
+ config.client = 'bacon'
55
+ config.key = '~/.chef/bacon.pem'
56
+
57
+ # If you are running your own Chef Server with a custom SSL certificate, you
58
+ # will need to specify the path to a pem file with your custom certificates
59
+ # and ChefAPI will wire everything up correctly. (NOTE: it must be a valid
60
+ # PEM file).
61
+ config.ssl_pem_file = '/path/to/my.pem'
62
+
63
+ # If you would like to be vulnerable to MITM attacks, you can also turn off
64
+ # SSL verification. Despite what Internet blog posts may suggest, you should
65
+ # exhaust other methods before disabling SSL verification. ChefAPI will emit
66
+ # a warning message for every request issued with SSL verification disabled.
67
+ config.ssl_verify = false
68
+
69
+ # If you are behind a proxy, Chef API can run requests through the proxy as
70
+ # well. Just set the following configuration parameters as needed.
71
+ config.proxy_username = 'user'
72
+ config.proxy_password = 'password'
73
+ config.proxy_address = 'my.proxy.server' # or 10.0.0.50
74
+ config.proxy_port = '8080'
75
+ end
76
+ ```
77
+
78
+ All of these configuration options are available via the top-level `ChefAPI` object.
79
+
80
+ ```ruby
81
+ ChefAPI.endpoint = '...'
82
+ ```
83
+
84
+ 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.
85
+
86
+ ```bash
87
+ # ChefAPI will use these values
88
+ export CHEF_API_ENDPOINT=https://api.opscode.com/organizations/meats
89
+ export CHEF_API_CLIENT=bacon
90
+ export CHEF_API_KEY=~/.chef/bacon.pem
91
+ ```
92
+
93
+ ### Making Requests
94
+ 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.
95
+
96
+ Most resources can be listed, retrieved, created, updated, and destroyed. In programming, this is commonly referred to as "CRUD".
97
+
98
+ #### Create
99
+ 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:
100
+
101
+ ```ruby
102
+ Client.create(name: 'new-client') #=> #<Resource::Client name: "new-client", admin: false, ...>
103
+ ```
104
+
105
+ Or you can create an instance of the object, setting parameters as you go.
106
+
107
+ ```ruby
108
+ client = Client.new
109
+ client.name = 'new-client'
110
+ client.save #=> #<Resource::Client name: "new-client", admin: false, ...>
111
+ ```
112
+
113
+ You can also mix-and-match the hash and object initialization:
114
+
115
+ ```ruby
116
+ client = Client.new(name: 'new-client')
117
+ client.validator = true
118
+ client.admin = true
119
+ client.save #=> #<Resource::Client name: "new-client", admin: false, ...>
120
+ ```
121
+
122
+ #### Read
123
+ Most resources have the following "read" functions:
124
+
125
+ - `.list`, `.all`, and `.each` for listing Chef resources
126
+ - `.fetch` for getting a single Chef resource with the given identifier
127
+
128
+ ##### Listing
129
+ 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:
130
+
131
+ ```ruby
132
+ Client.list #=> ["chef-webui", "validator"]
133
+ ```
134
+
135
+ You can also get the full collection of Chef resources using the `.all` method:
136
+
137
+ ```ruby
138
+ Client.all #=> [#<Resource::Client name: "chef-webui", admin: false ...>,
139
+ #<Resource::Client name: "validator", admin: false ...>]
140
+ ```
141
+
142
+ 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:
143
+
144
+ ```ruby
145
+ Client.each do |client|
146
+ puts client.name
147
+ end
148
+ ```
149
+
150
+ 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:
151
+
152
+ ```ruby
153
+ Client.first #=> #<Resource::Client name: "chef-webui" ...>
154
+ Client.first(3) #=> [#<Resource::Client name: "chef-webui" ...>, ...]
155
+ Client.map(&:public_key) #=> ["-----BEGIN PUBLIC KEY-----\nMIGfMA...", "-----BEGIN PUBLIC KEY-----\nMIIBI..."]
156
+ ```
157
+
158
+ ##### Fetching
159
+ 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:
160
+
161
+ ```ruby
162
+ Client.fetch('chef-webui') #=> #<Resource::Client name: "chef-webui" ...>
163
+ ```
164
+
165
+ If a resource with the given identifier does not exist, it will return `nil`:
166
+
167
+ ```ruby
168
+ Client.fetch('not-a-real-client') #=> nil
169
+ ```
170
+
171
+ #### Update
172
+ You can update a resource using it's unique identifier and a list of hash attributes:
173
+
174
+ ```ruby
175
+ Client.update('chef-webui', admin: true)
176
+ ```
177
+
178
+ Or you can get an instance of the object and update the attributes manually:
179
+
180
+ ```ruby
181
+ client = Client.fetch('chef-webui')
182
+ client.admin = true
183
+ client.save
184
+ ```
185
+
186
+ #### Delete
187
+ You can destroy a resource using it's unique identifier:
188
+
189
+ ```ruby
190
+ Client.destroy('chef-webui') #=> true
191
+ ```
192
+
193
+ Or you can get an instance of the object and delete it manually:
194
+
195
+ ```ruby
196
+ client = Client.fetch('chef-webui')
197
+ client.destroy #=> true
198
+ ```
199
+
200
+ ### Validations
201
+ 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:
202
+
203
+ ```ruby
204
+ client = Client.new
205
+ client.save #=> false
206
+ ```
207
+
208
+ 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:
209
+
210
+ ```ruby
211
+ client.errors #=> { :name => ["must be present"] }
212
+ ```
213
+
214
+ 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:
215
+
216
+ ```ruby
217
+ client.errors.full_messages #=> ["`name' must be present"]
218
+ ```
219
+
220
+ You can also force ChefAPI to raise an exception if the validations fail, using the "bang" version of save - `save!`:
221
+
222
+ ```ruby
223
+ client.save! #=> InvalidResource: There were errors saving your resource: `name' must be present
224
+ ```
225
+
226
+
227
+ FAQ
228
+ ---
229
+ **Q: How is this different than [Ridley](https://github.com/RiotGames/ridley)?**<br>
230
+ 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).
231
+
232
+
233
+ Development
234
+ -----------
235
+ 1. Clone the project on GitHub
236
+ 2. Create a feature branch
237
+ 3. Submit a Pull Request
238
+
239
+ Important Notes:
240
+
241
+ - **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.
242
+ - **The tests must be be idempotent.** The HTTP calls made during a test should be able to be run over and over.
243
+ - **Tests are order independent.** The default RSpec configuration randomizes the test order, so this should not be a problem.
244
+
245
+
246
+ License & Authors
247
+ -----------------
248
+ - Author: Seth Vargo <sethvargo@gmail.com>
249
+
250
+ ```text
251
+ Copyright 2013-2014 Seth Vargo
252
+
253
+ Licensed under the Apache License, Version 2.0 (the "License");
254
+ you may not use this file except in compliance with the License.
255
+ You may obtain a copy of the License at
256
+
257
+ http://www.apache.org/licenses/LICENSE-2.0
258
+
259
+ Unless required by applicable law or agreed to in writing, software
260
+ distributed under the License is distributed on an "AS IS" BASIS,
261
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
262
+ See the License for the specific language governing permissions and
263
+ limitations under the License.
264
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/chef-api.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chef-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'chef-api'
8
+ spec.version = ChefAPI::VERSION
9
+ spec.authors = ['Seth Vargo']
10
+ spec.email = ['sethvargo@gmail.com']
11
+ spec.description = 'A tiny Chef API client with minimal dependencies'
12
+ spec.summary = 'A Chef API client in Ruby'
13
+ spec.homepage = 'https://github.com/sethvargo/chef-api'
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.required_ruby_version = '>= 1.9'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'i18n', '~> 0.6'
24
+ spec.add_dependency 'mixlib-authentication', '~> 1.3'
25
+ end
@@ -0,0 +1,6 @@
1
+ module ChefAPI
2
+ module Boolean; end
3
+
4
+ TrueClass.send(:include, Boolean)
5
+ FalseClass.send(:include, Boolean)
6
+ end
@@ -0,0 +1,78 @@
1
+ module ChefAPI
2
+ #
3
+ # A re-usable class containing configuration information for the {Client}. See
4
+ # {Defaults} for a list of default values.
5
+ #
6
+ module Configurable
7
+ class << self
8
+ #
9
+ # The list of configurable keys.
10
+ #
11
+ # @return [Array<Symbol>]
12
+ #
13
+ def keys
14
+ @keys ||= [
15
+ :endpoint,
16
+ :client,
17
+ :key,
18
+ :proxy_address,
19
+ :proxy_password,
20
+ :proxy_port,
21
+ :proxy_username,
22
+ :ssl_pem_file,
23
+ :ssl_verify,
24
+ :user_agent,
25
+ ]
26
+ end
27
+ end
28
+
29
+ #
30
+ # Create one attribute getter and setter for each key.
31
+ #
32
+ ChefAPI::Configurable.keys.each do |key|
33
+ attr_accessor key
34
+ end
35
+
36
+ #
37
+ # Set the configuration for this config, using a block.
38
+ #
39
+ # @example Configure the API endpoint
40
+ # ChefAPI.configure do |config|
41
+ # config.endpoint = "http://www.my-ChefAPI-server.com/ChefAPI"
42
+ # end
43
+ #
44
+ def configure
45
+ yield self
46
+ end
47
+
48
+ #
49
+ # Reset all configuration options to their default values.
50
+ #
51
+ # @example Reset all settings
52
+ # ChefAPI.reset!
53
+ #
54
+ # @return [self]
55
+ #
56
+ def reset!
57
+ ChefAPI::Configurable.keys.each do |key|
58
+ instance_variable_set(:"@#{key}", Defaults.options[key])
59
+ end
60
+ self
61
+ end
62
+ alias_method :setup, :reset!
63
+
64
+ private
65
+
66
+ #
67
+ # The list of configurable keys, as an options hash.
68
+ #
69
+ # @return [Hash]
70
+ #
71
+ def options
72
+ map = ChefAPI::Configurable.keys.map do |key|
73
+ [key, instance_variable_get(:"@#{key}")]
74
+ end
75
+ Hash[map]
76
+ end
77
+ end
78
+ end