chef-zero 4.3.0 → 4.3.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/LICENSE +201 -201
- data/README.md +155 -155
- data/Rakefile +31 -31
- data/bin/chef-zero +100 -100
- data/lib/chef_zero.rb +10 -10
- data/lib/chef_zero/chef_data/acl_path.rb +139 -139
- data/lib/chef_zero/chef_data/cookbook_data.rb +240 -240
- data/lib/chef_zero/chef_data/data_normalizer.rb +208 -207
- data/lib/chef_zero/chef_data/default_creator.rb +446 -446
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +31 -31
- data/lib/chef_zero/data_store/data_not_found_error.rb +28 -28
- data/lib/chef_zero/data_store/default_facade.rb +149 -149
- data/lib/chef_zero/data_store/interface_v1.rb +67 -67
- data/lib/chef_zero/data_store/interface_v2.rb +18 -18
- data/lib/chef_zero/data_store/memory_store.rb +33 -33
- data/lib/chef_zero/data_store/memory_store_v2.rb +155 -155
- data/lib/chef_zero/data_store/raw_file_store.rb +147 -147
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +142 -142
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -107
- data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/actor_endpoint.rb +94 -94
- data/lib/chef_zero/endpoints/actors_endpoint.rb +64 -64
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +31 -31
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +119 -119
- data/lib/chef_zero/endpoints/cookbooks_base.rb +65 -65
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +123 -123
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/node_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_endpoint.rb +46 -46
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -43
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +62 -62
- data/lib/chef_zero/endpoints/policies_endpoint.rb +151 -151
- data/lib/chef_zero/endpoints/principal_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +63 -63
- data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +50 -50
- data/lib/chef_zero/endpoints/search_endpoint.rb +194 -194
- data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -40
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/version_endpoint.rb +12 -12
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +242 -242
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +69 -69
- data/lib/chef_zero/rest_router.rb +45 -45
- data/lib/chef_zero/rspec.rb +308 -308
- data/lib/chef_zero/server.rb +642 -642
- data/lib/chef_zero/socketless_server_map.rb +92 -92
- data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
- data/lib/chef_zero/solr/query/phrase.rb +23 -23
- data/lib/chef_zero/solr/query/range_query.rb +46 -46
- data/lib/chef_zero/solr/query/regexpable_query.rb +29 -29
- data/lib/chef_zero/solr/query/subquery.rb +37 -37
- data/lib/chef_zero/solr/query/term.rb +45 -45
- data/lib/chef_zero/solr/query/unary_operator.rb +43 -43
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +203 -203
- data/lib/chef_zero/version.rb +3 -3
- data/spec/run_oc_pedant.rb +63 -63
- data/spec/search_spec.rb +32 -32
- data/spec/server_spec.rb +92 -92
- data/spec/socketless_server_map_spec.rb +76 -76
- data/spec/support/oc_pedant.rb +132 -132
- data/spec/support/stickywicket.pem +27 -27
- metadata +3 -3
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Author:: John Keiser (<jkeiser@opscode.com>)
|
|
3
|
-
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
|
4
|
-
# License:: Apache License, Version 2.0
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
#
|
|
18
|
-
|
|
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
|
-
|
|
24
|
-
module ChefZero
|
|
25
|
-
module DataStore
|
|
26
|
-
class RawFileStore < ChefZero::DataStore::InterfaceV2
|
|
27
|
-
def initialize(root, destructible = false)
|
|
28
|
-
@root = root
|
|
29
|
-
@destructible = destructible
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
attr_reader :root
|
|
33
|
-
attr_reader :destructible
|
|
34
|
-
|
|
35
|
-
def path_to(path, name=nil)
|
|
36
|
-
if name
|
|
37
|
-
File.join(root, *path, name)
|
|
38
|
-
else
|
|
39
|
-
File.join(root, *path)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def clear
|
|
44
|
-
if destructible
|
|
45
|
-
Dir.entries(root).each do |entry|
|
|
46
|
-
next if entry == '.' || entry == '..'
|
|
47
|
-
FileUtils.rm_rf(Path.join(root, entry))
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def create_dir(path, name, *options)
|
|
53
|
-
real_path = path_to(path, name)
|
|
54
|
-
if options.include?(:recursive)
|
|
55
|
-
FileUtils.mkdir_p(real_path)
|
|
56
|
-
else
|
|
57
|
-
begin
|
|
58
|
-
Dir.mkdir(File.join(path, name))
|
|
59
|
-
rescue Errno::ENOENT
|
|
60
|
-
raise DataNotFoundError.new(path)
|
|
61
|
-
rescue Errno::EEXIST
|
|
62
|
-
raise DataAlreadyExistsError.new(path + [name])
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def create(path, name, data, *options)
|
|
68
|
-
if options.include?(:create_dir)
|
|
69
|
-
FileUtils.mkdir_p(path_to(path))
|
|
70
|
-
end
|
|
71
|
-
begin
|
|
72
|
-
File.open(path_to(path, name), File::WRONLY|File::CREAT|File::EXCL|File::BINARY, :internal_encoding => nil) do |file|
|
|
73
|
-
file.write data
|
|
74
|
-
end
|
|
75
|
-
rescue Errno::ENOENT
|
|
76
|
-
raise DataNotFoundError.new(path)
|
|
77
|
-
rescue Errno::EEXIST
|
|
78
|
-
raise DataAlreadyExistsError.new(path + [name])
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def get(path, request=nil)
|
|
83
|
-
begin
|
|
84
|
-
return IO.read(path_to(path))
|
|
85
|
-
rescue Errno::ENOENT
|
|
86
|
-
raise DataNotFoundError.new(path)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def set(path, data, *options)
|
|
91
|
-
if options.include?(:create_dir)
|
|
92
|
-
FileUtils.mkdir_p(path_to(path[0..-2]))
|
|
93
|
-
end
|
|
94
|
-
begin
|
|
95
|
-
mode = File::WRONLY|File::TRUNC|File::BINARY
|
|
96
|
-
if options.include?(:create)
|
|
97
|
-
mode |= File::CREAT
|
|
98
|
-
end
|
|
99
|
-
File.open(path_to(path), mode, :internal_encoding => nil) do |file|
|
|
100
|
-
file.write data
|
|
101
|
-
end
|
|
102
|
-
rescue Errno::ENOENT
|
|
103
|
-
raise DataNotFoundError.new(path)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def delete(path)
|
|
108
|
-
begin
|
|
109
|
-
File.delete(path_to(path))
|
|
110
|
-
rescue Errno::ENOENT
|
|
111
|
-
raise DataNotFoundError.new(path)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def delete_dir(path, *options)
|
|
116
|
-
if options.include?(:recursive)
|
|
117
|
-
if !File.exist?(path_to(path))
|
|
118
|
-
raise DataNotFoundError.new(path)
|
|
119
|
-
end
|
|
120
|
-
FileUtils.rm_rf(path_to(path))
|
|
121
|
-
else
|
|
122
|
-
begin
|
|
123
|
-
Dir.rmdir(path_to(path))
|
|
124
|
-
rescue Errno::ENOENT
|
|
125
|
-
raise DataNotFoundError.new(path)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def list(path)
|
|
131
|
-
begin
|
|
132
|
-
Dir.entries(path_to(path)).select { |entry| entry != '.' && entry != '..' }.to_a
|
|
133
|
-
rescue Errno::ENOENT
|
|
134
|
-
raise DataNotFoundError.new(path)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def exists?(path, options = {})
|
|
139
|
-
File.exists?(path_to(path))
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def exists_dir?(path)
|
|
143
|
-
File.exists?(path_to(path))
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
1
|
+
#
|
|
2
|
+
# Author:: John Keiser (<jkeiser@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
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
|
+
|
|
24
|
+
module ChefZero
|
|
25
|
+
module DataStore
|
|
26
|
+
class RawFileStore < ChefZero::DataStore::InterfaceV2
|
|
27
|
+
def initialize(root, destructible = false)
|
|
28
|
+
@root = root
|
|
29
|
+
@destructible = destructible
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
attr_reader :root
|
|
33
|
+
attr_reader :destructible
|
|
34
|
+
|
|
35
|
+
def path_to(path, name=nil)
|
|
36
|
+
if name
|
|
37
|
+
File.join(root, *path, name)
|
|
38
|
+
else
|
|
39
|
+
File.join(root, *path)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def clear
|
|
44
|
+
if destructible
|
|
45
|
+
Dir.entries(root).each do |entry|
|
|
46
|
+
next if entry == '.' || entry == '..'
|
|
47
|
+
FileUtils.rm_rf(Path.join(root, entry))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def create_dir(path, name, *options)
|
|
53
|
+
real_path = path_to(path, name)
|
|
54
|
+
if options.include?(:recursive)
|
|
55
|
+
FileUtils.mkdir_p(real_path)
|
|
56
|
+
else
|
|
57
|
+
begin
|
|
58
|
+
Dir.mkdir(File.join(path, name))
|
|
59
|
+
rescue Errno::ENOENT
|
|
60
|
+
raise DataNotFoundError.new(path)
|
|
61
|
+
rescue Errno::EEXIST
|
|
62
|
+
raise DataAlreadyExistsError.new(path + [name])
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def create(path, name, data, *options)
|
|
68
|
+
if options.include?(:create_dir)
|
|
69
|
+
FileUtils.mkdir_p(path_to(path))
|
|
70
|
+
end
|
|
71
|
+
begin
|
|
72
|
+
File.open(path_to(path, name), File::WRONLY|File::CREAT|File::EXCL|File::BINARY, :internal_encoding => nil) do |file|
|
|
73
|
+
file.write data
|
|
74
|
+
end
|
|
75
|
+
rescue Errno::ENOENT
|
|
76
|
+
raise DataNotFoundError.new(path)
|
|
77
|
+
rescue Errno::EEXIST
|
|
78
|
+
raise DataAlreadyExistsError.new(path + [name])
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def get(path, request=nil)
|
|
83
|
+
begin
|
|
84
|
+
return IO.read(path_to(path))
|
|
85
|
+
rescue Errno::ENOENT
|
|
86
|
+
raise DataNotFoundError.new(path)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def set(path, data, *options)
|
|
91
|
+
if options.include?(:create_dir)
|
|
92
|
+
FileUtils.mkdir_p(path_to(path[0..-2]))
|
|
93
|
+
end
|
|
94
|
+
begin
|
|
95
|
+
mode = File::WRONLY|File::TRUNC|File::BINARY
|
|
96
|
+
if options.include?(:create)
|
|
97
|
+
mode |= File::CREAT
|
|
98
|
+
end
|
|
99
|
+
File.open(path_to(path), mode, :internal_encoding => nil) do |file|
|
|
100
|
+
file.write data
|
|
101
|
+
end
|
|
102
|
+
rescue Errno::ENOENT
|
|
103
|
+
raise DataNotFoundError.new(path)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def delete(path)
|
|
108
|
+
begin
|
|
109
|
+
File.delete(path_to(path))
|
|
110
|
+
rescue Errno::ENOENT
|
|
111
|
+
raise DataNotFoundError.new(path)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def delete_dir(path, *options)
|
|
116
|
+
if options.include?(:recursive)
|
|
117
|
+
if !File.exist?(path_to(path))
|
|
118
|
+
raise DataNotFoundError.new(path)
|
|
119
|
+
end
|
|
120
|
+
FileUtils.rm_rf(path_to(path))
|
|
121
|
+
else
|
|
122
|
+
begin
|
|
123
|
+
Dir.rmdir(path_to(path))
|
|
124
|
+
rescue Errno::ENOENT
|
|
125
|
+
raise DataNotFoundError.new(path)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def list(path)
|
|
131
|
+
begin
|
|
132
|
+
Dir.entries(path_to(path)).select { |entry| entry != '.' && entry != '..' }.to_a
|
|
133
|
+
rescue Errno::ENOENT
|
|
134
|
+
raise DataNotFoundError.new(path)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def exists?(path, options = {})
|
|
139
|
+
File.exists?(path_to(path))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def exists_dir?(path)
|
|
143
|
+
File.exists?(path_to(path))
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
require 'chef_zero/data_store/interface_v2'
|
|
2
|
-
|
|
3
|
-
module ChefZero
|
|
4
|
-
module DataStore
|
|
5
|
-
class V1ToV2Adapter < ChefZero::DataStore::InterfaceV2
|
|
6
|
-
def initialize(real_store, single_org, options = {})
|
|
7
|
-
@real_store = real_store
|
|
8
|
-
@single_org = single_org
|
|
9
|
-
@options = options
|
|
10
|
-
clear
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
attr_reader :real_store
|
|
14
|
-
attr_reader :single_org
|
|
15
|
-
|
|
16
|
-
def clear
|
|
17
|
-
real_store.clear if real_store.respond_to?(:clear)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def create_dir(path, name, *options)
|
|
21
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
22
|
-
raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
|
|
23
|
-
raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
|
|
24
|
-
fix_exceptions do
|
|
25
|
-
real_store.create_dir(path[2..-1], name, *options)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def create(path, name, data, *options)
|
|
30
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
31
|
-
raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
|
|
32
|
-
raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
|
|
33
|
-
fix_exceptions do
|
|
34
|
-
real_store.create(path[2..-1], name, data, *options)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def get(path, request=nil)
|
|
39
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
40
|
-
fix_exceptions do
|
|
41
|
-
# Make it so build_uri will include /organizations/ORG inside the V1 data store
|
|
42
|
-
if request && request.rest_base_prefix.size == 0
|
|
43
|
-
old_base_uri = request.base_uri
|
|
44
|
-
request.base_uri = File.join(request.base_uri, 'organizations', single_org)
|
|
45
|
-
end
|
|
46
|
-
begin
|
|
47
|
-
real_store.get(path[2..-1], request)
|
|
48
|
-
ensure
|
|
49
|
-
request.base_uri = old_base_uri if request && request.rest_base_prefix.size == 0
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def set(path, data, *options)
|
|
55
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
56
|
-
fix_exceptions do
|
|
57
|
-
real_store.set(path[2..-1], data, *options)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def delete(path, *options)
|
|
62
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
|
63
|
-
fix_exceptions do
|
|
64
|
-
real_store.delete(path[2..-1])
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def delete_dir(path, *options)
|
|
69
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
|
70
|
-
fix_exceptions do
|
|
71
|
-
real_store.delete_dir(path[2..-1], *options)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def list(path)
|
|
76
|
-
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
77
|
-
if path == []
|
|
78
|
-
[ 'organizations' ]
|
|
79
|
-
elsif path == [ 'organizations' ]
|
|
80
|
-
[ single_org ]
|
|
81
|
-
else
|
|
82
|
-
fix_exceptions do
|
|
83
|
-
real_store.list(path[2..-1])
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def exists?(path)
|
|
89
|
-
return false if skip_organizations?(path)
|
|
90
|
-
fix_exceptions do
|
|
91
|
-
real_store.exists?(path[2..-1])
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def exists_dir?(path)
|
|
96
|
-
return false if skip_organizations?(path)
|
|
97
|
-
if path == []
|
|
98
|
-
true
|
|
99
|
-
elsif path == [ 'organizations' ] || path == [ 'users' ]
|
|
100
|
-
true
|
|
101
|
-
else
|
|
102
|
-
return false if skip_organizations?(path)
|
|
103
|
-
fix_exceptions do
|
|
104
|
-
real_store.exists_dir?(path[2..-1])
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
private
|
|
110
|
-
|
|
111
|
-
def fix_exceptions
|
|
112
|
-
begin
|
|
113
|
-
yield
|
|
114
|
-
rescue DataAlreadyExistsError => e
|
|
115
|
-
err = DataAlreadyExistsError.new([ 'organizations', single_org ] + e.path, e)
|
|
116
|
-
err.set_backtrace(e.backtrace)
|
|
117
|
-
raise err
|
|
118
|
-
rescue DataNotFoundError => e
|
|
119
|
-
err = DataNotFoundError.new([ 'organizations', single_org ] + e.path, e)
|
|
120
|
-
err.set_backtrace(e.backtrace)
|
|
121
|
-
raise e
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def skip_organizations?(path, name = nil)
|
|
126
|
-
if path == []
|
|
127
|
-
false
|
|
128
|
-
elsif path[0] == 'organizations'
|
|
129
|
-
if path.size == 1
|
|
130
|
-
false
|
|
131
|
-
elsif path.size >= 2 && path[1] != single_org
|
|
132
|
-
true
|
|
133
|
-
else
|
|
134
|
-
false
|
|
135
|
-
end
|
|
136
|
-
else
|
|
137
|
-
true
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
1
|
+
require 'chef_zero/data_store/interface_v2'
|
|
2
|
+
|
|
3
|
+
module ChefZero
|
|
4
|
+
module DataStore
|
|
5
|
+
class V1ToV2Adapter < ChefZero::DataStore::InterfaceV2
|
|
6
|
+
def initialize(real_store, single_org, options = {})
|
|
7
|
+
@real_store = real_store
|
|
8
|
+
@single_org = single_org
|
|
9
|
+
@options = options
|
|
10
|
+
clear
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_reader :real_store
|
|
14
|
+
attr_reader :single_org
|
|
15
|
+
|
|
16
|
+
def clear
|
|
17
|
+
real_store.clear if real_store.respond_to?(:clear)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_dir(path, name, *options)
|
|
21
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
22
|
+
raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
|
|
23
|
+
raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
|
|
24
|
+
fix_exceptions do
|
|
25
|
+
real_store.create_dir(path[2..-1], name, *options)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create(path, name, data, *options)
|
|
30
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
31
|
+
raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
|
|
32
|
+
raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
|
|
33
|
+
fix_exceptions do
|
|
34
|
+
real_store.create(path[2..-1], name, data, *options)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get(path, request=nil)
|
|
39
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
40
|
+
fix_exceptions do
|
|
41
|
+
# Make it so build_uri will include /organizations/ORG inside the V1 data store
|
|
42
|
+
if request && request.rest_base_prefix.size == 0
|
|
43
|
+
old_base_uri = request.base_uri
|
|
44
|
+
request.base_uri = File.join(request.base_uri, 'organizations', single_org)
|
|
45
|
+
end
|
|
46
|
+
begin
|
|
47
|
+
real_store.get(path[2..-1], request)
|
|
48
|
+
ensure
|
|
49
|
+
request.base_uri = old_base_uri if request && request.rest_base_prefix.size == 0
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def set(path, data, *options)
|
|
55
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
56
|
+
fix_exceptions do
|
|
57
|
+
real_store.set(path[2..-1], data, *options)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def delete(path, *options)
|
|
62
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
|
63
|
+
fix_exceptions do
|
|
64
|
+
real_store.delete(path[2..-1])
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def delete_dir(path, *options)
|
|
69
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
|
70
|
+
fix_exceptions do
|
|
71
|
+
real_store.delete_dir(path[2..-1], *options)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def list(path)
|
|
76
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
|
77
|
+
if path == []
|
|
78
|
+
[ 'organizations' ]
|
|
79
|
+
elsif path == [ 'organizations' ]
|
|
80
|
+
[ single_org ]
|
|
81
|
+
else
|
|
82
|
+
fix_exceptions do
|
|
83
|
+
real_store.list(path[2..-1])
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def exists?(path)
|
|
89
|
+
return false if skip_organizations?(path)
|
|
90
|
+
fix_exceptions do
|
|
91
|
+
real_store.exists?(path[2..-1])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def exists_dir?(path)
|
|
96
|
+
return false if skip_organizations?(path)
|
|
97
|
+
if path == []
|
|
98
|
+
true
|
|
99
|
+
elsif path == [ 'organizations' ] || path == [ 'users' ]
|
|
100
|
+
true
|
|
101
|
+
else
|
|
102
|
+
return false if skip_organizations?(path)
|
|
103
|
+
fix_exceptions do
|
|
104
|
+
real_store.exists_dir?(path[2..-1])
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def fix_exceptions
|
|
112
|
+
begin
|
|
113
|
+
yield
|
|
114
|
+
rescue DataAlreadyExistsError => e
|
|
115
|
+
err = DataAlreadyExistsError.new([ 'organizations', single_org ] + e.path, e)
|
|
116
|
+
err.set_backtrace(e.backtrace)
|
|
117
|
+
raise err
|
|
118
|
+
rescue DataNotFoundError => e
|
|
119
|
+
err = DataNotFoundError.new([ 'organizations', single_org ] + e.path, e)
|
|
120
|
+
err.set_backtrace(e.backtrace)
|
|
121
|
+
raise e
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def skip_organizations?(path, name = nil)
|
|
126
|
+
if path == []
|
|
127
|
+
false
|
|
128
|
+
elsif path[0] == 'organizations'
|
|
129
|
+
if path.size == 1
|
|
130
|
+
false
|
|
131
|
+
elsif path.size >= 2 && path[1] != single_org
|
|
132
|
+
true
|
|
133
|
+
else
|
|
134
|
+
false
|
|
135
|
+
end
|
|
136
|
+
else
|
|
137
|
+
true
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|