chef-zero 2.2.1 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,149 @@
|
|
1
|
+
require 'chef_zero/data_store/interface_v2'
|
2
|
+
require 'chef_zero/chef_data/default_creator'
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
module DataStore
|
6
|
+
#
|
7
|
+
# The DefaultFacade exists to layer defaults on top of an existing data
|
8
|
+
# store. When you create an org, you just create the directory itself:
|
9
|
+
# the rest of the org (such as environments/_default) will not actually
|
10
|
+
# exist anywhere, but when you get(/organizations/org/environments/_default),
|
11
|
+
# the DefaultFacade will create one for you on the fly.
|
12
|
+
#
|
13
|
+
# acls in particular are instantiated on the fly using this method.
|
14
|
+
#
|
15
|
+
class DefaultFacade < ChefZero::DataStore::InterfaceV2
|
16
|
+
def initialize(real_store, single_org, osc_compat, superusers = nil)
|
17
|
+
@real_store = real_store
|
18
|
+
@default_creator = ChefData::DefaultCreator.new(self, single_org, osc_compat, superusers)
|
19
|
+
clear
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :real_store
|
23
|
+
attr_reader :default_creator
|
24
|
+
|
25
|
+
def clear
|
26
|
+
real_store.clear if real_store.respond_to?(:clear)
|
27
|
+
default_creator.clear
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_dir(path, name, *options)
|
31
|
+
if default_creator.exists?(path + [ name ]) && !options.include?(:recursive)
|
32
|
+
raise DataAlreadyExistsError.new(path + [name])
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
real_store.create_dir(path, name, *options)
|
37
|
+
rescue DataNotFoundError
|
38
|
+
if default_creator.exists?(path)
|
39
|
+
real_store.create_dir(path, name, :recursive, *options)
|
40
|
+
else
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
options_hash = options.last.is_a?(Hash) ? options.last : {}
|
46
|
+
default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:recursive))
|
47
|
+
end
|
48
|
+
|
49
|
+
def create(path, name, data, *options)
|
50
|
+
if default_creator.exists?(path + [ name ]) && !options.include?(:create_dir)
|
51
|
+
raise DataAlreadyExistsError.new(path + [name])
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
real_store.create(path, name, data, *options)
|
56
|
+
rescue DataNotFoundError
|
57
|
+
if default_creator.exists?(path)
|
58
|
+
real_store.create(path, name, data, :create_dir, *options)
|
59
|
+
else
|
60
|
+
raise
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
options_hash = options.last.is_a?(Hash) ? options.last : {}
|
65
|
+
default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:recursive))
|
66
|
+
end
|
67
|
+
|
68
|
+
def get(path, request=nil)
|
69
|
+
begin
|
70
|
+
real_store.get(path, request)
|
71
|
+
rescue DataNotFoundError
|
72
|
+
result = default_creator.get(path)
|
73
|
+
if result
|
74
|
+
JSON.pretty_generate(result)
|
75
|
+
else
|
76
|
+
raise
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set(path, data, *options)
|
82
|
+
begin
|
83
|
+
real_store.set(path, data, *options)
|
84
|
+
rescue DataNotFoundError
|
85
|
+
if options.include?(:create_dir) ||
|
86
|
+
options.include?(:create) && default_creator.exists?(path[0..-2]) ||
|
87
|
+
default_creator.exists?(path)
|
88
|
+
real_store.set(path, data, :create, :create_dir, *options)
|
89
|
+
else
|
90
|
+
raise
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
if options.include?(:create)
|
95
|
+
options_hash = options.last.is_a?(Hash) ? options.last : {}
|
96
|
+
default_creator.created(path, options_hash[:requestor], options.include?(:create_dir))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def delete(path, *options)
|
101
|
+
deleted = default_creator.deleted(path)
|
102
|
+
begin
|
103
|
+
real_store.delete(path)
|
104
|
+
rescue DataNotFoundError
|
105
|
+
if !deleted
|
106
|
+
raise
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete_dir(path, *options)
|
112
|
+
deleted = default_creator.deleted(path)
|
113
|
+
begin
|
114
|
+
real_store.delete_dir(path, *options)
|
115
|
+
rescue DataNotFoundError
|
116
|
+
if !deleted
|
117
|
+
raise
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def list(path)
|
123
|
+
default_results = default_creator.list(path)
|
124
|
+
begin
|
125
|
+
real_results = real_store.list(path)
|
126
|
+
if default_results
|
127
|
+
(real_results + default_results).uniq
|
128
|
+
else
|
129
|
+
real_results
|
130
|
+
end
|
131
|
+
rescue DataNotFoundError
|
132
|
+
if default_results
|
133
|
+
default_results
|
134
|
+
else
|
135
|
+
raise
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def exists?(path)
|
141
|
+
real_store.exists?(path) || default_creator.exists?(path)
|
142
|
+
end
|
143
|
+
|
144
|
+
def exists_dir?(path)
|
145
|
+
real_store.exists_dir?(path) || default_creator.exists?(path)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -9,38 +9,56 @@ module ChefZero
|
|
9
9
|
raise "clear not implemented by class #{self.class}"
|
10
10
|
end
|
11
11
|
|
12
|
+
# Create a directory.
|
13
|
+
# options is a list of symbols, including:
|
14
|
+
# :recursive - create any parents needed
|
12
15
|
def create_dir(path, name, *options)
|
13
16
|
raise "create_dir not implemented by class #{self.class}"
|
14
17
|
end
|
15
18
|
|
19
|
+
# Create a file.
|
20
|
+
# options is a list of symbols, including:
|
21
|
+
# :create_dir - create any parents needed
|
16
22
|
def create(path, name, data, *options)
|
17
23
|
raise "create not implemented by class #{self.class}"
|
18
24
|
end
|
19
25
|
|
26
|
+
# Get a file.
|
20
27
|
def get(path, request=nil)
|
21
28
|
raise "get not implemented by class #{self.class}"
|
22
29
|
end
|
23
30
|
|
31
|
+
# Set a file's value.
|
32
|
+
# options is a list of symbols, including:
|
33
|
+
# :create - create the file if it does not exist
|
34
|
+
# :create_dir - create the directory if it does not exist
|
24
35
|
def set(path, data, *options)
|
25
36
|
raise "set not implemented by class #{self.class}"
|
26
37
|
end
|
27
38
|
|
39
|
+
# Delete a file.
|
28
40
|
def delete(path)
|
29
41
|
raise "delete not implemented by class #{self.class}"
|
30
42
|
end
|
31
43
|
|
44
|
+
# Delete a directory.
|
45
|
+
# options is a list of symbols, including:
|
46
|
+
# :recursive - delete even if empty
|
32
47
|
def delete_dir(path, *options)
|
33
48
|
raise "delete_dir not implemented by class #{self.class}"
|
34
49
|
end
|
35
50
|
|
51
|
+
# List a directory.
|
36
52
|
def list(path)
|
37
53
|
raise "list not implemented by class #{self.class}"
|
38
54
|
end
|
39
55
|
|
56
|
+
# Check a file's existence.
|
40
57
|
def exists?(path)
|
41
58
|
raise "exists? not implemented by class #{self.class}"
|
42
59
|
end
|
43
60
|
|
61
|
+
# Check a directory's existence.
|
44
62
|
def exists_dir?(path)
|
45
63
|
raise "exists_dir? not implemented by class #{self.class}"
|
46
64
|
end
|
@@ -18,13 +18,14 @@
|
|
18
18
|
|
19
19
|
require 'chef_zero/data_store/v2_to_v1_adapter'
|
20
20
|
require 'chef_zero/data_store/memory_store_v2'
|
21
|
+
require 'chef_zero/data_store/default_facade'
|
21
22
|
|
22
23
|
module ChefZero
|
23
24
|
module DataStore
|
24
25
|
class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
|
25
26
|
def initialize
|
26
27
|
super
|
27
|
-
@real_store = ChefZero::DataStore::MemoryStoreV2.new
|
28
|
+
@real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, 'chef', true)
|
28
29
|
clear
|
29
30
|
end
|
30
31
|
end
|
@@ -31,31 +31,6 @@ module ChefZero
|
|
31
31
|
|
32
32
|
def clear
|
33
33
|
@data = {}
|
34
|
-
|
35
|
-
create_dir([], 'organizations')
|
36
|
-
end
|
37
|
-
|
38
|
-
def create_org
|
39
|
-
org = {
|
40
|
-
'clients' => {
|
41
|
-
'chef-validator' => '{ "validator": true }',
|
42
|
-
'chef-webui' => '{ "admin": true }'
|
43
|
-
},
|
44
|
-
'cookbooks' => {},
|
45
|
-
'data' => {},
|
46
|
-
'environments' => {
|
47
|
-
'_default' => '{ "description": "The default Chef environment" }'
|
48
|
-
},
|
49
|
-
'file_store' => {
|
50
|
-
'checksums' => {}
|
51
|
-
},
|
52
|
-
'nodes' => {},
|
53
|
-
'roles' => {},
|
54
|
-
'sandboxes' => {},
|
55
|
-
'users' => {
|
56
|
-
'admin' => '{ "admin": "true" }'
|
57
|
-
}
|
58
|
-
}
|
59
34
|
end
|
60
35
|
|
61
36
|
def create_dir(path, name, *options)
|
@@ -66,7 +41,7 @@ module ChefZero
|
|
66
41
|
raise DataAlreadyExistsError.new(path + [name])
|
67
42
|
end
|
68
43
|
else
|
69
|
-
|
44
|
+
parent[name] = {}
|
70
45
|
end
|
71
46
|
end
|
72
47
|
|
@@ -139,7 +114,7 @@ module ChefZero
|
|
139
114
|
begin
|
140
115
|
value = _get(path)
|
141
116
|
if value.is_a?(Hash) && !options[:allow_dirs]
|
142
|
-
raise "exists? does not work with directories (#{path} = #{
|
117
|
+
raise "exists? does not work with directories (#{path} = #{value.class})"
|
143
118
|
end
|
144
119
|
return true
|
145
120
|
rescue DataNotFoundError
|
@@ -166,7 +141,7 @@ module ChefZero
|
|
166
141
|
path.each_with_index do |path_part, index|
|
167
142
|
if !value.has_key?(path_part)
|
168
143
|
if create_dir
|
169
|
-
|
144
|
+
value[path_part] = {}
|
170
145
|
else
|
171
146
|
raise DataNotFoundError.new(path[0,index+1])
|
172
147
|
end
|
@@ -175,14 +150,6 @@ module ChefZero
|
|
175
150
|
end
|
176
151
|
value
|
177
152
|
end
|
178
|
-
|
179
|
-
def _create_dir(parent_path, parent, name)
|
180
|
-
if parent_path == [ 'organizations' ]
|
181
|
-
parent[name] = create_org
|
182
|
-
else
|
183
|
-
parent[name] = {}
|
184
|
-
end
|
185
|
-
end
|
186
153
|
end
|
187
154
|
end
|
188
155
|
end
|
@@ -0,0 +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
|
@@ -10,117 +10,87 @@ module ChefZero
|
|
10
10
|
clear
|
11
11
|
end
|
12
12
|
|
13
|
-
ORG_DEFAULTS = {
|
14
|
-
'clients' => {
|
15
|
-
'chef-validator' => '{ "validator": true }',
|
16
|
-
'chef-webui' => '{ "admin": true }'
|
17
|
-
},
|
18
|
-
'environments' => {
|
19
|
-
'_default' => '{ "description": "The default Chef environment" }'
|
20
|
-
},
|
21
|
-
'users' => {
|
22
|
-
'admin' => '{ "admin": "true" }'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
13
|
attr_reader :real_store
|
27
14
|
attr_reader :single_org
|
28
15
|
|
29
16
|
def clear
|
30
|
-
if @options[:org_defaults]
|
31
|
-
@defaults = { 'organizations' => { @single_org => @options[:org_defaults] }}
|
32
|
-
else
|
33
|
-
@defaults = {}
|
34
|
-
end
|
35
17
|
real_store.clear if real_store.respond_to?(:clear)
|
36
18
|
end
|
37
19
|
|
38
20
|
def create_dir(path, name, *options)
|
39
|
-
|
40
|
-
if
|
41
|
-
|
42
|
-
end
|
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
|
43
24
|
fix_exceptions do
|
44
25
|
real_store.create_dir(path[2..-1], name, *options)
|
45
26
|
end
|
46
27
|
end
|
47
28
|
|
48
29
|
def create(path, name, data, *options)
|
49
|
-
|
50
|
-
if
|
51
|
-
|
52
|
-
end
|
53
|
-
remove_default(path, name)
|
54
|
-
|
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
|
55
33
|
fix_exceptions do
|
56
34
|
real_store.create(path[2..-1], name, data, *options)
|
57
35
|
end
|
58
36
|
end
|
59
37
|
|
60
38
|
def get(path, request=nil)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
fix_exceptions do
|
66
|
-
real_store.get(path[2..-1], request)
|
67
|
-
end
|
39
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
40
|
+
fix_exceptions do
|
41
|
+
real_store.get(path[2..-1], request)
|
68
42
|
end
|
69
43
|
end
|
70
44
|
|
71
45
|
def set(path, data, *options)
|
72
|
-
|
73
|
-
remove_default(path)
|
46
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
74
47
|
fix_exceptions do
|
75
48
|
real_store.set(path[2..-1], data, *options)
|
76
49
|
end
|
77
50
|
end
|
78
51
|
|
79
|
-
def delete(path)
|
80
|
-
|
81
|
-
remove_default(path)
|
52
|
+
def delete(path, *options)
|
53
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
82
54
|
fix_exceptions do
|
83
55
|
real_store.delete(path[2..-1])
|
84
56
|
end
|
85
57
|
end
|
86
58
|
|
87
59
|
def delete_dir(path, *options)
|
88
|
-
|
60
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
|
89
61
|
fix_exceptions do
|
90
62
|
real_store.delete_dir(path[2..-1], *options)
|
91
63
|
end
|
92
64
|
end
|
93
65
|
|
94
66
|
def list(path)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
67
|
+
raise DataNotFoundError.new(path) if skip_organizations?(path)
|
68
|
+
if path == []
|
69
|
+
[ 'organizations' ]
|
70
|
+
elsif path == [ 'organizations' ]
|
71
|
+
[ single_org ]
|
72
|
+
else
|
73
|
+
fix_exceptions do
|
74
|
+
real_store.list(path[2..-1])
|
103
75
|
end
|
104
|
-
result
|
105
76
|
end
|
106
77
|
end
|
107
78
|
|
108
79
|
def exists?(path)
|
109
|
-
return
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
fix_exceptions do
|
114
|
-
real_store.exists?(path[2..-1])
|
115
|
-
end
|
80
|
+
return false if skip_organizations?(path)
|
81
|
+
fix_exceptions do
|
82
|
+
real_store.exists?(path[2..-1])
|
116
83
|
end
|
117
84
|
end
|
118
85
|
|
119
86
|
def exists_dir?(path)
|
120
|
-
return
|
121
|
-
if
|
87
|
+
return false if skip_organizations?(path)
|
88
|
+
if path == []
|
89
|
+
true
|
90
|
+
elsif path == [ 'organizations' ] || path == [ 'users' ]
|
122
91
|
true
|
123
92
|
else
|
93
|
+
return false if skip_organizations?(path)
|
124
94
|
fix_exceptions do
|
125
95
|
real_store.exists_dir?(path[2..-1])
|
126
96
|
end
|
@@ -129,40 +99,6 @@ module ChefZero
|
|
129
99
|
|
130
100
|
private
|
131
101
|
|
132
|
-
def using_default?(path, name = nil)
|
133
|
-
path = path + [name] if name
|
134
|
-
result = @defaults
|
135
|
-
path.each do |part|
|
136
|
-
return false if !result.has_key?(part)
|
137
|
-
result = result[part]
|
138
|
-
end
|
139
|
-
!result.nil?
|
140
|
-
end
|
141
|
-
|
142
|
-
def get_default(path, name = nil)
|
143
|
-
path = path + [name] if name
|
144
|
-
result = @defaults
|
145
|
-
path.each do |part|
|
146
|
-
return nil if !result.has_key?(part)
|
147
|
-
result = result[part]
|
148
|
-
end
|
149
|
-
result
|
150
|
-
end
|
151
|
-
|
152
|
-
def remove_default(path, name = nil)
|
153
|
-
dir = name ? path[0..-2] : path
|
154
|
-
default = @defaults
|
155
|
-
dir.each do |part|
|
156
|
-
return if !default.has_key?(part)
|
157
|
-
default = default[part]
|
158
|
-
end
|
159
|
-
|
160
|
-
name = name || path.last
|
161
|
-
if name
|
162
|
-
default.delete(name)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
102
|
def fix_exceptions
|
167
103
|
begin
|
168
104
|
yield
|
@@ -175,17 +111,17 @@ module ChefZero
|
|
175
111
|
|
176
112
|
def skip_organizations?(path, name = nil)
|
177
113
|
if path == []
|
178
|
-
raise "" if name == nil || name != 'organizations'
|
179
|
-
true
|
180
|
-
elsif path == ['organizations']
|
181
|
-
raise "" if name == nil || name != single_org
|
182
|
-
true
|
183
|
-
else
|
184
|
-
raise "Path #{path} must start with /organizations/#{single_org}" if path[0..1] != [ 'organizations', single_org ]
|
185
|
-
if !name
|
186
|
-
raise "Path #{path} must start with /organizations/#{single_org}/<something>" if path.size <= 2
|
187
|
-
end
|
188
114
|
false
|
115
|
+
elsif path[0] == 'organizations'
|
116
|
+
if path.size == 1
|
117
|
+
false
|
118
|
+
elsif path.size >= 2 && path[1] != single_org
|
119
|
+
true
|
120
|
+
else
|
121
|
+
false
|
122
|
+
end
|
123
|
+
else
|
124
|
+
true
|
189
125
|
end
|
190
126
|
end
|
191
127
|
end
|