chef-zero 4.8.0 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -4
- data/Rakefile +20 -10
- data/bin/chef-zero +12 -12
- data/chef-zero.gemspec +24 -24
- data/lib/chef_zero.rb +1 -1
- data/lib/chef_zero/chef_data/acl_path.rb +16 -16
- data/lib/chef_zero/chef_data/cookbook_data.rb +24 -24
- data/lib/chef_zero/chef_data/data_normalizer.rb +120 -120
- data/lib/chef_zero/chef_data/default_creator.rb +145 -145
- data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
- data/lib/chef_zero/data_store/data_not_found_error.rb +2 -2
- data/lib/chef_zero/data_store/default_facade.rb +5 -5
- data/lib/chef_zero/data_store/interface_v1.rb +1 -1
- data/lib/chef_zero/data_store/interface_v2.rb +1 -1
- data/lib/chef_zero/data_store/memory_store.rb +4 -4
- data/lib/chef_zero/data_store/memory_store_v2.rb +8 -8
- data/lib/chef_zero/data_store/raw_file_store.rb +10 -10
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +9 -9
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +5 -5
- data/lib/chef_zero/endpoints/acl_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/acls_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/actor_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +5 -6
- data/lib/chef_zero/endpoints/actors_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +10 -10
- data/lib/chef_zero/endpoints/container_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +20 -16
- data/lib/chef_zero/endpoints/cookbooks_base.rb +13 -13
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/dummy_endpoint.rb +0 -2
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/group_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/groups_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/license_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/node_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +7 -7
- data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/organization_endpoint.rb +10 -10
- data/lib/chef_zero/endpoints/organization_user_base.rb +2 -2
- data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +12 -13
- data/lib/chef_zero/endpoints/policies_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/policy_group_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/principal_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +9 -9
- data/lib/chef_zero/endpoints/search_endpoint.rb +51 -49
- data/lib/chef_zero/endpoints/searches_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/version_endpoint.rb +1 -1
- data/lib/chef_zero/log.rb +1 -1
- data/lib/chef_zero/rest_base.rb +25 -25
- data/lib/chef_zero/rest_request.rb +11 -11
- data/lib/chef_zero/rest_router.rb +30 -30
- data/lib/chef_zero/rspec.rb +33 -33
- data/lib/chef_zero/server.rb +188 -189
- data/lib/chef_zero/socketless_server_map.rb +2 -3
- data/lib/chef_zero/solr/query/binary_operator.rb +8 -8
- data/lib/chef_zero/solr/query/phrase.rb +1 -1
- data/lib/chef_zero/solr/query/range_query.rb +2 -2
- data/lib/chef_zero/solr/query/regexpable_query.rb +1 -0
- data/lib/chef_zero/solr/query/term.rb +5 -5
- data/lib/chef_zero/solr/query/unary_operator.rb +4 -4
- data/lib/chef_zero/solr/solr_doc.rb +4 -4
- data/lib/chef_zero/solr/solr_parser.rb +34 -33
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run_oc_pedant.rb +61 -60
- data/spec/search_spec.rb +11 -11
- data/spec/server_spec.rb +35 -35
- data/spec/socketless_server_map_spec.rb +1 -3
- data/spec/support/oc_pedant.rb +20 -21
- metadata +2 -2
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/rest_base"
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module Endpoints
|
@@ -8,8 +8,8 @@ module ChefZero
|
|
8
8
|
def get(request)
|
9
9
|
get_data(request, request.rest_path[0..-2])
|
10
10
|
username = request.rest_path[1]
|
11
|
-
result = list_data(request, [
|
12
|
-
exists_data?(request, [
|
11
|
+
result = list_data(request, [ "organizations" ]).select do |org|
|
12
|
+
exists_data?(request, [ "organizations", org, "association_requests", username ])
|
13
13
|
end
|
14
14
|
result = result.map { |org| { "id" => "#{username}-#{org}", "orgname" => org } }
|
15
15
|
json_response(200, result)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/rest_base"
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module Endpoints
|
@@ -7,11 +7,11 @@ module ChefZero
|
|
7
7
|
class UserOrganizationsEndpoint < RestBase
|
8
8
|
def get(request)
|
9
9
|
username = request.rest_path[1]
|
10
|
-
result = list_data(request, [
|
11
|
-
exists_data?(request, [
|
10
|
+
result = list_data(request, [ "organizations" ]).select do |orgname|
|
11
|
+
exists_data?(request, [ "organizations", orgname, "users", username ])
|
12
12
|
end
|
13
13
|
result = result.map do |orgname|
|
14
|
-
org = get_data(request, [
|
14
|
+
org = get_data(request, [ "organizations", orgname, "org" ])
|
15
15
|
org = FFI_Yajl::Parser.parse(org, :create_additions => false)
|
16
16
|
{ "organization" => ChefData::DataNormalizer.normalize_organization(org, orgname) }
|
17
17
|
end
|
data/lib/chef_zero/log.rb
CHANGED
data/lib/chef_zero/rest_base.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "chef_zero/rest_request"
|
2
|
+
require "chef_zero/rest_error_response"
|
3
|
+
require "chef_zero/data_store/data_not_found_error"
|
4
|
+
require "chef_zero/chef_data/acl_path"
|
5
5
|
|
6
6
|
module ChefZero
|
7
7
|
class RestBase
|
@@ -34,7 +34,7 @@ module ChefZero
|
|
34
34
|
"error" => "invalid-x-ops-server-api-version",
|
35
35
|
"message" => "Specified version #{version} not supported",
|
36
36
|
"min_api_version" => MIN_API_VERSION,
|
37
|
-
"max_api_version" => MAX_API_VERSION
|
37
|
+
"max_api_version" => MAX_API_VERSION,
|
38
38
|
}
|
39
39
|
|
40
40
|
return json_response(406,
|
@@ -51,11 +51,11 @@ module ChefZero
|
|
51
51
|
method = request.method.downcase.to_sym
|
52
52
|
if !self.respond_to?(method)
|
53
53
|
accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) }
|
54
|
-
accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(
|
55
|
-
return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{request.env['REQUEST_PATH']}': #{request.env['REQUEST_METHOD']}"]
|
54
|
+
accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(", ")
|
55
|
+
return [405, { "Content-Type" => "text/plain", "Allow" => accept_methods_str }, "Bad request method for '#{request.env['REQUEST_PATH']}': #{request.env['REQUEST_METHOD']}"]
|
56
56
|
end
|
57
|
-
if json_only && !accepts?(request,
|
58
|
-
return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"]
|
57
|
+
if json_only && !accepts?(request, "application", "json")
|
58
|
+
return [406, { "Content-Type" => "text/plain" }, "Must accept application/json"]
|
59
59
|
end
|
60
60
|
# Dispatch to get()/post()/put()/delete()
|
61
61
|
begin
|
@@ -73,12 +73,12 @@ module ChefZero
|
|
73
73
|
def accepts?(request, category, type)
|
74
74
|
# If HTTP_ACCEPT is not sent at all, assume it accepts anything
|
75
75
|
# This parses as per http://tools.ietf.org/html/rfc7231#section-5.3
|
76
|
-
return true if !request.env[
|
77
|
-
accepts = request.env[
|
78
|
-
return accepts.include?("#{category}/#{type}") || accepts.include?("#{category}/*") || accepts.include?(
|
76
|
+
return true if !request.env["HTTP_ACCEPT"]
|
77
|
+
accepts = request.env["HTTP_ACCEPT"].split(/,\s*/).map { |x| x.split(";", 2)[0].strip }
|
78
|
+
return accepts.include?("#{category}/#{type}") || accepts.include?("#{category}/*") || accepts.include?("*/*")
|
79
79
|
end
|
80
80
|
|
81
|
-
def get_data(request, rest_path=nil, *options)
|
81
|
+
def get_data(request, rest_path = nil, *options)
|
82
82
|
rest_path ||= request.rest_path
|
83
83
|
rest_path = rest_path.map { |v| URI.decode(v) }
|
84
84
|
begin
|
@@ -94,7 +94,7 @@ module ChefZero
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
def list_data(request, rest_path=nil, *options)
|
97
|
+
def list_data(request, rest_path = nil, *options)
|
98
98
|
rest_path ||= request.rest_path
|
99
99
|
begin
|
100
100
|
data_store.list(rest_path)
|
@@ -107,7 +107,7 @@ module ChefZero
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def delete_data(request, rest_path=nil, *options)
|
110
|
+
def delete_data(request, rest_path = nil, *options)
|
111
111
|
rest_path ||= request.rest_path
|
112
112
|
begin
|
113
113
|
data_store.delete(rest_path, *options)
|
@@ -196,17 +196,17 @@ module ChefZero
|
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
-
def exists_data?(request, rest_path=nil)
|
199
|
+
def exists_data?(request, rest_path = nil)
|
200
200
|
rest_path ||= request.rest_path
|
201
201
|
data_store.exists?(rest_path)
|
202
202
|
end
|
203
203
|
|
204
|
-
def exists_data_dir?(request, rest_path=nil)
|
204
|
+
def exists_data_dir?(request, rest_path = nil)
|
205
205
|
rest_path ||= request.rest_path
|
206
206
|
data_store.exists_dir?(rest_path)
|
207
207
|
end
|
208
208
|
|
209
|
-
def error(response_code, error, opts={})
|
209
|
+
def error(response_code, error, opts = {})
|
210
210
|
json_response(response_code, { "error" => [ error ] }, opts)
|
211
211
|
end
|
212
212
|
|
@@ -223,7 +223,7 @@ module ChefZero
|
|
223
223
|
#
|
224
224
|
# @return (see #already_json_response)
|
225
225
|
#
|
226
|
-
def json_response(response_code, data, options={})
|
226
|
+
def json_response(response_code, data, options = {})
|
227
227
|
options = { pretty: true }.merge(options)
|
228
228
|
do_pretty_json = !!options.delete(:pretty) # make sure we have a proper Boolean.
|
229
229
|
json = FFI_Yajl::Encoder.encode(data, pretty: do_pretty_json)
|
@@ -231,7 +231,7 @@ module ChefZero
|
|
231
231
|
end
|
232
232
|
|
233
233
|
def text_response(response_code, text)
|
234
|
-
[response_code, {"Content-Type" => "text/plain"}, text]
|
234
|
+
[response_code, { "Content-Type" => "text/plain" }, text]
|
235
235
|
end
|
236
236
|
|
237
237
|
# Returns an Array with the response code, HTTP headers, and JSON body.
|
@@ -245,7 +245,7 @@ module ChefZero
|
|
245
245
|
#
|
246
246
|
# @return [Array(Fixnum, Hash{String => String}, String)]
|
247
247
|
#
|
248
|
-
def already_json_response(response_code, json_text, options={})
|
248
|
+
def already_json_response(response_code, json_text, options = {})
|
249
249
|
version_header = FFI_Yajl::Encoder.encode(
|
250
250
|
"min_version" => MIN_API_VERSION.to_s,
|
251
251
|
"max_version" => MAX_API_VERSION.to_s,
|
@@ -255,7 +255,7 @@ module ChefZero
|
|
255
255
|
|
256
256
|
headers = {
|
257
257
|
"Content-Type" => "application/json",
|
258
|
-
"X-Ops-Server-API-Version" => version_header
|
258
|
+
"X-Ops-Server-API-Version" => version_header,
|
259
259
|
}
|
260
260
|
headers.merge!(options[:headers]) if options[:headers]
|
261
261
|
|
@@ -266,7 +266,7 @@ module ChefZero
|
|
266
266
|
def build_uri(base_uri, rest_path)
|
267
267
|
if server.options[:single_org]
|
268
268
|
# Strip off /organizations/chef if we are in single org mode
|
269
|
-
if rest_path[0..1] != [
|
269
|
+
if rest_path[0..1] != [ "organizations", server.options[:single_org] ]
|
270
270
|
raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode"
|
271
271
|
end
|
272
272
|
|
@@ -314,8 +314,8 @@ module ChefZero
|
|
314
314
|
|
315
315
|
def policy_name_invalid?(name)
|
316
316
|
!name.is_a?(String) ||
|
317
|
-
|
318
|
-
|
317
|
+
name.size > 255 ||
|
318
|
+
name =~ /[+ !]/
|
319
319
|
end
|
320
320
|
end
|
321
321
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rack/request"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
class RestRequest
|
@@ -15,10 +15,10 @@ module ChefZero
|
|
15
15
|
|
16
16
|
def base_uri
|
17
17
|
# Load balancer awareness
|
18
|
-
if env[
|
19
|
-
scheme = env[
|
18
|
+
if env["HTTP_X_FORWARDED_PROTO"]
|
19
|
+
scheme = env["HTTP_X_FORWARDED_PROTO"]
|
20
20
|
else
|
21
|
-
scheme = env[
|
21
|
+
scheme = env["rack.url_scheme"]
|
22
22
|
end
|
23
23
|
@base_uri ||= "#{scheme}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}"
|
24
24
|
end
|
@@ -28,7 +28,7 @@ module ChefZero
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def api_version
|
31
|
-
@env[
|
31
|
+
@env["HTTP_X_OPS_SERVER_API_VERSION"] || ZERO
|
32
32
|
end
|
33
33
|
|
34
34
|
def api_v0?
|
@@ -36,15 +36,15 @@ module ChefZero
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def requestor
|
39
|
-
@env[
|
39
|
+
@env["HTTP_X_OPS_USERID"]
|
40
40
|
end
|
41
41
|
|
42
42
|
def method
|
43
|
-
@env[
|
43
|
+
@env["REQUEST_METHOD"]
|
44
44
|
end
|
45
45
|
|
46
46
|
def rest_path
|
47
|
-
@rest_path ||= rest_base_prefix + env[
|
47
|
+
@rest_path ||= rest_base_prefix + env["PATH_INFO"].split("/").select { |part| part != "" }
|
48
48
|
end
|
49
49
|
|
50
50
|
def rest_path=(rest_path)
|
@@ -56,7 +56,7 @@ module ChefZero
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def body
|
59
|
-
@body ||= env[
|
59
|
+
@body ||= env["rack.input"].read
|
60
60
|
end
|
61
61
|
|
62
62
|
def query_params
|
@@ -72,9 +72,9 @@ module ChefZero
|
|
72
72
|
def to_s
|
73
73
|
result = "#{method} #{rest_path.join('/')}"
|
74
74
|
if query_params.size > 0
|
75
|
-
result << "?#{query_params.map { |k,v| "#{k}=#{v}" }.join('&') }"
|
75
|
+
result << "?#{query_params.map { |k, v| "#{k}=#{v}" }.join('&') }"
|
76
76
|
end
|
77
|
-
if body.chomp !=
|
77
|
+
if body.chomp != ""
|
78
78
|
result << "\n--- #{method} BODY ---\n"
|
79
79
|
result << body
|
80
80
|
result << "\n" if !body.end_with?("\n")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "pp"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
class RestRouter
|
@@ -33,40 +33,40 @@ module ChefZero
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def find_endpoint(clean_path)
|
37
|
+
_, endpoint = routes.find { |route, endpoint| route.match(clean_path) }
|
38
|
+
endpoint || not_found
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def log_request(request)
|
42
|
+
ChefZero::Log.debug do
|
43
|
+
"#{request.method} /#{request.rest_path.join("/")}".tap do |msg|
|
44
|
+
next unless request.method =~ /^(POST|PUT)$/
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
46
|
+
if request.body.nil? || request.body.empty?
|
47
|
+
msg << " (no body)"
|
48
|
+
else
|
49
|
+
msg << [
|
50
|
+
"",
|
51
|
+
"--- #{request.method} BODY ---",
|
52
|
+
request.body.chomp,
|
53
|
+
"--- END #{request.method} BODY ---",
|
54
|
+
].join("\n")
|
56
55
|
end
|
57
56
|
end
|
58
|
-
|
59
|
-
ChefZero::Log.debug { request.pretty_inspect }
|
60
57
|
end
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
]
|
69
|
-
|
70
|
-
|
59
|
+
ChefZero::Log.debug { request.pretty_inspect }
|
60
|
+
end
|
61
|
+
|
62
|
+
def log_response(response)
|
63
|
+
ChefZero::Log.debug {
|
64
|
+
[ "",
|
65
|
+
"--- RESPONSE (#{response[0]}) ---",
|
66
|
+
response[2].chomp,
|
67
|
+
"--- END RESPONSE ---",
|
68
|
+
].join("\n")
|
69
|
+
}
|
70
|
+
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/chef_zero/rspec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "tempfile"
|
2
|
+
require "chef_zero/server"
|
3
|
+
require "chef_zero/rest_request"
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module RSpec
|
@@ -25,7 +25,7 @@ module ChefZero
|
|
25
25
|
|
26
26
|
# Set up configuration so that clients will point to the server
|
27
27
|
self.server = ChefZero::Server.new(chef_server_options)
|
28
|
-
self.client_key = Tempfile.new([
|
28
|
+
self.client_key = Tempfile.new(["chef_zero_client_key", ".pem"])
|
29
29
|
client_key.write(ChefZero::PRIVATE_KEY)
|
30
30
|
client_key.close
|
31
31
|
# Start the server
|
@@ -84,7 +84,7 @@ module ChefZero
|
|
84
84
|
else
|
85
85
|
Chef::Config.chef_server_url = ChefZero::RSpec.server.url
|
86
86
|
end
|
87
|
-
Chef::Config.node_name =
|
87
|
+
Chef::Config.node_name = "admin"
|
88
88
|
Chef::Config.client_key = ChefZero::RSpec.client_key.path
|
89
89
|
Chef::Config.http_retry_count = 0
|
90
90
|
end
|
@@ -103,7 +103,7 @@ module ChefZero
|
|
103
103
|
end
|
104
104
|
|
105
105
|
module WhenTheChefServerClassMethods
|
106
|
-
def organization(name, org =
|
106
|
+
def organization(name, org = "{}", &block)
|
107
107
|
before(chef_server_options[:server_scope]) { organization(name, org, &block) }
|
108
108
|
end
|
109
109
|
|
@@ -175,8 +175,8 @@ module ChefZero
|
|
175
175
|
end
|
176
176
|
|
177
177
|
module WhenTheChefServerInstanceMethods
|
178
|
-
def organization(name, org =
|
179
|
-
ChefZero::RSpec.server.data_store.set([
|
178
|
+
def organization(name, org = "{}", &block)
|
179
|
+
ChefZero::RSpec.server.data_store.set([ "organizations", name, "org" ], dejsonize(org), :create_dir, :create)
|
180
180
|
prev_org_name = @current_org
|
181
181
|
@current_org = name
|
182
182
|
prev_object_path = @current_object_path
|
@@ -192,7 +192,7 @@ module ChefZero
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def acl_for(path, data)
|
195
|
-
ChefZero::RSpec.server.load_data({
|
195
|
+
ChefZero::RSpec.server.load_data({ "acls" => { path => data } }, current_org)
|
196
196
|
end
|
197
197
|
|
198
198
|
def acl(data)
|
@@ -201,14 +201,14 @@ module ChefZero
|
|
201
201
|
|
202
202
|
def client(name, data, &block)
|
203
203
|
with_object_path("clients/#{name}") do
|
204
|
-
ChefZero::RSpec.server.load_data({
|
204
|
+
ChefZero::RSpec.server.load_data({ "clients" => { name => data } }, current_org)
|
205
205
|
instance_eval(&block) if block_given?
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
def container(name, data, &block)
|
210
210
|
with_object_path("containers/#{name}") do
|
211
|
-
ChefZero::RSpec.server.load_data({
|
211
|
+
ChefZero::RSpec.server.load_data({ "containers" => { name => data } }, current_org)
|
212
212
|
instance_eval(&block) if block_given?
|
213
213
|
end
|
214
214
|
end
|
@@ -217,14 +217,14 @@ module ChefZero
|
|
217
217
|
with_object_path("cookbooks/#{name}") do
|
218
218
|
# If you didn't specify metadata.rb, we generate it for you. If you
|
219
219
|
# explicitly set it to nil, that means you don't want it at all.
|
220
|
-
if data.has_key?(
|
221
|
-
if data[
|
222
|
-
data.delete(
|
220
|
+
if data.has_key?("metadata.rb")
|
221
|
+
if data["metadata.rb"].nil?
|
222
|
+
data.delete("metadata.rb")
|
223
223
|
end
|
224
224
|
else
|
225
|
-
data[
|
225
|
+
data["metadata.rb"] = "name #{name.inspect}; version #{version.inspect}"
|
226
226
|
end
|
227
|
-
ChefZero::RSpec.server.load_data({
|
227
|
+
ChefZero::RSpec.server.load_data({ "cookbooks" => { "#{name}-#{version}" => data.merge(options) } }, current_org)
|
228
228
|
instance_eval(&block) if block_given?
|
229
229
|
end
|
230
230
|
end
|
@@ -233,78 +233,78 @@ module ChefZero
|
|
233
233
|
with_object_path("cookbook_artifacts/#{name}") do
|
234
234
|
# If you didn't specify metadata.rb, we generate it for you. If you
|
235
235
|
# explicitly set it to nil, that means you don't want it at all.
|
236
|
-
if data.has_key?(
|
237
|
-
if data[
|
238
|
-
data.delete(
|
236
|
+
if data.has_key?("metadata.rb")
|
237
|
+
if data["metadata.rb"].nil?
|
238
|
+
data.delete("metadata.rb")
|
239
239
|
end
|
240
240
|
else
|
241
|
-
data[
|
241
|
+
data["metadata.rb"] = "name #{name.inspect}"
|
242
242
|
end
|
243
|
-
ChefZero::RSpec.server.load_data({
|
243
|
+
ChefZero::RSpec.server.load_data({ "cookbook_artifacts" => { "#{name}-#{identifier}" => data } }, current_org)
|
244
244
|
instance_eval(&block) if block_given?
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
248
|
def data_bag(name, data, &block)
|
249
249
|
with_object_path("data/#{name}") do
|
250
|
-
ChefZero::RSpec.server.load_data({
|
250
|
+
ChefZero::RSpec.server.load_data({ "data" => { name => data } }, current_org)
|
251
251
|
instance_eval(&block) if block_given?
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
255
|
def environment(name, data, &block)
|
256
256
|
with_object_path("environments/#{name}") do
|
257
|
-
ChefZero::RSpec.server.load_data({
|
257
|
+
ChefZero::RSpec.server.load_data({ "environments" => { name => data } }, current_org)
|
258
258
|
instance_eval(&block) if block_given?
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
262
|
def group(name, data, &block)
|
263
263
|
with_object_path("groups/#{name}") do
|
264
|
-
ChefZero::RSpec.server.load_data({
|
264
|
+
ChefZero::RSpec.server.load_data({ "groups" => { name => data } }, current_org)
|
265
265
|
instance_eval(&block) if block_given?
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
269
269
|
def node(name, data, &block)
|
270
270
|
with_object_path("nodes/#{name}") do
|
271
|
-
ChefZero::RSpec.server.load_data({
|
271
|
+
ChefZero::RSpec.server.load_data({ "nodes" => { name => data } }, current_org)
|
272
272
|
instance_eval(&block) if block_given?
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
def org_invite(*usernames)
|
277
|
-
ChefZero::RSpec.server.load_data({
|
277
|
+
ChefZero::RSpec.server.load_data({ "invites" => usernames }, current_org)
|
278
278
|
end
|
279
279
|
|
280
280
|
def org_member(*usernames)
|
281
|
-
ChefZero::RSpec.server.load_data({
|
281
|
+
ChefZero::RSpec.server.load_data({ "members" => usernames }, current_org)
|
282
282
|
end
|
283
283
|
|
284
284
|
def policy(name, version, data, &block)
|
285
285
|
with_object_path("policies/#{name}") do
|
286
|
-
ChefZero::RSpec.server.load_data({
|
286
|
+
ChefZero::RSpec.server.load_data({ "policies" => { name => { version => data } } }, current_org)
|
287
287
|
instance_eval(&block) if block_given?
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
def policy_group(name, data, &block)
|
292
292
|
with_object_path("policy_groups/#{name}") do
|
293
|
-
ChefZero::RSpec.server.load_data({
|
293
|
+
ChefZero::RSpec.server.load_data({ "policy_groups" => { name => data } }, current_org)
|
294
294
|
instance_eval(&block) if block_given?
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
298
|
def role(name, data, &block)
|
299
299
|
with_object_path("roles/#{name}") do
|
300
|
-
ChefZero::RSpec.server.load_data({
|
300
|
+
ChefZero::RSpec.server.load_data({ "roles" => { name => data } }, current_org)
|
301
301
|
instance_eval(&block) if block_given?
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
def sandbox(name, data, &block)
|
306
306
|
with_object_path("sandboxes/#{name}") do
|
307
|
-
ChefZero::RSpec.server.load_data({
|
307
|
+
ChefZero::RSpec.server.load_data({ "sandboxes" => { name => data } }, current_org)
|
308
308
|
instance_eval(&block) if block_given?
|
309
309
|
end
|
310
310
|
end
|
@@ -312,14 +312,14 @@ module ChefZero
|
|
312
312
|
def user(name, data, &block)
|
313
313
|
if ChefZero::RSpec.server.options[:osc_compat]
|
314
314
|
with_object_path("users/#{name}") do
|
315
|
-
ChefZero::RSpec.server.load_data({
|
315
|
+
ChefZero::RSpec.server.load_data({ "users" => { name => data } }, current_org)
|
316
316
|
instance_eval(&block) if block_given?
|
317
317
|
end
|
318
318
|
else
|
319
319
|
old_object_path = @current_object_path
|
320
320
|
@current_object_path = "users/#{name}"
|
321
321
|
begin
|
322
|
-
ChefZero::RSpec.server.load_data({
|
322
|
+
ChefZero::RSpec.server.load_data({ "users" => { name => data } }, current_org)
|
323
323
|
instance_eval(&block) if block_given?
|
324
324
|
ensure
|
325
325
|
@current_object_path = old_object_path
|