chef-zero 2.0.2 → 2.1
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/lib/chef_zero/data_normalizer.rb +6 -2
- data/lib/chef_zero/data_store/interface_v1.rb +49 -0
- data/lib/chef_zero/data_store/interface_v2.rb +18 -0
- data/lib/chef_zero/data_store/memory_store.rb +6 -141
- data/lib/chef_zero/data_store/memory_store_v2.rb +188 -0
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +190 -0
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -0
- data/lib/chef_zero/endpoints/actor_endpoint.rb +6 -12
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/cookbooks_base.rb +5 -5
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +9 -9
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/node_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/principal_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/role_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +2 -3
- data/lib/chef_zero/endpoints/search_endpoint.rb +13 -9
- data/lib/chef_zero/endpoints/searches_endpoint.rb +1 -1
- data/lib/chef_zero/rest_base.rb +10 -2
- data/lib/chef_zero/rest_request.rb +4 -3
- data/lib/chef_zero/server.rb +83 -52
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run.rb +72 -25
- data/spec/support/pedant.rb +4 -0
- metadata +10 -5
@@ -11,23 +11,23 @@ module ChefZero
|
|
11
11
|
filter_cookbooks(cookbooks_list, constraints, num_versions) do |name, versions|
|
12
12
|
versions_list = versions.map do |version|
|
13
13
|
{
|
14
|
-
'url' => build_uri(request.base_uri, ['cookbooks', name, version]),
|
14
|
+
'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name, version]),
|
15
15
|
'version' => version
|
16
16
|
}
|
17
17
|
end
|
18
18
|
results[name] = {
|
19
|
-
'url' => build_uri(request.base_uri, ['cookbooks', name]),
|
19
|
+
'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name]),
|
20
20
|
'versions' => versions_list
|
21
21
|
}
|
22
22
|
end
|
23
23
|
results
|
24
24
|
end
|
25
25
|
|
26
|
-
def all_cookbooks_list
|
26
|
+
def all_cookbooks_list(request)
|
27
27
|
result = {}
|
28
28
|
# Race conditions exist here (if someone deletes while listing). I don't care.
|
29
|
-
data_store.list(['cookbooks']).each do |name|
|
30
|
-
result[name] = data_store.list(['cookbooks', name])
|
29
|
+
data_store.list(request.rest_path[0..1] + ['cookbooks']).each do |name|
|
30
|
+
result[name] = data_store.list(request.rest_path[0..1] + ['cookbooks', name])
|
31
31
|
end
|
32
32
|
result
|
33
33
|
end
|
@@ -12,7 +12,7 @@ module ChefZero
|
|
12
12
|
else
|
13
13
|
num_versions = 1
|
14
14
|
end
|
15
|
-
json_response(200, format_cookbooks_list(request, all_cookbooks_list, {}, num_versions))
|
15
|
+
json_response(200, format_cookbooks_list(request, all_cookbooks_list(request), {}, num_versions))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -15,7 +15,7 @@ module ChefZero
|
|
15
15
|
key = JSON.parse(request.body, :create_additions => false)[identity_key]
|
16
16
|
response = super(request)
|
17
17
|
if response[0] == 201
|
18
|
-
already_json_response(201, DataBagItemEndpoint::populate_defaults(request, request.body, request.rest_path[
|
18
|
+
already_json_response(201, DataBagItemEndpoint::populate_defaults(request, request.body, request.rest_path[3], key))
|
19
19
|
else
|
20
20
|
response
|
21
21
|
end
|
@@ -31,7 +31,7 @@ module ChefZero
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def delete(request)
|
34
|
-
key = request.rest_path[
|
34
|
+
key = request.rest_path[3]
|
35
35
|
delete_data_dir(request, request.rest_path, :recursive)
|
36
36
|
json_response(200, {
|
37
37
|
'chef_type' => 'data_bag',
|
@@ -12,7 +12,7 @@ module ChefZero
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def populate_defaults(request, response_json)
|
15
|
-
DataBagItemEndpoint::populate_defaults(request, response_json, request.rest_path[
|
15
|
+
DataBagItemEndpoint::populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.populate_defaults(request, response_json, data_bag, data_bag_item)
|
@@ -10,10 +10,10 @@ module ChefZero
|
|
10
10
|
name = JSON.parse(contents, :create_additions => false)[identity_key]
|
11
11
|
if name.nil?
|
12
12
|
error(400, "Must specify '#{identity_key}' in JSON")
|
13
|
-
elsif exists_data_dir?(request, ['data', name])
|
13
|
+
elsif exists_data_dir?(request, request.rest_path[0..1] + ['data', name])
|
14
14
|
error(409, "Object already exists")
|
15
15
|
else
|
16
|
-
data_store.create_dir(['data'], name, :recursive)
|
16
|
+
data_store.create_dir(request.rest_path[0..1] + ['data'], name, :recursive)
|
17
17
|
json_response(201, {"uri" => "#{build_uri(request.base_uri, request.rest_path + [name])}"})
|
18
18
|
end
|
19
19
|
end
|
@@ -6,10 +6,10 @@ module ChefZero
|
|
6
6
|
# /environments/NAME/cookbooks/NAME
|
7
7
|
class EnvironmentCookbookEndpoint < CookbooksBase
|
8
8
|
def get(request)
|
9
|
-
cookbook_name = request.rest_path[
|
10
|
-
environment = JSON.parse(get_data(request, request.rest_path[0..
|
9
|
+
cookbook_name = request.rest_path[5]
|
10
|
+
environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
|
11
11
|
constraints = environment['cookbook_versions'] || {}
|
12
|
-
cookbook_versions = list_data(request, request.rest_path[
|
12
|
+
cookbook_versions = list_data(request, request.rest_path[0..1] + request.rest_path[4..5])
|
13
13
|
if request.query_params['num_versions'] == 'all'
|
14
14
|
num_versions = nil
|
15
15
|
elsif request.query_params['num_versions']
|
@@ -8,7 +8,7 @@ module ChefZero
|
|
8
8
|
class EnvironmentCookbookVersionsEndpoint < RestBase
|
9
9
|
|
10
10
|
def post(request)
|
11
|
-
cookbook_names = list_data(request, ['cookbooks'])
|
11
|
+
cookbook_names = list_data(request, request.rest_path[0..1] + ['cookbooks'])
|
12
12
|
|
13
13
|
# Get the list of cookbooks and versions desired by the runlist
|
14
14
|
desired_versions = {}
|
@@ -16,17 +16,17 @@ module ChefZero
|
|
16
16
|
run_list.each do |run_list_entry|
|
17
17
|
if run_list_entry =~ /(.+)::.+\@(.+)/ || run_list_entry =~ /(.+)\@(.+)/
|
18
18
|
raise RestErrorResponse.new(412, "No such cookbook: #{$1}") if !cookbook_names.include?($1)
|
19
|
-
raise RestErrorResponse.new(412, "No such cookbook version for cookbook #{$1}: #{$2}") if !list_data(request, ['cookbooks', $1]).include?($2)
|
19
|
+
raise RestErrorResponse.new(412, "No such cookbook version for cookbook #{$1}: #{$2}") if !list_data(request, request.rest_path[0..1] + ['cookbooks', $1]).include?($2)
|
20
20
|
desired_versions[$1] = [ $2 ]
|
21
21
|
else
|
22
22
|
desired_cookbook = run_list_entry.split('::')[0]
|
23
23
|
raise RestErrorResponse.new(412, "No such cookbook: #{desired_cookbook}") if !cookbook_names.include?(desired_cookbook)
|
24
|
-
desired_versions[desired_cookbook] = list_data(request, ['cookbooks', desired_cookbook])
|
24
|
+
desired_versions[desired_cookbook] = list_data(request, request.rest_path[0..1] + ['cookbooks', desired_cookbook])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
# Filter by environment constraints
|
29
|
-
environment = JSON.parse(get_data(request, request.rest_path[0..
|
29
|
+
environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
|
30
30
|
environment_constraints = environment['cookbook_versions'] || {}
|
31
31
|
|
32
32
|
desired_versions.each_key do |name|
|
@@ -48,8 +48,8 @@ module ChefZero
|
|
48
48
|
|
49
49
|
result = {}
|
50
50
|
solved.each_pair do |name, versions|
|
51
|
-
cookbook = JSON.parse(get_data(request, ['cookbooks', name, versions[0]]), :create_additions => false)
|
52
|
-
result[name] = DataNormalizer.normalize_cookbook(cookbook, name, versions[0], request.base_uri, 'MIN')
|
51
|
+
cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
|
52
|
+
result[name] = DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
|
53
53
|
end
|
54
54
|
json_response(200, result)
|
55
55
|
end
|
@@ -74,7 +74,7 @@ module ChefZero
|
|
74
74
|
new_unsolved = unsolved[1..-1]
|
75
75
|
|
76
76
|
# Pick this cookbook, and add dependencies
|
77
|
-
cookbook_obj = JSON.parse(get_data(request, ['cookbooks', solve_for, desired_version]), :create_additions => false)
|
77
|
+
cookbook_obj = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
|
78
78
|
cookbook_metadata = cookbook_obj['metadata'] || {}
|
79
79
|
cookbook_dependencies = cookbook_metadata['dependencies'] || {}
|
80
80
|
dep_not_found = false
|
@@ -84,12 +84,12 @@ module ChefZero
|
|
84
84
|
if !new_desired_versions.has_key?(dep_name)
|
85
85
|
new_unsolved = new_unsolved + [dep_name]
|
86
86
|
# If the dep is missing, we will try other versions of the cookbook that might not have the bad dep.
|
87
|
-
if !exists_data_dir?(request, ['cookbooks', dep_name])
|
87
|
+
if !exists_data_dir?(request, request.rest_path[0..1] + ['cookbooks', dep_name])
|
88
88
|
@last_missing_dep = dep_name.to_s
|
89
89
|
dep_not_found = true
|
90
90
|
break
|
91
91
|
end
|
92
|
-
new_desired_versions[dep_name] = list_data(request, ['cookbooks', dep_name])
|
92
|
+
new_desired_versions[dep_name] = list_data(request, request.rest_path[0..1] + ['cookbooks', dep_name])
|
93
93
|
new_desired_versions = filter_by_constraint(new_desired_versions, dep_name, environment_constraints[dep_name])
|
94
94
|
end
|
95
95
|
new_desired_versions = filter_by_constraint(new_desired_versions, dep_name, dep_constraint)
|
@@ -6,7 +6,7 @@ module ChefZero
|
|
6
6
|
# /environments/NAME/cookbooks
|
7
7
|
class EnvironmentCookbooksEndpoint < CookbooksBase
|
8
8
|
def get(request)
|
9
|
-
environment = JSON.parse(get_data(request, request.rest_path[0..
|
9
|
+
environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
|
10
10
|
constraints = environment['cookbook_versions'] || {}
|
11
11
|
if request.query_params['num_versions'] == 'all'
|
12
12
|
num_versions = nil
|
@@ -15,7 +15,7 @@ module ChefZero
|
|
15
15
|
else
|
16
16
|
num_versions = 1
|
17
17
|
end
|
18
|
-
json_response(200, format_cookbooks_list(request, all_cookbooks_list, constraints, num_versions))
|
18
|
+
json_response(200, format_cookbooks_list(request, all_cookbooks_list(request), constraints, num_versions))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -7,7 +7,7 @@ module ChefZero
|
|
7
7
|
# /environments/NAME
|
8
8
|
class EnvironmentEndpoint < RestObjectEndpoint
|
9
9
|
def delete(request)
|
10
|
-
if request.rest_path[
|
10
|
+
if request.rest_path[3] == "_default"
|
11
11
|
# 405, really?
|
12
12
|
error(405, "The '_default' environment cannot be modified.")
|
13
13
|
else
|
@@ -16,7 +16,7 @@ module ChefZero
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def put(request)
|
19
|
-
if request.rest_path[
|
19
|
+
if request.rest_path[3] == "_default"
|
20
20
|
error(405, "The '_default' environment cannot be modified.")
|
21
21
|
else
|
22
22
|
super(request)
|
@@ -25,7 +25,7 @@ module ChefZero
|
|
25
25
|
|
26
26
|
def populate_defaults(request, response_json)
|
27
27
|
response = JSON.parse(response_json, :create_additions => false)
|
28
|
-
response = DataNormalizer.normalize_environment(response, request.rest_path[
|
28
|
+
response = DataNormalizer.normalize_environment(response, request.rest_path[3])
|
29
29
|
JSON.pretty_generate(response)
|
30
30
|
end
|
31
31
|
end
|
@@ -7,13 +7,13 @@ module ChefZero
|
|
7
7
|
class EnvironmentNodesEndpoint < RestBase
|
8
8
|
def get(request)
|
9
9
|
# 404 if environment does not exist
|
10
|
-
get_data(request, request.rest_path[0..
|
10
|
+
get_data(request, request.rest_path[0..3])
|
11
11
|
|
12
12
|
result = {}
|
13
|
-
list_data(request, ['nodes']).each do |name|
|
14
|
-
node = JSON.parse(get_data(request, ['nodes', name]), :create_additions => false)
|
15
|
-
if node['chef_environment'] == request.rest_path[
|
16
|
-
result[name] = build_uri(request.base_uri, ['nodes', name])
|
13
|
+
list_data(request, request.rest_path[0..1] + ['nodes']).each do |name|
|
14
|
+
node = JSON.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
|
15
|
+
if node['chef_environment'] == request.rest_path[3]
|
16
|
+
result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['nodes', name])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
json_response(200, result)
|
@@ -6,12 +6,12 @@ module ChefZero
|
|
6
6
|
# /environment/NAME/recipes
|
7
7
|
class EnvironmentRecipesEndpoint < CookbooksBase
|
8
8
|
def get(request)
|
9
|
-
environment = JSON.parse(get_data(request, request.rest_path[0..
|
9
|
+
environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
|
10
10
|
constraints = environment['cookbook_versions'] || {}
|
11
11
|
result = []
|
12
|
-
filter_cookbooks(all_cookbooks_list, constraints, 1) do |name, versions|
|
12
|
+
filter_cookbooks(all_cookbooks_list(request), constraints, 1) do |name, versions|
|
13
13
|
if versions.size > 0
|
14
|
-
cookbook = JSON.parse(get_data(request, ['cookbooks', name, versions[0]]), :create_additions => false)
|
14
|
+
cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
|
15
15
|
result += recipe_names(name, cookbook)
|
16
16
|
end
|
17
17
|
end
|
@@ -8,18 +8,18 @@ module ChefZero
|
|
8
8
|
class EnvironmentRoleEndpoint < CookbooksBase
|
9
9
|
def get(request)
|
10
10
|
# 404 if environment does not exist
|
11
|
-
if request.rest_path[
|
12
|
-
environment_path = request.rest_path[0..1]
|
13
|
-
role_path = request.rest_path[
|
11
|
+
if request.rest_path[2] == 'environments'
|
12
|
+
environment_path = request.rest_path[0..1] + request.rest_path[2..3]
|
13
|
+
role_path = request.rest_path[0..1] + request.rest_path[4..5]
|
14
14
|
else
|
15
|
-
environment_path = request.rest_path[
|
16
|
-
role_path = request.rest_path[0..1]
|
15
|
+
environment_path = request.rest_path[0..1] + request.rest_path[4..5]
|
16
|
+
role_path = request.rest_path[0..1] + request.rest_path[2..3]
|
17
17
|
end
|
18
18
|
# Verify that the environment exists
|
19
19
|
get_data(request, environment_path)
|
20
20
|
|
21
21
|
role = JSON.parse(get_data(request, role_path), :create_additions => false)
|
22
|
-
environment_name = environment_path[
|
22
|
+
environment_name = environment_path[3]
|
23
23
|
if environment_name == '_default'
|
24
24
|
run_list = role['run_list']
|
25
25
|
else
|
@@ -8,7 +8,7 @@ module ChefZero
|
|
8
8
|
class NodeEndpoint < RestObjectEndpoint
|
9
9
|
def populate_defaults(request, response_json)
|
10
10
|
node = JSON.parse(response_json, :create_additions => false)
|
11
|
-
node = DataNormalizer.normalize_node(node, request.rest_path[
|
11
|
+
node = DataNormalizer.normalize_node(node, request.rest_path[3])
|
12
12
|
JSON.pretty_generate(node)
|
13
13
|
end
|
14
14
|
end
|
@@ -8,11 +8,11 @@ module ChefZero
|
|
8
8
|
class PrincipalEndpoint < RestBase
|
9
9
|
def get(request)
|
10
10
|
name = request.rest_path[-1]
|
11
|
-
json = get_data(request, [ 'users', name ], :nil)
|
11
|
+
json = get_data(request, request.rest_path[0..1] + [ 'users', name ], :nil)
|
12
12
|
if json
|
13
13
|
type = 'user'
|
14
14
|
else
|
15
|
-
json = get_data(request, [ 'clients', name ], :nil)
|
15
|
+
json = get_data(request, request.rest_path[0..1] + [ 'clients', name ], :nil)
|
16
16
|
type = 'client'
|
17
17
|
end
|
18
18
|
if json
|
@@ -26,15 +26,16 @@ module ChefZero
|
|
26
26
|
rename = key != request.rest_path[-1]
|
27
27
|
if rename
|
28
28
|
begin
|
29
|
-
data_store.create(request.rest_path[0..-2], key, request.body)
|
29
|
+
data_store.create(request.rest_path[0..1] + request.rest_path[2..-2], key, request.body)
|
30
30
|
rescue DataStore::DataAlreadyExistsError
|
31
31
|
return error(409, "Cannot rename '#{request.rest_path[-1]}' to '#{key}': '#{key}' already exists")
|
32
32
|
end
|
33
33
|
delete_data(request)
|
34
|
+
already_json_response(201, populate_defaults(request, request.body))
|
34
35
|
else
|
35
36
|
set_data(request, request.rest_path, request.body)
|
37
|
+
already_json_response(200, populate_defaults(request, request.body))
|
36
38
|
end
|
37
|
-
already_json_response(200, populate_defaults(request, request.body))
|
38
39
|
end
|
39
40
|
|
40
41
|
def delete(request)
|
@@ -58,4 +59,3 @@ module ChefZero
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
@@ -8,7 +8,7 @@ module ChefZero
|
|
8
8
|
class RoleEndpoint < RestObjectEndpoint
|
9
9
|
def populate_defaults(request, response_json)
|
10
10
|
role = JSON.parse(response_json, :create_additions => false)
|
11
|
-
role = DataNormalizer.normalize_role(role, request.rest_path[
|
11
|
+
role = DataNormalizer.normalize_role(role, request.rest_path[3])
|
12
12
|
JSON.pretty_generate(role)
|
13
13
|
end
|
14
14
|
end
|
@@ -6,7 +6,7 @@ module ChefZero
|
|
6
6
|
# /roles/NAME/environments
|
7
7
|
class RoleEnvironmentsEndpoint < RestBase
|
8
8
|
def get(request)
|
9
|
-
role = JSON.parse(get_data(request, request.rest_path[0..
|
9
|
+
role = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
|
10
10
|
json_response(200, [ '_default' ] + (role['env_run_lists'].keys || []))
|
11
11
|
end
|
12
12
|
end
|
@@ -9,14 +9,14 @@ module ChefZero
|
|
9
9
|
def put(request)
|
10
10
|
existing_sandbox = JSON.parse(get_data(request), :create_additions => false)
|
11
11
|
existing_sandbox['checksums'].each do |checksum|
|
12
|
-
if !exists_data?(request, ['file_store', 'checksums', checksum])
|
12
|
+
if !exists_data?(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum])
|
13
13
|
raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
delete_data(request)
|
17
17
|
json_response(200, {
|
18
|
-
:guid => request.rest_path[
|
19
|
-
:name => request.rest_path[
|
18
|
+
:guid => request.rest_path[3],
|
19
|
+
:name => request.rest_path[3],
|
20
20
|
:checksums => existing_sandbox['checksums'],
|
21
21
|
:create_time => existing_sandbox['create_time'],
|
22
22
|
:is_completed => true
|
@@ -16,12 +16,12 @@ module ChefZero
|
|
16
16
|
needed_checksums = JSON.parse(request.body, :create_additions => false)['checksums']
|
17
17
|
result_checksums = {}
|
18
18
|
needed_checksums.keys.each do |needed_checksum|
|
19
|
-
if list_data(request, ['file_store', 'checksums']).include?(needed_checksum)
|
19
|
+
if list_data(request, request.rest_path[0..1] + ['file_store', 'checksums']).include?(needed_checksum)
|
20
20
|
result_checksums[needed_checksum] = { :needs_upload => false }
|
21
21
|
else
|
22
22
|
result_checksums[needed_checksum] = {
|
23
23
|
:needs_upload => true,
|
24
|
-
:url => build_uri(request.base_uri, ['file_store', 'checksums', needed_checksum])
|
24
|
+
:url => build_uri(request.base_uri, request.rest_path[0..1] + ['file_store', 'checksums', needed_checksum])
|
25
25
|
}
|
26
26
|
sandbox_checksums << needed_checksum
|
27
27
|
end
|
@@ -48,4 +48,3 @@ module ChefZero
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
@@ -46,18 +46,22 @@ module ChefZero
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def search_container(request, index)
|
49
|
-
case index
|
49
|
+
relative_parts, normalize_proc = case index
|
50
50
|
when 'client'
|
51
|
-
[ ['clients'], Proc.new { |client, name| DataNormalizer.normalize_client(client, name) }
|
51
|
+
[ ['clients'], Proc.new { |client, name| DataNormalizer.normalize_client(client, name) } ]
|
52
52
|
when 'node'
|
53
|
-
[ ['nodes'], Proc.new { |node, name| DataNormalizer.normalize_node(node, name) }
|
53
|
+
[ ['nodes'], Proc.new { |node, name| DataNormalizer.normalize_node(node, name) } ]
|
54
54
|
when 'environment'
|
55
|
-
[ ['environments'], Proc.new { |environment, name| DataNormalizer.normalize_environment(environment, name) }
|
55
|
+
[ ['environments'], Proc.new { |environment, name| DataNormalizer.normalize_environment(environment, name) } ]
|
56
56
|
when 'role'
|
57
|
-
[ ['roles'], Proc.new { |role, name| DataNormalizer.normalize_role(role, name) }
|
57
|
+
[ ['roles'], Proc.new { |role, name| DataNormalizer.normalize_role(role, name) } ]
|
58
58
|
else
|
59
|
-
[ ['data', index], Proc.new { |data_bag_item, id| DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') }
|
59
|
+
[ ['data', index], Proc.new { |data_bag_item, id| DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') } ]
|
60
60
|
end
|
61
|
+
[
|
62
|
+
request.rest_path[0..1] + relative_parts,
|
63
|
+
normalize_proc
|
64
|
+
]
|
61
65
|
end
|
62
66
|
|
63
67
|
def expand_for_indexing(value, index, id)
|
@@ -90,7 +94,7 @@ module ChefZero
|
|
90
94
|
|
91
95
|
def search(request)
|
92
96
|
# Extract parameters
|
93
|
-
index = request.rest_path[
|
97
|
+
index = request.rest_path[3]
|
94
98
|
query_string = request.query_params['q'] || '*:*'
|
95
99
|
solr_query = ChefZero::Solr::SolrParser.new(query_string).parse
|
96
100
|
sort_string = request.query_params['sort']
|
@@ -100,14 +104,14 @@ module ChefZero
|
|
100
104
|
rows = rows.to_i if rows
|
101
105
|
|
102
106
|
# Get the search container
|
103
|
-
container, expander
|
107
|
+
container, expander = search_container(request, index)
|
104
108
|
|
105
109
|
# Search!
|
106
110
|
result = []
|
107
111
|
list_data(request, container).each do |name|
|
108
112
|
value = get_data(request, container + [name])
|
109
113
|
expanded = expander.call(JSON.parse(value, :create_additions => false), name)
|
110
|
-
result << [ name, build_uri(base_uri, [name]), expanded, expand_for_indexing(expanded, index, name) ]
|
114
|
+
result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ]
|
111
115
|
end
|
112
116
|
result = result.select do |name, uri, value, search_value|
|
113
117
|
solr_query.matches_doc?(ChefZero::Solr::SolrDoc.new(search_value, name))
|
@@ -7,7 +7,7 @@ module ChefZero
|
|
7
7
|
def get(request)
|
8
8
|
# Get the result
|
9
9
|
result_hash = {}
|
10
|
-
indices = (%w(client environment node role) + data_store.list(['data'])).sort
|
10
|
+
indices = (%w(client environment node role) + data_store.list(request.rest_path[0..1] + ['data'])).sort
|
11
11
|
indices.each do |index|
|
12
12
|
result_hash[index] = build_uri(request.base_uri, request.rest_path + [index])
|
13
13
|
end
|
data/lib/chef_zero/rest_base.rb
CHANGED
@@ -28,6 +28,7 @@ module ChefZero
|
|
28
28
|
begin
|
29
29
|
self.send(method, request)
|
30
30
|
rescue RestErrorResponse => e
|
31
|
+
ChefZero::Log.debug("#{e.inspect}\n#{e.backtrace.join("\n")}")
|
31
32
|
error(e.response_code, e.error)
|
32
33
|
end
|
33
34
|
end
|
@@ -119,11 +120,18 @@ module ChefZero
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def build_uri(base_uri, rest_path)
|
122
|
-
|
123
|
+
if server.options[:single_org]
|
124
|
+
# Strip off /organizations/chef if we are in single org mode
|
125
|
+
if rest_path[0..1] != [ 'organizations', 'chef' ]
|
126
|
+
raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode"
|
127
|
+
end
|
128
|
+
"#{base_uri}/#{rest_path[2..-1].join('/')}"
|
129
|
+
else
|
130
|
+
"#{base_uri}/#{rest_path.join('/')}"
|
131
|
+
end
|
123
132
|
end
|
124
133
|
|
125
134
|
def self.build_uri(base_uri, rest_path)
|
126
|
-
"#{base_uri}/#{rest_path.join('/')}"
|
127
135
|
end
|
128
136
|
|
129
137
|
def populate_defaults(request, response)
|