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,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "chef_zero/rest_base"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
module Endpoints
|
@@ -8,7 +8,7 @@ module ChefZero
|
|
8
8
|
DEFAULT_PUBLIC_KEY_NAME = "default"
|
9
9
|
DATE_FORMAT = "%FT%TZ" # e.g. 2015-12-24T21:00:00Z
|
10
10
|
|
11
|
-
def get(request, alt_uri_root=nil)
|
11
|
+
def get(request, alt_uri_root = nil)
|
12
12
|
path = data_path(request)
|
13
13
|
|
14
14
|
# Get actor or 404 if it doesn't exist
|
@@ -35,7 +35,7 @@ module ChefZero
|
|
35
35
|
if generate_keys
|
36
36
|
private_key, public_key = server.gen_key_pair
|
37
37
|
else
|
38
|
-
public_key = request_body[
|
38
|
+
public_key = request_body["public_key"]
|
39
39
|
end
|
40
40
|
|
41
41
|
key_name = request_body["name"]
|
@@ -74,7 +74,6 @@ module ChefZero
|
|
74
74
|
|
75
75
|
actor_data["public_key"] = public_key
|
76
76
|
set_data(request, actor_path(request), to_json(actor_data))
|
77
|
-
|
78
77
|
end
|
79
78
|
|
80
79
|
# Returns the keys data store path, which is the same as
|
@@ -90,7 +89,7 @@ module ChefZero
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
def list_key(request, data_path, alt_uri_root=nil)
|
92
|
+
def list_key(request, data_path, alt_uri_root = nil)
|
94
93
|
key_name, expiration_date =
|
95
94
|
if data_path[-1] == DEFAULT_PUBLIC_KEY_NAME
|
96
95
|
[ DEFAULT_PUBLIC_KEY_NAME, "infinity" ]
|
@@ -111,7 +110,7 @@ module ChefZero
|
|
111
110
|
request.rest_path[2] == "clients"
|
112
111
|
end
|
113
112
|
|
114
|
-
def key_uri(request, key_name, alt_uri_root=nil)
|
113
|
+
def key_uri(request, key_name, alt_uri_root = nil)
|
115
114
|
uri_root = alt_uri_root.nil? ? request.rest_path : alt_uri_root
|
116
115
|
build_uri(request.base_uri, [ *uri_root, key_name ])
|
117
116
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_list_endpoint"
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module Endpoints
|
@@ -10,13 +10,13 @@ module ChefZero
|
|
10
10
|
|
11
11
|
# apply query filters: if one applies, stop processing rest
|
12
12
|
# (precendence matches chef-server: https://github.com/chef/chef-server/blob/268a0c9/src/oc_erchef/apps/chef_objects/src/chef_user.erl#L554-L559)
|
13
|
-
if value = request.query_params[
|
14
|
-
response[2] = filter(
|
15
|
-
elsif value = request.query_params[
|
16
|
-
response[2] = filter(
|
13
|
+
if value = request.query_params["external_authentication_uid"]
|
14
|
+
response[2] = filter("external_authentication_uid", value, request, response[2])
|
15
|
+
elsif value = request.query_params["email"]
|
16
|
+
response[2] = filter("email", value, request, response[2])
|
17
17
|
end
|
18
18
|
|
19
|
-
if request.query_params[
|
19
|
+
if request.query_params["verbose"]
|
20
20
|
results = parse_json(response[2])
|
21
21
|
results.each do |name, url|
|
22
22
|
record = get_data(request, request.rest_path + [ name ], :nil)
|
@@ -35,16 +35,16 @@ module ChefZero
|
|
35
35
|
# First, find out if the user actually posted a public key. If not, make
|
36
36
|
# one.
|
37
37
|
request_body = parse_json(request.body)
|
38
|
-
public_key = request_body[
|
38
|
+
public_key = request_body["public_key"]
|
39
39
|
|
40
40
|
skip_key_create = !request.api_v0? && !request_body["create_key"]
|
41
41
|
|
42
42
|
if !public_key && !skip_key_create
|
43
43
|
private_key, public_key = server.gen_key_pair
|
44
|
-
request_body[
|
44
|
+
request_body["public_key"] = public_key
|
45
45
|
request.body = to_json(request_body)
|
46
46
|
elsif skip_key_create
|
47
|
-
request_body[
|
47
|
+
request_body["public_key"] = nil
|
48
48
|
request.body = to_json(request_body)
|
49
49
|
end
|
50
50
|
|
@@ -55,8 +55,8 @@ module ChefZero
|
|
55
55
|
user_data = parse_json(result[2])
|
56
56
|
|
57
57
|
key_data = {}
|
58
|
-
key_data[
|
59
|
-
key_data[
|
58
|
+
key_data["private_key"] = private_key if private_key
|
59
|
+
key_data["public_key"] = public_key unless request.rest_path[0] == "users"
|
60
60
|
|
61
61
|
response =
|
62
62
|
if request.api_v0?
|
@@ -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,23 +7,23 @@ module ChefZero
|
|
7
7
|
class AuthenticateUserEndpoint < RestBase
|
8
8
|
def post(request)
|
9
9
|
request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
|
10
|
-
name = request_json[
|
11
|
-
password = request_json[
|
10
|
+
name = request_json["username"]
|
11
|
+
password = request_json["password"]
|
12
12
|
begin
|
13
|
-
user = data_store.get([
|
13
|
+
user = data_store.get(["users", name])
|
14
14
|
rescue ChefZero::DataStore::DataNotFoundError
|
15
15
|
raise RestErrorResponse.new(401, "Bad username or password")
|
16
16
|
end
|
17
17
|
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
|
18
|
-
user = ChefData::DataNormalizer.normalize_user(user, name, [
|
19
|
-
if user[
|
18
|
+
user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat])
|
19
|
+
if user["password"] != password
|
20
20
|
raise RestErrorResponse.new(401, "Bad username or password")
|
21
21
|
end
|
22
22
|
# Include only particular user data in the response
|
23
|
-
user.keep_if { |key,value| %w
|
23
|
+
user.keep_if { |key, value| %w{first_name last_name display_name email username}.include?(key) }
|
24
24
|
json_response(200, {
|
25
|
-
|
26
|
-
|
25
|
+
"status" => "linked",
|
26
|
+
"user" => user,
|
27
27
|
})
|
28
28
|
end
|
29
29
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_object_endpoint"
|
3
|
+
require "chef_zero/chef_data/data_normalizer"
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module Endpoints
|
7
7
|
# /organizations/ORG/containers/NAME
|
8
8
|
class ContainerEndpoint < RestObjectEndpoint
|
9
9
|
def initialize(server)
|
10
|
-
super(server, %w
|
10
|
+
super(server, %w{id containername})
|
11
11
|
end
|
12
12
|
|
13
13
|
undef_method(:put)
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_list_endpoint"
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module Endpoints
|
6
6
|
# /organizations/ORG/containers
|
7
7
|
class ContainersEndpoint < RestListEndpoint
|
8
8
|
def initialize(server)
|
9
|
-
super(server, %w
|
9
|
+
super(server, %w{id containername})
|
10
10
|
end
|
11
11
|
|
12
12
|
# create a container.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "chef_zero/endpoints/cookbooks_base"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
module Endpoints
|
@@ -7,19 +7,19 @@ module ChefZero
|
|
7
7
|
def get(request)
|
8
8
|
filter = request.rest_path[3]
|
9
9
|
case filter
|
10
|
-
when
|
10
|
+
when "_latest"
|
11
11
|
result = {}
|
12
12
|
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
|
13
13
|
if versions.size > 0
|
14
|
-
result[name] = build_uri(request.base_uri, request.rest_path[0..1] + [
|
14
|
+
result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, versions[0]])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
json_response(200, result)
|
18
|
-
when
|
18
|
+
when "_recipes"
|
19
19
|
result = []
|
20
20
|
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
|
21
21
|
if versions.size > 0
|
22
|
-
cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + [
|
22
|
+
cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false)
|
23
23
|
result += recipe_names(name, cookbook)
|
24
24
|
end
|
25
25
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_object_endpoint"
|
3
|
+
require "chef_zero/rest_error_response"
|
4
|
+
require "chef_zero/chef_data/data_normalizer"
|
5
|
+
require "chef_zero/data_store/data_not_found_error"
|
6
6
|
|
7
7
|
module ChefZero
|
8
8
|
module Endpoints
|
@@ -23,14 +23,14 @@ module ChefZero
|
|
23
23
|
# Honor frozen
|
24
24
|
if existing_cookbook
|
25
25
|
existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false)
|
26
|
-
if existing_cookbook_json[
|
27
|
-
if request.query_params[
|
26
|
+
if existing_cookbook_json["frozen?"]
|
27
|
+
if request.query_params["force"] != "true"
|
28
28
|
raise RestErrorResponse.new(409, "The cookbook #{name} at version #{version} is frozen. Use the 'force' option to override.")
|
29
29
|
end
|
30
30
|
# For some reason, you are forever unable to modify "frozen?" on a frozen cookbook.
|
31
31
|
request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
|
32
|
-
if !request_body[
|
33
|
-
request_body[
|
32
|
+
if !request_body["frozen?"]
|
33
|
+
request_body["frozen?"] = true
|
34
34
|
request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
|
35
35
|
end
|
36
36
|
end
|
@@ -74,8 +74,8 @@ module ChefZero
|
|
74
74
|
FFI_Yajl::Parser.parse(cookbook, :create_additions => false).each_pair do |key, value|
|
75
75
|
if value.is_a?(Array)
|
76
76
|
value.each do |file|
|
77
|
-
if file.is_a?(Hash) && file.has_key?(
|
78
|
-
result << file[
|
77
|
+
if file.is_a?(Hash) && file.has_key?("checksum")
|
78
|
+
result << file["checksum"]
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -86,7 +86,7 @@ module ChefZero
|
|
86
86
|
private
|
87
87
|
|
88
88
|
def hoover_unused_checksums(deleted_checksums, request)
|
89
|
-
%w
|
89
|
+
%w{cookbooks cookbook_artifacts}.each do |cookbook_type|
|
90
90
|
begin
|
91
91
|
cookbooks = data_store.list(request.rest_path[0..1] + [cookbook_type])
|
92
92
|
rescue ChefZero::DataStore::DataNotFoundError
|
@@ -95,9 +95,13 @@ module ChefZero
|
|
95
95
|
cookbooks = []
|
96
96
|
end
|
97
97
|
cookbooks.each do |cookbook_name|
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
# as below, this can be racy.
|
99
|
+
begin
|
100
|
+
data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version|
|
101
|
+
cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request)
|
102
|
+
deleted_checksums = deleted_checksums - get_checksums(cookbook)
|
103
|
+
end
|
104
|
+
rescue ChefZero::DataStore::DataNotFoundError
|
101
105
|
end
|
102
106
|
end
|
103
107
|
end
|
@@ -106,7 +110,7 @@ module ChefZero
|
|
106
110
|
# This deals with an exception on delete, but things can still get deleted
|
107
111
|
# that shouldn't be.
|
108
112
|
begin
|
109
|
-
delete_data(request, request.rest_path[0..1] + [
|
113
|
+
delete_data(request, request.rest_path[0..1] + ["file_store", "checksums", checksum], :data_store_exceptions)
|
110
114
|
rescue ChefZero::DataStore::DataNotFoundError
|
111
115
|
end
|
112
116
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/rest_base"
|
3
|
+
require "chef_zero/chef_data/data_normalizer"
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module Endpoints
|
@@ -11,13 +11,13 @@ 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
|
-
|
15
|
-
|
14
|
+
"url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, version]),
|
15
|
+
"version" => version,
|
16
16
|
}
|
17
17
|
end
|
18
18
|
results[name] = {
|
19
|
-
|
20
|
-
|
19
|
+
"url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name]),
|
20
|
+
"versions" => versions_list,
|
21
21
|
}
|
22
22
|
end
|
23
23
|
results
|
@@ -26,8 +26,8 @@ module ChefZero
|
|
26
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(request.rest_path[0..1] + [
|
30
|
-
result[name] = data_store.list(request.rest_path[0..1] + [
|
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
|
@@ -48,10 +48,10 @@ module ChefZero
|
|
48
48
|
|
49
49
|
def recipe_names(cookbook_name, cookbook)
|
50
50
|
result = []
|
51
|
-
if cookbook[
|
52
|
-
cookbook[
|
53
|
-
if recipe[
|
54
|
-
if recipe[
|
51
|
+
if cookbook["recipes"]
|
52
|
+
cookbook["recipes"].each do |recipe|
|
53
|
+
if recipe["path"] == "recipes/#{recipe['name']}" && recipe["name"][-3..-1] == ".rb"
|
54
|
+
if recipe["name"] == "default.rb"
|
55
55
|
result << cookbook_name
|
56
56
|
end
|
57
57
|
result << "#{cookbook_name}::#{recipe['name'][0..-4]}"
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "chef_zero/endpoints/cookbooks_base"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
module Endpoints
|
5
5
|
# /cookbooks
|
6
6
|
class CookbooksEndpoint < CookbooksBase
|
7
7
|
def get(request)
|
8
|
-
if request.query_params[
|
8
|
+
if request.query_params["num_versions"] == "all"
|
9
9
|
num_versions = nil
|
10
|
-
elsif request.query_params[
|
11
|
-
num_versions = request.query_params[
|
10
|
+
elsif request.query_params["num_versions"]
|
11
|
+
num_versions = request.query_params["num_versions"].to_i
|
12
12
|
else
|
13
13
|
num_versions = 1
|
14
14
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_list_endpoint"
|
3
|
+
require "chef_zero/endpoints/data_bag_item_endpoint"
|
4
|
+
require "chef_zero/rest_error_response"
|
5
5
|
|
6
6
|
module ChefZero
|
7
7
|
module Endpoints
|
8
8
|
# /data/NAME
|
9
9
|
class DataBagEndpoint < RestListEndpoint
|
10
10
|
def initialize(server)
|
11
|
-
super(server,
|
11
|
+
super(server, "id")
|
12
12
|
end
|
13
13
|
|
14
14
|
def post(request)
|
@@ -16,7 +16,7 @@ module ChefZero
|
|
16
16
|
key = identity_keys.map { |k| json[k] }.select { |v| v }.first
|
17
17
|
response = super(request)
|
18
18
|
if response[0] == 201
|
19
|
-
already_json_response(201, DataBagItemEndpoint
|
19
|
+
already_json_response(201, DataBagItemEndpoint.populate_defaults(request, request.body, request.rest_path[3], key))
|
20
20
|
else
|
21
21
|
response
|
22
22
|
end
|
@@ -24,10 +24,10 @@ module ChefZero
|
|
24
24
|
|
25
25
|
def get_key(contents)
|
26
26
|
data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false)
|
27
|
-
if data_bag_item[
|
28
|
-
data_bag_item[
|
27
|
+
if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
|
28
|
+
data_bag_item["raw_data"]["id"]
|
29
29
|
else
|
30
|
-
data_bag_item[
|
30
|
+
data_bag_item["id"]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,9 +35,9 @@ module ChefZero
|
|
35
35
|
key = request.rest_path[3]
|
36
36
|
delete_data_dir(request, request.rest_path, :recursive)
|
37
37
|
json_response(200, {
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
"chef_type" => "data_bag",
|
39
|
+
"json_class" => "Chef::DataBag",
|
40
|
+
"name" => key,
|
41
41
|
})
|
42
42
|
end
|
43
43
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/endpoints/rest_object_endpoint"
|
3
|
+
require "chef_zero/endpoints/data_bag_item_endpoint"
|
4
|
+
require "chef_zero/chef_data/data_normalizer"
|
5
5
|
|
6
6
|
module ChefZero
|
7
7
|
module Endpoints
|
8
8
|
# /data/NAME/NAME
|
9
9
|
class DataBagItemEndpoint < RestObjectEndpoint
|
10
10
|
def initialize(server)
|
11
|
-
super(server,
|
11
|
+
super(server, "id")
|
12
12
|
end
|
13
13
|
|
14
14
|
def populate_defaults(request, response_json)
|
15
|
-
DataBagItemEndpoint
|
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)
|