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 "chef_zero/data_store/interface_v2"
|
2
|
+
require "chef_zero/chef_data/default_creator"
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module DataStore
|
@@ -65,7 +65,7 @@ module ChefZero
|
|
65
65
|
default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:create_dir))
|
66
66
|
end
|
67
67
|
|
68
|
-
def get(path, request=nil)
|
68
|
+
def get(path, request = nil)
|
69
69
|
begin
|
70
70
|
real_store.get(path, request)
|
71
71
|
rescue DataNotFoundError
|
@@ -83,8 +83,8 @@ module ChefZero
|
|
83
83
|
real_store.set(path, data, *options)
|
84
84
|
rescue DataNotFoundError
|
85
85
|
if options.include?(:create_dir) ||
|
86
|
-
|
87
|
-
|
86
|
+
options.include?(:create) && default_creator.exists?(path[0..-2]) ||
|
87
|
+
default_creator.exists?(path)
|
88
88
|
real_store.set(path, data, :create, :create_dir, *options)
|
89
89
|
else
|
90
90
|
raise
|
@@ -16,16 +16,16 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
19
|
+
require "chef_zero/data_store/v2_to_v1_adapter"
|
20
|
+
require "chef_zero/data_store/memory_store_v2"
|
21
|
+
require "chef_zero/data_store/default_facade"
|
22
22
|
|
23
23
|
module ChefZero
|
24
24
|
module DataStore
|
25
25
|
class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
|
26
26
|
def initialize
|
27
27
|
super
|
28
|
-
@real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new,
|
28
|
+
@real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, "chef", true)
|
29
29
|
clear
|
30
30
|
end
|
31
31
|
end
|
@@ -16,9 +16,9 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
19
|
+
require "chef_zero/data_store/data_already_exists_error"
|
20
|
+
require "chef_zero/data_store/data_not_found_error"
|
21
|
+
require "chef_zero/data_store/interface_v2"
|
22
22
|
|
23
23
|
module ChefZero
|
24
24
|
module DataStore
|
@@ -58,7 +58,7 @@ module ChefZero
|
|
58
58
|
parent[name] = data
|
59
59
|
end
|
60
60
|
|
61
|
-
def get(path, request=nil)
|
61
|
+
def get(path, request = nil)
|
62
62
|
value = _get(path)
|
63
63
|
if value.is_a?(Hash)
|
64
64
|
raise "get() called on directory #{path.join('/')}"
|
@@ -81,7 +81,7 @@ module ChefZero
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def delete(path)
|
84
|
-
parent = _get(path[0,path.length-1])
|
84
|
+
parent = _get(path[0, path.length - 1])
|
85
85
|
if !parent.has_key?(path[-1])
|
86
86
|
raise DataNotFoundError.new(path)
|
87
87
|
end
|
@@ -92,7 +92,7 @@ module ChefZero
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def delete_dir(path, *options)
|
95
|
-
parent = _get(path[0,path.length-1])
|
95
|
+
parent = _get(path[0, path.length - 1])
|
96
96
|
if !parent.has_key?(path[-1])
|
97
97
|
raise DataNotFoundError.new(path)
|
98
98
|
end
|
@@ -136,14 +136,14 @@ module ChefZero
|
|
136
136
|
|
137
137
|
private
|
138
138
|
|
139
|
-
def _get(path, create_dir=false)
|
139
|
+
def _get(path, create_dir = false)
|
140
140
|
value = @data
|
141
141
|
path.each_with_index do |path_part, index|
|
142
142
|
if !value.has_key?(path_part)
|
143
143
|
if create_dir
|
144
144
|
value[path_part] = {}
|
145
145
|
else
|
146
|
-
raise DataNotFoundError.new(path[0,index+1])
|
146
|
+
raise DataNotFoundError.new(path[0, index + 1])
|
147
147
|
end
|
148
148
|
end
|
149
149
|
value = value[path_part]
|
@@ -16,10 +16,10 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
19
|
+
require "chef_zero/data_store/data_already_exists_error"
|
20
|
+
require "chef_zero/data_store/data_not_found_error"
|
21
|
+
require "chef_zero/data_store/interface_v2"
|
22
|
+
require "fileutils"
|
23
23
|
|
24
24
|
module ChefZero
|
25
25
|
module DataStore
|
@@ -32,7 +32,7 @@ module ChefZero
|
|
32
32
|
attr_reader :root
|
33
33
|
attr_reader :destructible
|
34
34
|
|
35
|
-
def path_to(path, name=nil)
|
35
|
+
def path_to(path, name = nil)
|
36
36
|
if name
|
37
37
|
File.join(root, *path, name)
|
38
38
|
else
|
@@ -43,7 +43,7 @@ module ChefZero
|
|
43
43
|
def clear
|
44
44
|
if destructible
|
45
45
|
Dir.entries(root).each do |entry|
|
46
|
-
next if entry ==
|
46
|
+
next if entry == "." || entry == ".."
|
47
47
|
FileUtils.rm_rf(Path.join(root, entry))
|
48
48
|
end
|
49
49
|
end
|
@@ -69,7 +69,7 @@ module ChefZero
|
|
69
69
|
FileUtils.mkdir_p(path_to(path))
|
70
70
|
end
|
71
71
|
begin
|
72
|
-
File.open(path_to(path, name), File::WRONLY|File::CREAT|File::EXCL|File::BINARY, :internal_encoding => nil) do |file|
|
72
|
+
File.open(path_to(path, name), File::WRONLY | File::CREAT | File::EXCL | File::BINARY, :internal_encoding => nil) do |file|
|
73
73
|
file.write data
|
74
74
|
end
|
75
75
|
rescue Errno::ENOENT
|
@@ -79,7 +79,7 @@ module ChefZero
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
def get(path, request=nil)
|
82
|
+
def get(path, request = nil)
|
83
83
|
begin
|
84
84
|
return IO.read(path_to(path))
|
85
85
|
rescue Errno::ENOENT
|
@@ -92,7 +92,7 @@ module ChefZero
|
|
92
92
|
FileUtils.mkdir_p(path_to(path[0..-2]))
|
93
93
|
end
|
94
94
|
begin
|
95
|
-
mode = File::WRONLY|File::TRUNC|File::BINARY
|
95
|
+
mode = File::WRONLY | File::TRUNC | File::BINARY
|
96
96
|
if options.include?(:create)
|
97
97
|
mode |= File::CREAT
|
98
98
|
end
|
@@ -129,7 +129,7 @@ module ChefZero
|
|
129
129
|
|
130
130
|
def list(path)
|
131
131
|
begin
|
132
|
-
Dir.entries(path_to(path)).select { |entry| entry !=
|
132
|
+
Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
|
133
133
|
rescue Errno::ENOENT
|
134
134
|
raise DataNotFoundError.new(path)
|
135
135
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "chef_zero/data_store/interface_v2"
|
2
2
|
|
3
3
|
module ChefZero
|
4
4
|
module DataStore
|
@@ -35,13 +35,13 @@ module ChefZero
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def get(path, request=nil)
|
38
|
+
def get(path, request = nil)
|
39
39
|
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
40
40
|
fix_exceptions do
|
41
41
|
# Make it so build_uri will include /organizations/ORG inside the V1 data store
|
42
42
|
if request && request.rest_base_prefix.size == 0
|
43
43
|
old_base_uri = request.base_uri
|
44
|
-
request.base_uri = File.join(request.base_uri,
|
44
|
+
request.base_uri = File.join(request.base_uri, "organizations", single_org)
|
45
45
|
end
|
46
46
|
begin
|
47
47
|
real_store.get(path[2..-1], request)
|
@@ -75,8 +75,8 @@ module ChefZero
|
|
75
75
|
def list(path)
|
76
76
|
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
77
77
|
if path == []
|
78
|
-
[
|
79
|
-
elsif path == [
|
78
|
+
[ "organizations" ]
|
79
|
+
elsif path == [ "organizations" ]
|
80
80
|
[ single_org ]
|
81
81
|
else
|
82
82
|
fix_exceptions do
|
@@ -96,7 +96,7 @@ module ChefZero
|
|
96
96
|
return false if skip_organizations?(path)
|
97
97
|
if path == []
|
98
98
|
true
|
99
|
-
elsif path == [
|
99
|
+
elsif path == [ "organizations" ] || path == [ "users" ]
|
100
100
|
true
|
101
101
|
else
|
102
102
|
return false if skip_organizations?(path)
|
@@ -112,11 +112,11 @@ module ChefZero
|
|
112
112
|
begin
|
113
113
|
yield
|
114
114
|
rescue DataAlreadyExistsError => e
|
115
|
-
err = DataAlreadyExistsError.new([
|
115
|
+
err = DataAlreadyExistsError.new([ "organizations", single_org ] + e.path, e)
|
116
116
|
err.set_backtrace(e.backtrace)
|
117
117
|
raise err
|
118
118
|
rescue DataNotFoundError => e
|
119
|
-
err = DataNotFoundError.new([
|
119
|
+
err = DataNotFoundError.new([ "organizations", single_org ] + e.path, e)
|
120
120
|
err.set_backtrace(e.backtrace)
|
121
121
|
raise e
|
122
122
|
end
|
@@ -125,7 +125,7 @@ module ChefZero
|
|
125
125
|
def skip_organizations?(path, name = nil)
|
126
126
|
if path == []
|
127
127
|
false
|
128
|
-
elsif path[0] ==
|
128
|
+
elsif path[0] == "organizations"
|
129
129
|
if path.size == 1
|
130
130
|
false
|
131
131
|
elsif path.size >= 2 && path[1] != single_org
|
@@ -16,13 +16,13 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
19
|
+
require "chef_zero/data_store/interface_v1"
|
20
20
|
|
21
21
|
module ChefZero
|
22
22
|
module DataStore
|
23
23
|
class V2ToV1Adapter < ChefZero::DataStore::InterfaceV1
|
24
24
|
def initialize
|
25
|
-
@single_org =
|
25
|
+
@single_org = "chef"
|
26
26
|
end
|
27
27
|
|
28
28
|
attr_reader :real_store
|
@@ -30,7 +30,7 @@ module ChefZero
|
|
30
30
|
|
31
31
|
def clear
|
32
32
|
real_store.clear
|
33
|
-
real_store.create_dir([
|
33
|
+
real_store.create_dir([ "organizations" ], single_org, :recursive)
|
34
34
|
end
|
35
35
|
|
36
36
|
def create_dir(path, name, *options)
|
@@ -45,7 +45,7 @@ module ChefZero
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def get(path, request=nil)
|
48
|
+
def get(path, request = nil)
|
49
49
|
fix_exceptions do
|
50
50
|
real_store.get(fix_path(path), request)
|
51
51
|
end
|
@@ -100,7 +100,7 @@ module ChefZero
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def fix_path(path)
|
103
|
-
[
|
103
|
+
[ "organizations", single_org ] + path
|
104
104
|
end
|
105
105
|
end
|
106
106
|
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/acl_path"
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module Endpoints
|
@@ -17,10 +17,10 @@ module ChefZero
|
|
17
17
|
class AclEndpoint < RestBase
|
18
18
|
def validate_request(request)
|
19
19
|
path = request.rest_path[0..-3] # Strip off _acl/PERM
|
20
|
-
path = path[0..1] if path.size == 3 && path[0] ==
|
20
|
+
path = path[0..1] if path.size == 3 && path[0] == "organizations" && %w{organization organizations}.include?(path[2])
|
21
21
|
acl_path = ChefData::AclPath.get_acl_data_path(path)
|
22
22
|
perm = request.rest_path[-1]
|
23
|
-
if !acl_path || !%w
|
23
|
+
if !acl_path || !%w{read create update delete grant}.include?(perm)
|
24
24
|
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
|
25
25
|
end
|
26
26
|
[acl_path, perm]
|
@@ -31,7 +31,7 @@ module ChefZero
|
|
31
31
|
acls = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
|
32
32
|
acls[perm] = FFI_Yajl::Parser.parse(request.body, :create_additions => false)[perm]
|
33
33
|
set_data(request, path, FFI_Yajl::Encoder.encode(acls, :pretty => true))
|
34
|
-
json_response(200, {
|
34
|
+
json_response(200, { "uri" => "#{build_uri(request.base_uri, request.rest_path)}" })
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "ffi_yajl"
|
2
|
+
require "chef_zero/rest_base"
|
3
|
+
require "chef_zero/chef_data/data_normalizer"
|
4
|
+
require "chef_zero/chef_data/acl_path"
|
5
5
|
|
6
6
|
module ChefZero
|
7
7
|
module Endpoints
|
@@ -15,7 +15,7 @@ module ChefZero
|
|
15
15
|
class AclsEndpoint < RestBase
|
16
16
|
def get(request)
|
17
17
|
path = request.rest_path[0..-2] # Strip off _acl
|
18
|
-
path = path[0..1] if path.size == 3 && path[0] ==
|
18
|
+
path = path[0..1] if path.size == 3 && path[0] == "organizations" && %w{organization organizations}.include?(path[2])
|
19
19
|
acl_path = ChefData::AclPath.get_acl_data_path(path)
|
20
20
|
if !acl_path
|
21
21
|
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
|
@@ -1,6 +1,6 @@
|
|
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
|
@@ -21,10 +21,10 @@ module ChefZero
|
|
21
21
|
def delete(request)
|
22
22
|
result = super
|
23
23
|
|
24
|
-
if request.rest_path[0] ==
|
25
|
-
list_data(request, [
|
24
|
+
if request.rest_path[0] == "users"
|
25
|
+
list_data(request, [ "organizations" ]).each do |org|
|
26
26
|
begin
|
27
|
-
delete_data(request, [
|
27
|
+
delete_data(request, [ "organizations", org, "users", request.rest_path[1] ], :data_store_exceptions)
|
28
28
|
rescue DataStore::DataNotFoundError
|
29
29
|
end
|
30
30
|
end
|
@@ -38,22 +38,22 @@ module ChefZero
|
|
38
38
|
# Find out if we're updating the public key.
|
39
39
|
request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
|
40
40
|
|
41
|
-
if request_body[
|
41
|
+
if request_body["public_key"].nil?
|
42
42
|
# If public_key is null, then don't overwrite it. Weird patchiness.
|
43
43
|
body_modified = true
|
44
|
-
request_body.delete(
|
44
|
+
request_body.delete("public_key")
|
45
45
|
else
|
46
46
|
updating_public_key = true
|
47
47
|
end
|
48
48
|
|
49
49
|
# Generate private_key if requested.
|
50
|
-
if request_body.key?(
|
50
|
+
if request_body.key?("private_key")
|
51
51
|
body_modified = true
|
52
52
|
|
53
|
-
if request_body.delete(
|
53
|
+
if request_body.delete("private_key")
|
54
54
|
private_key, public_key = server.gen_key_pair
|
55
55
|
updating_public_key = true
|
56
|
-
request_body[
|
56
|
+
request_body["public_key"] = public_key
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -73,22 +73,22 @@ module ChefZero
|
|
73
73
|
rename_keys!(request, client_or_user_name)
|
74
74
|
end
|
75
75
|
|
76
|
-
if request.rest_path[0] ==
|
76
|
+
if request.rest_path[0] == "users"
|
77
77
|
response = {
|
78
|
-
|
78
|
+
"uri" => build_uri(request.base_uri, [ "users", client_or_user_name ]),
|
79
79
|
}
|
80
80
|
else
|
81
81
|
response = parse_json(result[2])
|
82
82
|
end
|
83
83
|
|
84
84
|
if client?(request)
|
85
|
-
response[
|
85
|
+
response["private_key"] = private_key ? private_key : false
|
86
86
|
else
|
87
|
-
response[
|
88
|
-
response.delete(
|
87
|
+
response["private_key"] = private_key if private_key
|
88
|
+
response.delete("public_key") unless updating_public_key
|
89
89
|
end
|
90
90
|
|
91
|
-
response.delete(
|
91
|
+
response.delete("password")
|
92
92
|
|
93
93
|
json_response(result[0], response)
|
94
94
|
else
|
@@ -125,7 +125,7 @@ module ChefZero
|
|
125
125
|
def rename_keys!(request, new_client_or_user_name)
|
126
126
|
orig_keys_path = keys_path_base(request)
|
127
127
|
new_keys_path = orig_keys_path.dup
|
128
|
-
.tap {|path| path[-2] = new_client_or_user_name }
|
128
|
+
.tap { |path| path[-2] = new_client_or_user_name }
|
129
129
|
|
130
130
|
key_names = list_data_or_else(request, orig_keys_path, nil)
|
131
131
|
return unless key_names # No keys to move
|
@@ -154,7 +154,7 @@ module ChefZero
|
|
154
154
|
rescue DataStore::DataNotFoundError
|
155
155
|
end
|
156
156
|
|
157
|
-
def client?(request, rest_path=nil)
|
157
|
+
def client?(request, rest_path = nil)
|
158
158
|
rest_path ||= request.rest_path
|
159
159
|
request.rest_path[2] == "clients"
|
160
160
|
end
|
@@ -165,7 +165,7 @@ module ChefZero
|
|
165
165
|
# /organizations/ORG/users/USER -> /organizations/ORG/user_keys/USER/keys
|
166
166
|
# /users/USER -> /user_keys/USER
|
167
167
|
#
|
168
|
-
def keys_path_base(request, client_or_user_name=nil)
|
168
|
+
def keys_path_base(request, client_or_user_name = nil)
|
169
169
|
rest_path = (rest_path || request.rest_path).dup
|
170
170
|
rest_path = rest_path.dup
|
171
171
|
case rest_path[-2]
|