chef-zero 2.2.1 → 3.0.0.rc.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/README.md +2 -0
- data/Rakefile +5 -1
- data/bin/chef-zero +17 -0
- data/lib/chef_zero/chef_data/acl_path.rb +139 -0
- data/lib/chef_zero/chef_data/cookbook_data.rb +240 -0
- data/lib/chef_zero/chef_data/data_normalizer.rb +207 -0
- data/lib/chef_zero/chef_data/default_creator.rb +446 -0
- data/lib/chef_zero/data_store/default_facade.rb +149 -0
- data/lib/chef_zero/data_store/interface_v1.rb +18 -0
- data/lib/chef_zero/data_store/memory_store.rb +2 -1
- data/lib/chef_zero/data_store/memory_store_v2.rb +3 -36
- data/lib/chef_zero/data_store/raw_file_store.rb +147 -0
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +39 -103
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +1 -1
- data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -0
- data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -0
- data/lib/chef_zero/endpoints/actor_endpoint.rb +36 -10
- data/lib/chef_zero/endpoints/actors_endpoint.rb +38 -6
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +15 -9
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -0
- data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -0
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +15 -14
- data/lib/chef_zero/endpoints/cookbooks_base.rb +2 -2
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +5 -4
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/environment_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/group_endpoint.rb +20 -0
- data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -0
- data/lib/chef_zero/endpoints/license_endpoint.rb +25 -0
- data/lib/chef_zero/endpoints/node_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -0
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +29 -0
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -0
- data/lib/chef_zero/endpoints/organization_endpoint.rb +41 -0
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +48 -0
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +14 -0
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -0
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +55 -0
- data/lib/chef_zero/endpoints/principal_endpoint.rb +15 -3
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +8 -6
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +12 -10
- data/lib/chef_zero/endpoints/role_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/search_endpoint.rb +10 -10
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -0
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -0
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -0
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -0
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -0
- data/lib/chef_zero/rest_base.rb +79 -13
- data/lib/chef_zero/rest_error_response.rb +1 -1
- data/lib/chef_zero/rest_request.rb +4 -0
- data/lib/chef_zero/rest_router.rb +1 -0
- data/lib/chef_zero/rspec.rb +55 -8
- data/lib/chef_zero/server.rb +87 -21
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run_oc_pedant.rb +53 -0
- data/spec/{run.rb → run_pedant.rb} +13 -4
- data/spec/server_spec.rb +54 -0
- data/spec/support/oc_pedant.rb +134 -0
- data/spec/support/pedant.rb +1 -1
- metadata +54 -13
- data/lib/chef_zero/cookbook_data.rb +0 -236
- data/lib/chef_zero/data_normalizer.rb +0 -146
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'chef_zero/rest_base'
|
3
|
+
require 'chef_zero/chef_data/acl_path'
|
4
|
+
|
5
|
+
module ChefZero
|
6
|
+
module Endpoints
|
7
|
+
# /organizations/ORG/<thing>/NAME/_acl/PERM
|
8
|
+
# Where thing is:
|
9
|
+
# clients, data, containers, cookbooks, environments
|
10
|
+
# groups, roles, nodes, users
|
11
|
+
# or
|
12
|
+
# /organizations/ORG/organization/_acl/PERM
|
13
|
+
# or
|
14
|
+
# /users/NAME/_acl/PERM
|
15
|
+
#
|
16
|
+
# Where PERM is create,read,update,delete,grant
|
17
|
+
class AclEndpoint < RestBase
|
18
|
+
def validate_request(request)
|
19
|
+
path = request.rest_path[0..-3]
|
20
|
+
path = path[0..1] if path.size == 3 && path[0] == 'organizations' && %w(organization organizations).include?(path[2])
|
21
|
+
acl_path = ChefData::AclPath.get_acl_data_path(path) # Strip off _acl/PERM
|
22
|
+
perm = request.rest_path[-1]
|
23
|
+
if !acl_path || !%w(read create update delete grant).include?(perm)
|
24
|
+
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
|
25
|
+
end
|
26
|
+
[acl_path, perm]
|
27
|
+
end
|
28
|
+
|
29
|
+
def put(request)
|
30
|
+
path, perm = validate_request(request)
|
31
|
+
acls = JSON.parse(get_data(request, path), :create_additions => false)
|
32
|
+
acls[perm] = JSON.parse(request.body, :create_additions => false)[perm]
|
33
|
+
set_data(request, path, JSON.pretty_generate(acls))
|
34
|
+
json_response(200, {'uri' => "#{build_uri(request.base_uri, request.rest_path)}"})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'chef_zero/rest_base'
|
3
|
+
require 'chef_zero/chef_data/data_normalizer'
|
4
|
+
require 'chef_zero/chef_data/acl_path'
|
5
|
+
|
6
|
+
module ChefZero
|
7
|
+
module Endpoints
|
8
|
+
# /organizations/ORG/THING/NAME/_acl
|
9
|
+
# Where THING is:
|
10
|
+
# - clients, data, containers, cookbooks, environments
|
11
|
+
# groups, roles, nodes, users
|
12
|
+
# or
|
13
|
+
# /organizations/ORG/organization/_acl
|
14
|
+
# /users/NAME/_acl
|
15
|
+
class AclsEndpoint < RestBase
|
16
|
+
def get(request)
|
17
|
+
path = request.rest_path[0..-2] # Strip off _acl
|
18
|
+
path = path[0..1] if path.size == 3 && path[0] == 'organizations' && %w(organization organizations).include?(path[2])
|
19
|
+
acl_path = ChefData::AclPath.get_acl_data_path(path)
|
20
|
+
if !acl_path
|
21
|
+
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
|
22
|
+
end
|
23
|
+
acls = JSON.parse(get_data(request, acl_path), :create_additions => false)
|
24
|
+
acls = ChefData::DataNormalizer.normalize_acls(acls)
|
25
|
+
json_response(200, acls)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,14 +1,29 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
|
-
require 'chef_zero/data_normalizer'
|
3
|
+
require 'chef_zero/chef_data/data_normalizer'
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module Endpoints
|
7
|
-
# /clients
|
7
|
+
# /organizations/ORG/clients/NAME
|
8
|
+
# /organizations/ORG/users/NAME
|
9
|
+
# /users/NAME
|
8
10
|
class ActorEndpoint < RestObjectEndpoint
|
11
|
+
def delete(request)
|
12
|
+
result = super
|
13
|
+
if request.rest_path[0] == 'users'
|
14
|
+
list_data(request, [ 'organizations' ]).each do |org|
|
15
|
+
begin
|
16
|
+
delete_data(request, [ 'organizations', org, 'users', request.rest_path[1] ], :data_store_exceptions)
|
17
|
+
rescue DataStore::DataNotFoundError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
9
24
|
def put(request)
|
10
25
|
# Find out if we're updating the public key.
|
11
|
-
request_body =
|
26
|
+
request_body = JSON.parse(request.body, :create_additions => false)
|
12
27
|
if request_body['public_key'].nil?
|
13
28
|
# If public_key is null, then don't overwrite it. Weird patchiness.
|
14
29
|
body_modified = true
|
@@ -29,7 +44,7 @@ module ChefZero
|
|
29
44
|
end
|
30
45
|
|
31
46
|
# Save request
|
32
|
-
request.body =
|
47
|
+
request.body = JSON.pretty_generate(request_body) if body_modified
|
33
48
|
|
34
49
|
# PUT /clients is patchy
|
35
50
|
request.body = patch_request_body(request)
|
@@ -38,7 +53,18 @@ module ChefZero
|
|
38
53
|
|
39
54
|
# Inject private_key into response, delete public_key/password if applicable
|
40
55
|
if result[0] == 200 || result[0] == 201
|
41
|
-
|
56
|
+
if request.rest_path[0] == 'users'
|
57
|
+
key = nil
|
58
|
+
identity_keys.each do |identity_key|
|
59
|
+
key ||= request_body[identity_key]
|
60
|
+
end
|
61
|
+
key ||= request.rest_path[-1]
|
62
|
+
response = {
|
63
|
+
'uri' => build_uri(request.base_uri, [ 'users', key ])
|
64
|
+
}
|
65
|
+
else
|
66
|
+
response = JSON.parse(result[2], :create_additions => false)
|
67
|
+
end
|
42
68
|
response['private_key'] = private_key if private_key
|
43
69
|
response.delete('public_key') if !updating_public_key && request.rest_path[2] == 'users'
|
44
70
|
response.delete('password')
|
@@ -49,13 +75,13 @@ module ChefZero
|
|
49
75
|
end
|
50
76
|
|
51
77
|
def populate_defaults(request, response_json)
|
52
|
-
response =
|
78
|
+
response = JSON.parse(response_json, :create_additions => false)
|
53
79
|
if request.rest_path[2] == 'clients'
|
54
|
-
response = DataNormalizer.normalize_client(response, request.rest_path[3])
|
80
|
+
response = ChefData::DataNormalizer.normalize_client(response, request.rest_path[3])
|
55
81
|
else
|
56
|
-
response = DataNormalizer.normalize_user(response, request.rest_path[3])
|
82
|
+
response = ChefData::DataNormalizer.normalize_user(response, request.rest_path[3], identity_keys, server.options[:osc_compat], request.method)
|
57
83
|
end
|
58
|
-
|
84
|
+
JSON.pretty_generate(response)
|
59
85
|
end
|
60
86
|
end
|
61
87
|
end
|
@@ -1,27 +1,59 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/endpoints/rest_list_endpoint'
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module Endpoints
|
6
|
-
# /clients or /users
|
6
|
+
# /users, /organizations/ORG/clients or /organizations/ORG/users
|
7
7
|
class ActorsEndpoint < RestListEndpoint
|
8
|
+
def get(request)
|
9
|
+
response = super(request)
|
10
|
+
|
11
|
+
if request.query_params['email']
|
12
|
+
results = JSON.parse(response[2], :create_additions => false)
|
13
|
+
new_results = {}
|
14
|
+
results.each do |name, url|
|
15
|
+
record = get_data(request, request.rest_path + [ name ], :nil)
|
16
|
+
if record
|
17
|
+
record = JSON.parse(record, :create_additions => false)
|
18
|
+
new_results[name] = url if record['email'] == request.query_params['email']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
response[2] = JSON.pretty_generate(new_results)
|
22
|
+
end
|
23
|
+
|
24
|
+
if request.query_params['verbose']
|
25
|
+
results = JSON.parse(response[2], :create_additions => false)
|
26
|
+
results.each do |name, url|
|
27
|
+
record = get_data(request, request.rest_path + [ name ], :nil)
|
28
|
+
if record
|
29
|
+
record = JSON.parse(record, :create_additions => false)
|
30
|
+
record = ChefData::DataNormalizer.normalize_user(record, name, identity_keys, server.options[:osc_compat])
|
31
|
+
results[name] = record
|
32
|
+
end
|
33
|
+
end
|
34
|
+
response[2] = JSON.pretty_generate(results)
|
35
|
+
end
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
8
39
|
def post(request)
|
9
40
|
# First, find out if the user actually posted a public key. If not, make
|
10
41
|
# one.
|
11
|
-
request_body =
|
42
|
+
request_body = JSON.parse(request.body, :create_additions => false)
|
12
43
|
public_key = request_body['public_key']
|
13
44
|
if !public_key
|
14
45
|
private_key, public_key = server.gen_key_pair
|
15
46
|
request_body['public_key'] = public_key
|
16
|
-
request.body =
|
47
|
+
request.body = JSON.pretty_generate(request_body)
|
17
48
|
end
|
18
49
|
|
19
50
|
result = super(request)
|
51
|
+
|
20
52
|
if result[0] == 201
|
21
53
|
# If we generated a key, stuff it in the response.
|
22
|
-
response =
|
54
|
+
response = JSON.parse(result[2], :create_additions => false)
|
23
55
|
response['private_key'] = private_key if private_key
|
24
|
-
response['public_key'] = public_key
|
56
|
+
response['public_key'] = public_key unless request.rest_path[0] == 'users'
|
25
57
|
json_response(201, response)
|
26
58
|
else
|
27
59
|
result
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/rest_base'
|
3
3
|
|
4
4
|
module ChefZero
|
@@ -6,18 +6,24 @@ module ChefZero
|
|
6
6
|
# /authenticate_user
|
7
7
|
class AuthenticateUserEndpoint < RestBase
|
8
8
|
def post(request)
|
9
|
-
request_json =
|
10
|
-
name = request_json['
|
9
|
+
request_json = JSON.parse(request.body, :create_additions => false)
|
10
|
+
name = request_json['username']
|
11
11
|
password = request_json['password']
|
12
12
|
begin
|
13
|
-
user = data_store.get(
|
14
|
-
|
15
|
-
|
16
|
-
verified = false
|
13
|
+
user = data_store.get(['users', name])
|
14
|
+
rescue ChefZero::DataStore::DataNotFoundError
|
15
|
+
raise RestErrorResponse.new(401, "Bad username or password")
|
17
16
|
end
|
17
|
+
user = JSON.parse(user, :create_additions => false)
|
18
|
+
user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
|
19
|
+
if user['password'] != password
|
20
|
+
raise RestErrorResponse.new(401, "Bad username or password")
|
21
|
+
end
|
22
|
+
# Include only particular user data in the response
|
23
|
+
user.keep_if { |key,value| %w(first_name last_name display_name email username).include?(key) }
|
18
24
|
json_response(200, {
|
19
|
-
'
|
20
|
-
'
|
25
|
+
'status' => 'linked',
|
26
|
+
'user' => user
|
21
27
|
})
|
22
28
|
end
|
23
29
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
|
+
require 'chef_zero/chef_data/data_normalizer'
|
4
|
+
|
5
|
+
module ChefZero
|
6
|
+
module Endpoints
|
7
|
+
# /organizations/ORG/containers/NAME
|
8
|
+
class ContainerEndpoint < RestObjectEndpoint
|
9
|
+
def initialize(server)
|
10
|
+
super(server, %w(id containername))
|
11
|
+
end
|
12
|
+
|
13
|
+
undef_method(:put)
|
14
|
+
|
15
|
+
def populate_defaults(request, response_json)
|
16
|
+
container = JSON.parse(response_json, :create_additions => false)
|
17
|
+
container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
|
18
|
+
JSON.pretty_generate(container)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'chef_zero/endpoints/rest_list_endpoint'
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
module Endpoints
|
6
|
+
# /organizations/ORG/containers
|
7
|
+
class ContainersEndpoint < RestListEndpoint
|
8
|
+
def initialize(server)
|
9
|
+
super(server, %w(id containername))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -19,7 +19,7 @@ module ChefZero
|
|
19
19
|
result = []
|
20
20
|
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
|
21
21
|
if versions.size > 0
|
22
|
-
cookbook =
|
22
|
+
cookbook = JSON.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,12 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
3
|
require 'chef_zero/rest_error_response'
|
4
|
-
require 'chef_zero/data_normalizer'
|
4
|
+
require 'chef_zero/chef_data/data_normalizer'
|
5
5
|
require 'chef_zero/data_store/data_not_found_error'
|
6
6
|
|
7
7
|
module ChefZero
|
8
8
|
module Endpoints
|
9
|
-
# /cookbooks/NAME/VERSION
|
9
|
+
# /organizations/ORG/cookbooks/NAME/VERSION
|
10
10
|
class CookbookVersionEndpoint < RestObjectEndpoint
|
11
11
|
def get(request)
|
12
12
|
if request.rest_path[4] == "_latest" || request.rest_path[4] == "latest"
|
@@ -22,22 +22,22 @@ module ChefZero
|
|
22
22
|
|
23
23
|
# Honor frozen
|
24
24
|
if existing_cookbook
|
25
|
-
existing_cookbook_json =
|
25
|
+
existing_cookbook_json = JSON.parse(existing_cookbook, :create_additions => false)
|
26
26
|
if existing_cookbook_json['frozen?']
|
27
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
|
-
request_body =
|
31
|
+
request_body = JSON.parse(request.body, :create_additions => false)
|
32
32
|
if !request_body['frozen?']
|
33
33
|
request_body['frozen?'] = true
|
34
|
-
request.body =
|
34
|
+
request.body = JSON.pretty_generate(request_body)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
# Set the cookbook
|
40
|
-
set_data(request, request.rest_path
|
40
|
+
set_data(request, request.rest_path, request.body, :create_dir, :create)
|
41
41
|
|
42
42
|
# If the cookbook was updated, check for deleted files and clean them up
|
43
43
|
if existing_cookbook
|
@@ -59,8 +59,9 @@ module ChefZero
|
|
59
59
|
|
60
60
|
response = super(request)
|
61
61
|
cookbook_name = request.rest_path[3]
|
62
|
-
|
63
|
-
|
62
|
+
cookbook_path = request.rest_path[0..1] + ['cookbooks', cookbook_name]
|
63
|
+
if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
|
64
|
+
delete_data_dir(request, cookbook_path)
|
64
65
|
end
|
65
66
|
|
66
67
|
# Hoover deleted files, if they exist
|
@@ -70,7 +71,7 @@ module ChefZero
|
|
70
71
|
|
71
72
|
def get_checksums(cookbook)
|
72
73
|
result = []
|
73
|
-
|
74
|
+
JSON.parse(cookbook, :create_additions => false).each_pair do |key, value|
|
74
75
|
if value.is_a?(Array)
|
75
76
|
value.each do |file|
|
76
77
|
if file.is_a?(Hash) && file.has_key?('checksum')
|
@@ -96,7 +97,7 @@ module ChefZero
|
|
96
97
|
# This deals with an exception on delete, but things can still get deleted
|
97
98
|
# that shouldn't be.
|
98
99
|
begin
|
99
|
-
|
100
|
+
delete_data(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum], :data_store_exceptions)
|
100
101
|
rescue ChefZero::DataStore::DataNotFoundError
|
101
102
|
end
|
102
103
|
end
|
@@ -104,9 +105,9 @@ module ChefZero
|
|
104
105
|
|
105
106
|
def populate_defaults(request, response_json)
|
106
107
|
# Inject URIs into each cookbook file
|
107
|
-
cookbook =
|
108
|
-
cookbook = DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method)
|
109
|
-
|
108
|
+
cookbook = JSON.parse(response_json, :create_additions => false)
|
109
|
+
cookbook = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method)
|
110
|
+
JSON.pretty_generate(cookbook)
|
110
111
|
end
|
111
112
|
|
112
113
|
def latest_version(versions)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/endpoints/rest_list_endpoint'
|
3
3
|
require 'chef_zero/endpoints/data_bag_item_endpoint'
|
4
4
|
require 'chef_zero/rest_error_response'
|
@@ -12,7 +12,8 @@ module ChefZero
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def post(request)
|
15
|
-
|
15
|
+
json = JSON.parse(request.body, :create_additions => false)
|
16
|
+
key = identity_keys.map { |k| json[k] }.select { |v| v }.first
|
16
17
|
response = super(request)
|
17
18
|
if response[0] == 201
|
18
19
|
already_json_response(201, DataBagItemEndpoint::populate_defaults(request, request.body, request.rest_path[3], key))
|
@@ -22,7 +23,7 @@ module ChefZero
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def get_key(contents)
|
25
|
-
data_bag_item =
|
26
|
+
data_bag_item = JSON.parse(contents, :create_additions => false)
|
26
27
|
if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
|
27
28
|
data_bag_item['raw_data']['id']
|
28
29
|
else
|
@@ -42,4 +43,3 @@ module ChefZero
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'json'
|
2
2
|
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
3
|
require 'chef_zero/endpoints/data_bag_item_endpoint'
|
4
|
-
require 'chef_zero/data_normalizer'
|
4
|
+
require 'chef_zero/chef_data/data_normalizer'
|
5
5
|
|
6
6
|
module ChefZero
|
7
7
|
module Endpoints
|
@@ -16,9 +16,9 @@ module ChefZero
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.populate_defaults(request, response_json, data_bag, data_bag_item)
|
19
|
-
response =
|
20
|
-
response = DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
|
21
|
-
|
19
|
+
response = JSON.parse(response_json, :create_additions => false)
|
20
|
+
response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
|
21
|
+
JSON.pretty_generate(response)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|