chef-zero 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef_zero/rest_base.rb +14 -19
- data/lib/chef_zero/router.rb +11 -6
- data/lib/chef_zero/rspec.rb +12 -2
- data/lib/chef_zero/server.rb +9 -7
- data/lib/chef_zero/version.rb +1 -1
- metadata +2 -2
data/lib/chef_zero/rest_base.rb
CHANGED
@@ -15,26 +15,21 @@ module ChefZero
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(env)
|
18
|
+
rest_path = env['PATH_INFO'].split('/').select { |part| part != "" }
|
19
|
+
method = env['REQUEST_METHOD'].downcase.to_sym
|
20
|
+
if !self.respond_to?(method)
|
21
|
+
accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) }
|
22
|
+
accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(', ')
|
23
|
+
return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{env['REQUEST_PATH']}': #{env['REQUEST_METHOD']}"]
|
24
|
+
end
|
25
|
+
if json_only && !env['HTTP_ACCEPT'].split(';').include?('application/json')
|
26
|
+
return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"]
|
27
|
+
end
|
28
|
+
# Dispatch to get()/post()/put()/delete()
|
18
29
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) }
|
23
|
-
accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(', ')
|
24
|
-
return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{env['REQUEST_PATH']}': #{env['REQUEST_METHOD']}"]
|
25
|
-
end
|
26
|
-
if json_only && !env['HTTP_ACCEPT'].split(';').include?('application/json')
|
27
|
-
return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"]
|
28
|
-
end
|
29
|
-
# Dispatch to get()/post()/put()/delete()
|
30
|
-
begin
|
31
|
-
self.send(method, RestRequest.new(env))
|
32
|
-
rescue RestErrorResponse => e
|
33
|
-
error(e.response_code, e.error)
|
34
|
-
end
|
35
|
-
rescue
|
36
|
-
Chef::Log.error("#{$!.inspect}\n#{$!.backtrace.join("\n")}")
|
37
|
-
raise
|
30
|
+
self.send(method, RestRequest.new(env))
|
31
|
+
rescue RestErrorResponse => e
|
32
|
+
error(e.response_code, e.error)
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
data/lib/chef_zero/router.rb
CHANGED
@@ -13,14 +13,19 @@ module ChefZero
|
|
13
13
|
attr_accessor :not_found
|
14
14
|
|
15
15
|
def call(env)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
begin
|
17
|
+
Chef::Log.debug "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}#{env['QUERY_STRING'] != '' ? "?" + env['QUERY_STRING'] : ''}"
|
18
|
+
clean_path = "/" + env['PATH_INFO'].split('/').select { |part| part != "" }.join("/")
|
19
|
+
routes.each do |route, endpoint|
|
20
|
+
if route.match(clean_path)
|
21
|
+
return endpoint.call(env)
|
22
|
+
end
|
21
23
|
end
|
24
|
+
not_found.call(env)
|
25
|
+
rescue
|
26
|
+
Chef::Log.error("#{$!.inspect}\n#{$!.backtrace.join("\n")}")
|
27
|
+
[500, {"Content-Type" => "text/plain"}, "Exception raised! #{$!.inspect}\n#{$!.backtrace.join("\n")}"]
|
22
28
|
end
|
23
|
-
not_found.call(env)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
data/lib/chef_zero/rspec.rb
CHANGED
@@ -18,8 +18,8 @@ module ChefZero
|
|
18
18
|
@client_key = value
|
19
19
|
end
|
20
20
|
|
21
|
-
def when_the_chef_server(description, &block)
|
22
|
-
context "When the Chef server #{description}" do
|
21
|
+
def when_the_chef_server(description, *tags, &block)
|
22
|
+
context "When the Chef server #{description}", *tags do
|
23
23
|
before :each do
|
24
24
|
unless ChefZero::RSpec.server
|
25
25
|
# Set up configuration so that clients will point to the server
|
@@ -34,9 +34,19 @@ module ChefZero
|
|
34
34
|
ChefZero::RSpec.server.clear_data
|
35
35
|
end
|
36
36
|
|
37
|
+
@old_chef_server_url = Chef::Config.chef_server_url
|
38
|
+
@old_node_name = Chef::Config.node_name
|
39
|
+
@old_client_key = Chef::Config.client_key
|
37
40
|
Chef::Config.chef_server_url = ChefZero::RSpec.server.url
|
38
41
|
Chef::Config.node_name = 'admin'
|
39
42
|
Chef::Config.client_key = ChefZero::RSpec.client_key
|
43
|
+
Chef::Config.http_retry_count = 0
|
44
|
+
end
|
45
|
+
|
46
|
+
after :each do
|
47
|
+
Chef::Config.chef_server_url = @old_chef_server_url
|
48
|
+
Chef::Config.node_name = @old_node_name
|
49
|
+
Chef::Config.client_key = @old_client_key
|
40
50
|
end
|
41
51
|
|
42
52
|
def self.client(name, client)
|
data/lib/chef_zero/server.rb
CHANGED
@@ -151,15 +151,15 @@ module ChefZero
|
|
151
151
|
def load_data(contents)
|
152
152
|
%w(clients environments nodes roles users).each do |data_type|
|
153
153
|
if contents[data_type]
|
154
|
-
|
155
|
-
data[data_type].merge!(contents[data_type])
|
154
|
+
data[data_type].merge!(dejsonize_children(contents[data_type]))
|
156
155
|
end
|
157
156
|
end
|
158
157
|
if contents['data']
|
159
|
-
|
160
|
-
|
158
|
+
new_data = {}
|
159
|
+
contents['data'].each_pair do |key, data_bag|
|
160
|
+
new_data[key] = dejsonize_children(data_bag)
|
161
161
|
end
|
162
|
-
data['data'].merge!(
|
162
|
+
data['data'].merge!(new_data)
|
163
163
|
end
|
164
164
|
if contents['cookbooks']
|
165
165
|
contents['cookbooks'].each_pair do |name_version, cookbook|
|
@@ -243,10 +243,12 @@ module ChefZero
|
|
243
243
|
router
|
244
244
|
end
|
245
245
|
|
246
|
-
def dejsonize_children
|
246
|
+
def dejsonize_children(hash)
|
247
|
+
result = {}
|
247
248
|
hash.each_pair do |key, value|
|
248
|
-
|
249
|
+
result[key] = value.is_a?(Hash) ? JSON.pretty_generate(value) : value
|
249
250
|
end
|
251
|
+
result
|
250
252
|
end
|
251
253
|
|
252
254
|
def get_file(directory, path)
|
data/lib/chef_zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|