chef-api 0.5.0 → 0.6.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/.gitignore +1 -0
- data/.travis.yml +5 -2
- data/CHANGELOG.md +21 -12
- data/README.md +10 -2
- data/chef-api.gemspec +1 -1
- data/lib/chef-api/authentication.rb +1 -1
- data/lib/chef-api/connection.rb +22 -8
- data/lib/chef-api/defaults.rb +23 -12
- data/lib/chef-api/resources/base.rb +1 -1
- data/lib/chef-api/resources/role.rb +1 -0
- data/lib/chef-api/resources/user.rb +1 -1
- data/lib/chef-api/version.rb +1 -1
- data/spec/unit/defaults_spec.rb +39 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75862fce6679a723c8a852797401ffba16d1797f
|
4
|
+
data.tar.gz: 062d62a2b686c86bb693195cbc109be922feeb3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48bbfa255c2e75e154ab1fb89f8417c57fa7b495390d31241ef3f68dc5ca21970a6d9914dbef7627ad8ce786b740154819fa413209a110d702531949ad7cfefe
|
7
|
+
data.tar.gz: 3896eaa411e4a10307ee45d503c82da4b55eff89c85f356bfcdc3050f725a18a5f8485e88658e6ce45c42d356140eabb4b12880a31667714ef67cafe063d411f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,32 +1,41 @@
|
|
1
|
-
ChefAPI Changelog
|
2
|
-
|
1
|
+
# ChefAPI Changelog
|
2
|
+
|
3
|
+
## v0.6.0 (2016-05-05)
|
4
|
+
|
5
|
+
- Remove support for Ruby 1.9
|
6
|
+
- Add the ability to disable signing on a request
|
7
|
+
- Always send JSON when authenticating a user
|
8
|
+
- Fix to_json method contract
|
9
|
+
- Add config file support. See the readme for an example
|
10
|
+
- Add required fields to role schema
|
11
|
+
- Do not symbolize keys in the config
|
12
|
+
- Fix boolean logic in determining if SSL should be verified
|
13
|
+
|
14
|
+
## v0.5.0 (2014-07-10)
|
3
15
|
|
4
|
-
v0.5.0 (2014-07-10)
|
5
|
-
-------------------
|
6
16
|
- Relax the dependency on mime-types
|
7
17
|
- When searching for the file object of a multipart filepart, find the first IO that not a StringIO
|
8
18
|
- Rewind IO objects after digesting them
|
9
19
|
|
10
|
-
v0.4.1 (2014-07-07)
|
11
|
-
|
20
|
+
## v0.4.1 (2014-07-07)
|
21
|
+
|
12
22
|
- Remove dependency on mixlib-authentication
|
13
23
|
- Fix a bug where Content-Type headers were not sent properly
|
14
24
|
- Switch to rake for test running
|
15
25
|
- Improve test coverage with fixtures
|
16
26
|
|
17
|
-
v0.4.0 (2014-07-05)
|
18
|
-
|
27
|
+
## v0.4.0 (2014-07-05)
|
28
|
+
|
19
29
|
- Support multipart POST
|
20
30
|
|
21
|
-
v0.3.0 (2014-06-18)
|
22
|
-
|
31
|
+
## v0.3.0 (2014-06-18)
|
32
|
+
|
23
33
|
- Add search functionality
|
24
34
|
- Add partial search
|
25
35
|
- Update testing harness
|
26
36
|
|
37
|
+
## v0.2.1 (2014-04-17)
|
27
38
|
|
28
|
-
v0.2.1 (2014-04-17)
|
29
|
-
-------------------
|
30
39
|
- Fix a series of typographical errors
|
31
40
|
- Improved documentation for loading resources from disk
|
32
41
|
- Improved spec coverage
|
data/README.md
CHANGED
@@ -2,11 +2,9 @@ ChefAPI Client
|
|
2
2
|
==============
|
3
3
|
[][gem]
|
4
4
|
[][travis]
|
5
|
-
[][gittip]
|
6
5
|
|
7
6
|
[gem]: https://rubygems.org/gems/chef-api
|
8
7
|
[travis]: http://travis-ci.org/sethvargo/chef-api
|
9
|
-
[gittip]: https://www.gittip.com/sethvargo
|
10
8
|
|
11
9
|
**ChefAPI is currently in rapid development!** You should not consider this API stable until the official 1.0.0 release.
|
12
10
|
|
@@ -104,6 +102,16 @@ export CHEF_API_CLIENT=bacon
|
|
104
102
|
export CHEF_API_KEY=~/.chef/bacon.pem
|
105
103
|
```
|
106
104
|
|
105
|
+
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:
|
106
|
+
|
107
|
+
```json
|
108
|
+
{
|
109
|
+
"CHEF_API_ENDPOINT": "https://api.opscode.com/organizations/meats",
|
110
|
+
"CHEF_API_CLIENT": "bacon",
|
111
|
+
"CHEF_API_KEY": "~/.chef/bacon.pem"
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
107
115
|
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:
|
108
116
|
|
109
117
|
```ruby
|
data/chef-api.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'https://github.com/sethvargo/chef-api'
|
14
14
|
spec.license = 'Apache 2.0'
|
15
15
|
|
16
|
-
spec.required_ruby_version = '>=
|
16
|
+
spec.required_ruby_version = '>= 2.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split($/)
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/lib/chef-api/connection.rb
CHANGED
@@ -98,11 +98,12 @@ module ChefAPI
|
|
98
98
|
# @param path (see Connection#request)
|
99
99
|
# @param [Hash] params
|
100
100
|
# the list of query params
|
101
|
+
# @param request_options (see Connection#request)
|
101
102
|
#
|
102
103
|
# @raise (see Connection#request)
|
103
104
|
# @return (see Connection#request)
|
104
105
|
#
|
105
|
-
def get(path, params = {})
|
106
|
+
def get(path, params = {}, request_options = {})
|
106
107
|
request(:get, path, params)
|
107
108
|
end
|
108
109
|
|
@@ -114,11 +115,12 @@ module ChefAPI
|
|
114
115
|
# the body to use for the request
|
115
116
|
# @param [Hash] params
|
116
117
|
# the list of query params
|
118
|
+
# @param request_options (see Connection#request)
|
117
119
|
#
|
118
120
|
# @raise (see Connection#request)
|
119
121
|
# @return (see Connection#request)
|
120
122
|
#
|
121
|
-
def post(path, data, params = {})
|
123
|
+
def post(path, data, params = {}, request_options = {})
|
122
124
|
request(:post, path, data, params)
|
123
125
|
end
|
124
126
|
|
@@ -128,11 +130,12 @@ module ChefAPI
|
|
128
130
|
# @param path (see Connection#request)
|
129
131
|
# @param data (see Connection#post)
|
130
132
|
# @param params (see Connection#post)
|
133
|
+
# @param request_options (see Connection#request)
|
131
134
|
#
|
132
135
|
# @raise (see Connection#request)
|
133
136
|
# @return (see Connection#request)
|
134
137
|
#
|
135
|
-
def put(path, data, params = {})
|
138
|
+
def put(path, data, params = {}, request_options = {})
|
136
139
|
request(:put, path, data, params)
|
137
140
|
end
|
138
141
|
|
@@ -142,11 +145,12 @@ module ChefAPI
|
|
142
145
|
# @param path (see Connection#request)
|
143
146
|
# @param data (see Connection#post)
|
144
147
|
# @param params (see Connection#post)
|
148
|
+
# @param request_options (see Connection#request)
|
145
149
|
#
|
146
150
|
# @raise (see Connection#request)
|
147
151
|
# @return (see Connection#request)
|
148
152
|
#
|
149
|
-
def patch(path, data, params = {})
|
153
|
+
def patch(path, data, params = {}, request_options = {})
|
150
154
|
request(:patch, path, data, params)
|
151
155
|
end
|
152
156
|
|
@@ -155,11 +159,12 @@ module ChefAPI
|
|
155
159
|
#
|
156
160
|
# @param path (see Connection#request)
|
157
161
|
# @param params (see Connection#get)
|
162
|
+
# @param request_options (see Connection#request)
|
158
163
|
#
|
159
164
|
# @raise (see Connection#request)
|
160
165
|
# @return (see Connection#request)
|
161
166
|
#
|
162
|
-
def delete(path, params = {})
|
167
|
+
def delete(path, params = {}, request_options = {})
|
163
168
|
request(:delete, path, params)
|
164
169
|
end
|
165
170
|
|
@@ -180,11 +185,16 @@ module ChefAPI
|
|
180
185
|
# the data to use (varies based on the +verb+)
|
181
186
|
# @param [Hash] params
|
182
187
|
# the params to use for :patch, :post, :put
|
188
|
+
# @param [Hash] request_options
|
189
|
+
# the list of options/configurables for the actual request
|
190
|
+
#
|
191
|
+
# @option request_options [true, false] :sign (default: +true+)
|
192
|
+
# whether to sign the request using mixlib authentication headers
|
183
193
|
#
|
184
194
|
# @return [String, Hash]
|
185
195
|
# the response body
|
186
196
|
#
|
187
|
-
def request(verb, path, data = {}, params = {})
|
197
|
+
def request(verb, path, data = {}, params = {}, request_options = {})
|
188
198
|
log.info "#{verb.to_s.upcase} #{path}..."
|
189
199
|
log.debug "Chef flavor: #{flavor.inspect}"
|
190
200
|
|
@@ -230,7 +240,11 @@ module ChefAPI
|
|
230
240
|
end
|
231
241
|
|
232
242
|
# Sign the request
|
233
|
-
|
243
|
+
if request_options[:sign] == false
|
244
|
+
log.info "Skipping signed header authentication (user requested)..."
|
245
|
+
else
|
246
|
+
add_signing_headers(verb, uri.path, request)
|
247
|
+
end
|
234
248
|
|
235
249
|
# Create the HTTP connection object - since the proxy information defaults
|
236
250
|
# to +nil+, we can just pass it to the initializer method instead of doing
|
@@ -256,7 +270,7 @@ module ChefAPI
|
|
256
270
|
unless ssl_verify
|
257
271
|
log.warn "Disabling SSL verification..."
|
258
272
|
log.warn "Neither ChefAPI nor the maintainers are responsible for " \
|
259
|
-
"
|
273
|
+
"damages incurred as a result of disabling SSL verification. " \
|
260
274
|
"Please use this with extreme caution, or consider specifying " \
|
261
275
|
"a custom certificate using `config.ssl_pem_file'."
|
262
276
|
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
data/lib/chef-api/defaults.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chef-api/version'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module ChefAPI
|
4
5
|
module Defaults
|
@@ -18,6 +19,15 @@ module ChefAPI
|
|
18
19
|
Hash[Configurable.keys.map { |key| [key, send(key)] }]
|
19
20
|
end
|
20
21
|
|
22
|
+
#
|
23
|
+
# The Chef API configuration
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
def config
|
27
|
+
path = File.expand_path(ENV['CHEF_API_CONFIG'] || '~/.chef-api')
|
28
|
+
@config ||= File.exist?(path) ? JSON.parse(File.read(path)) : {}
|
29
|
+
end
|
30
|
+
|
21
31
|
#
|
22
32
|
# The endpoint where the Chef Server lives. This is equivalent to the
|
23
33
|
# +chef_server_url+ in Chef terminology. If you are using Enterprise
|
@@ -35,7 +45,7 @@ module ChefAPI
|
|
35
45
|
# @return [String] (default: +https://api.opscode.com/+)
|
36
46
|
#
|
37
47
|
def endpoint
|
38
|
-
ENV['CHEF_API_ENDPOINT'] || ENDPOINT
|
48
|
+
ENV['CHEF_API_ENDPOINT'] || config['CHEF_API_ENDPOINT'] || ENDPOINT
|
39
49
|
end
|
40
50
|
|
41
51
|
#
|
@@ -52,6 +62,8 @@ module ChefAPI
|
|
52
62
|
def flavor
|
53
63
|
if ENV['CHEF_API_FLAVOR']
|
54
64
|
ENV['CHEF_API_FLAVOR'].to_sym
|
65
|
+
elsif config['CHEF_API_FLAVOR']
|
66
|
+
config['CHEF_API_FLAVOR']
|
55
67
|
else
|
56
68
|
endpoint.include?('/organizations') ? :enterprise : :open_source
|
57
69
|
end
|
@@ -63,7 +75,7 @@ module ChefAPI
|
|
63
75
|
# @return [String]
|
64
76
|
#
|
65
77
|
def user_agent
|
66
|
-
ENV['CHEF_API_USER_AGENT'] || USER_AGENT
|
78
|
+
ENV['CHEF_API_USER_AGENT'] || config['CHEF_API_USER_AGENT'] || USER_AGENT
|
67
79
|
end
|
68
80
|
|
69
81
|
#
|
@@ -74,7 +86,7 @@ module ChefAPI
|
|
74
86
|
# @return [String, nil]
|
75
87
|
#
|
76
88
|
def client
|
77
|
-
ENV['CHEF_API_CLIENT']
|
89
|
+
ENV['CHEF_API_CLIENT'] || config['CHEF_API_CLIENT']
|
78
90
|
end
|
79
91
|
|
80
92
|
#
|
@@ -85,7 +97,7 @@ module ChefAPI
|
|
85
97
|
# @return [String, nil]
|
86
98
|
#
|
87
99
|
def key
|
88
|
-
|
100
|
+
ENV['CHEF_API_KEY'] || config['CHEF_API_KEY']
|
89
101
|
end
|
90
102
|
#
|
91
103
|
# The HTTP Proxy server address as a string
|
@@ -93,7 +105,7 @@ module ChefAPI
|
|
93
105
|
# @return [String, nil]
|
94
106
|
#
|
95
107
|
def proxy_address
|
96
|
-
ENV['CHEF_API_PROXY_ADDRESS']
|
108
|
+
ENV['CHEF_API_PROXY_ADDRESS'] || config['CHEF_API_PROXY_ADDRESS']
|
97
109
|
end
|
98
110
|
|
99
111
|
#
|
@@ -102,7 +114,7 @@ module ChefAPI
|
|
102
114
|
# @return [String, nil]
|
103
115
|
#
|
104
116
|
def proxy_password
|
105
|
-
ENV['CHEF_API_PROXY_PASSWORD']
|
117
|
+
ENV['CHEF_API_PROXY_PASSWORD'] || config['CHEF_API_PROXY_PASSWORD']
|
106
118
|
end
|
107
119
|
|
108
120
|
#
|
@@ -111,7 +123,7 @@ module ChefAPI
|
|
111
123
|
# @return [String, nil]
|
112
124
|
#
|
113
125
|
def proxy_port
|
114
|
-
ENV['CHEF_API_PROXY_PORT']
|
126
|
+
ENV['CHEF_API_PROXY_PORT'] || config['CHEF_API_PROXY_PORT']
|
115
127
|
end
|
116
128
|
|
117
129
|
#
|
@@ -120,7 +132,7 @@ module ChefAPI
|
|
120
132
|
# @return [String, nil]
|
121
133
|
#
|
122
134
|
def proxy_username
|
123
|
-
ENV['CHEF_API_PROXY_USERNAME']
|
135
|
+
ENV['CHEF_API_PROXY_USERNAME'] || config['CHEF_API_PROXY_USERNAME']
|
124
136
|
end
|
125
137
|
|
126
138
|
#
|
@@ -129,7 +141,7 @@ module ChefAPI
|
|
129
141
|
# @return [String, nil]
|
130
142
|
#
|
131
143
|
def ssl_pem_file
|
132
|
-
ENV['CHEF_API_SSL_PEM_FILE']
|
144
|
+
ENV['CHEF_API_SSL_PEM_FILE'] || config['CHEF_API_SSL_PEM_FILE']
|
133
145
|
end
|
134
146
|
|
135
147
|
#
|
@@ -138,13 +150,12 @@ module ChefAPI
|
|
138
150
|
# @return [true, false]
|
139
151
|
#
|
140
152
|
def ssl_verify
|
141
|
-
if ENV['CHEF_API_SSL_VERIFY'].nil?
|
153
|
+
if ENV['CHEF_API_SSL_VERIFY'].nil? && config['CHEF_API_SSL_VERIFY'].nil?
|
142
154
|
true
|
143
155
|
else
|
144
|
-
%w[t y].include?(ENV['CHEF_API_SSL_VERIFY'].downcase[0])
|
156
|
+
%w[t y].include?(ENV['CHEF_API_SSL_VERIFY'].downcase[0]) || config['CHEF_API_SSL_VERIFY']
|
145
157
|
end
|
146
158
|
end
|
147
|
-
|
148
159
|
end
|
149
160
|
end
|
150
161
|
end
|
@@ -4,6 +4,7 @@ module ChefAPI
|
|
4
4
|
|
5
5
|
schema do
|
6
6
|
attribute :name, type: String, primary: true, required: true
|
7
|
+
attribute :json_class, type: String, default: "Chef::Role"
|
7
8
|
attribute :description, type: String
|
8
9
|
attribute :default_attributes, type: Hash, default: {}
|
9
10
|
attribute :override_attributes, type: Hash, default: {}
|
data/lib/chef-api/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ChefAPI
|
4
|
+
describe Defaults do
|
5
|
+
context 'without a config file' do
|
6
|
+
before(:each) do
|
7
|
+
allow(subject).to receive(:config).and_return(Hash.new)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns the default endpoint' do
|
11
|
+
expect(subject.endpoint).to eq subject::ENDPOINT
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the default user agent' do
|
15
|
+
expect(subject.user_agent).to eq subject::USER_AGENT
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with a config file' do
|
20
|
+
before(:each) do
|
21
|
+
subject.instance_variable_set(:@config, nil)
|
22
|
+
allow(File).to receive(:exist?).with(anything()).and_return(true)
|
23
|
+
allow(File).to receive(:read).and_return("{\n"\
|
24
|
+
"\"CHEF_API_ENDPOINT\": \"test_endpoint\",\n" \
|
25
|
+
"\"CHEF_API_USER_AGENT\": \"test_user_agent\"\n" \
|
26
|
+
"}"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the overridden value for endpoint' do
|
31
|
+
expect(subject.endpoint).to eq 'test_endpoint'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns the overridden value for user agent' do
|
35
|
+
expect(subject.user_agent).to eq 'test_user_agent'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 0.6.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:
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logify
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- spec/support/shared/chef_api_resource.rb
|
99
99
|
- spec/support/user.pem
|
100
100
|
- spec/unit/authentication_spec.rb
|
101
|
+
- spec/unit/defaults_spec.rb
|
101
102
|
- spec/unit/errors_spec.rb
|
102
103
|
- spec/unit/resources/base_spec.rb
|
103
104
|
- spec/unit/resources/client_spec.rb
|
@@ -135,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
136
|
requirements:
|
136
137
|
- - ">="
|
137
138
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
139
|
+
version: '2.0'
|
139
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
141
|
requirements:
|
141
142
|
- - ">="
|
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
146
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.3
|
147
|
+
rubygems_version: 2.6.3
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
150
|
summary: A Chef API client in Ruby
|
@@ -161,6 +162,7 @@ test_files:
|
|
161
162
|
- spec/support/shared/chef_api_resource.rb
|
162
163
|
- spec/support/user.pem
|
163
164
|
- spec/unit/authentication_spec.rb
|
165
|
+
- spec/unit/defaults_spec.rb
|
164
166
|
- spec/unit/errors_spec.rb
|
165
167
|
- spec/unit/resources/base_spec.rb
|
166
168
|
- spec/unit/resources/client_spec.rb
|