chef-zero 3.0 → 3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef_zero/endpoints/acl_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +3 -3
- data/lib/chef_zero/rspec.rb +158 -37
- data/lib/chef_zero/server.rb +52 -6
- data/lib/chef_zero/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73fbe4d3eaf0c4c2c3eb17ebea721a97752812cc
|
4
|
+
data.tar.gz: 1e847cf609c0abfd313ce377378b69bceeba1e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca10f03c87e923b6a1b58c858eb6016129037f808ceb8531fdd33a9072ad021c65447c3931f80e60a310eb83ac8d5a4588b406d93b8cac00eef59d6fae6f77f5
|
7
|
+
data.tar.gz: fe9cf680382bf5c3717544608cd355395c96d3c46160ae9b9140f46bdc7392363070428173e2623cd533a4712393d3853313df952da2753e6046a9933247d912
|
@@ -16,9 +16,9 @@ module ChefZero
|
|
16
16
|
# Where PERM is create,read,update,delete,grant
|
17
17
|
class AclEndpoint < RestBase
|
18
18
|
def validate_request(request)
|
19
|
-
path = request.rest_path[0..-3]
|
19
|
+
path = request.rest_path[0..-3] # Strip off _acl/PERM
|
20
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)
|
21
|
+
acl_path = ChefData::AclPath.get_acl_data_path(path)
|
22
22
|
perm = request.rest_path[-1]
|
23
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)}")
|
@@ -31,7 +31,7 @@ module ChefZero
|
|
31
31
|
|
32
32
|
# /organizations/ORG/association_requests/USERNAME-ORG
|
33
33
|
begin
|
34
|
-
delete_data(request, [ 'organizations', orgname, 'association_requests',
|
34
|
+
delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions)
|
35
35
|
rescue DataStore::DataNotFoundError
|
36
36
|
end
|
37
37
|
|
@@ -15,8 +15,8 @@ module ChefZero
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def post(request)
|
18
|
-
contents = request.body
|
19
|
-
name =
|
18
|
+
contents = JSON.parse(request.body, :create_additions => false)
|
19
|
+
name = contents['name']
|
20
20
|
if name.nil?
|
21
21
|
error(400, "Must specify 'name' in JSON")
|
22
22
|
elsif exists_data_dir?(request, request.rest_path + [ name ])
|
@@ -27,7 +27,7 @@ module ChefZero
|
|
27
27
|
org = {
|
28
28
|
"guid" => UUIDTools::UUID.random_create.to_s.gsub('-', ''),
|
29
29
|
"assigned_at" => Time.now.to_s
|
30
|
-
}
|
30
|
+
}.merge(contents)
|
31
31
|
org_path = request.rest_path + [ name ]
|
32
32
|
set_data(request, org_path + [ 'org' ], JSON.pretty_generate(org))
|
33
33
|
|
data/lib/chef_zero/rspec.rb
CHANGED
@@ -24,6 +24,11 @@ module ChefZero
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def when_the_chef_server(description, *tags, &block)
|
27
|
+
if tags.last.is_a?(Hash)
|
28
|
+
opts = tags.last
|
29
|
+
else
|
30
|
+
opts = {}
|
31
|
+
end
|
27
32
|
context "When the Chef server #{description}", *tags do
|
28
33
|
before :each do
|
29
34
|
|
@@ -33,6 +38,7 @@ module ChefZero
|
|
33
38
|
else
|
34
39
|
default_opts
|
35
40
|
end
|
41
|
+
server_opts = server_opts.merge(opts)
|
36
42
|
|
37
43
|
if ChefZero::RSpec.server && server_opts != ChefZero::RSpec.server.options
|
38
44
|
ChefZero::RSpec.server.stop
|
@@ -77,79 +83,194 @@ module ChefZero
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
def self.organization(name, org = '{}')
|
81
|
-
before(:each)
|
82
|
-
|
83
|
-
|
86
|
+
def self.organization(name, org = '{}', &block)
|
87
|
+
before(:each) { organization(name, org, &block) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def organization(name, org = '{}', &block)
|
91
|
+
ChefZero::RSpec.server.data_store.set([ 'organizations', name, 'org' ], dejsonize(org), :create_dir, :create)
|
92
|
+
prev_org_name = @current_org
|
93
|
+
@current_org = name
|
94
|
+
prev_object_path = @current_object_path
|
95
|
+
@current_object_path = "organizations/#{name}"
|
96
|
+
if block_given?
|
97
|
+
begin
|
98
|
+
instance_eval(&block)
|
99
|
+
ensure
|
100
|
+
@current_org = prev_org_name
|
101
|
+
@current_object_path = prev_object_path
|
102
|
+
end
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|
87
|
-
def self.
|
88
|
-
before(:each)
|
89
|
-
|
90
|
-
|
106
|
+
def self.acl_for(path, data)
|
107
|
+
before(:each) { acl_for(path, data) }
|
108
|
+
end
|
109
|
+
|
110
|
+
def acl_for(path, data)
|
111
|
+
ChefZero::RSpec.server.load_data({ 'acls' => { path => data } }, current_org)
|
112
|
+
end
|
113
|
+
|
114
|
+
def acl(data)
|
115
|
+
acl_for(@current_object_path, data)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.client(name, data, &block)
|
119
|
+
before(:each) { client(name, data, &block) }
|
120
|
+
end
|
121
|
+
|
122
|
+
def client(name, data, &block)
|
123
|
+
with_object_path("clients/#{name}") do
|
124
|
+
ChefZero::RSpec.server.load_data({ 'clients' => { name => data } }, current_org)
|
125
|
+
instance_eval(&block) if block_given?
|
91
126
|
end
|
92
127
|
end
|
93
128
|
|
94
|
-
def self.
|
95
|
-
before(:each)
|
96
|
-
|
97
|
-
|
129
|
+
def self.container(name, data, &block)
|
130
|
+
before(:each) { container(name, data, &block) }
|
131
|
+
end
|
132
|
+
|
133
|
+
def container(name, data, &block)
|
134
|
+
with_object_path("containers/#{name}") do
|
135
|
+
ChefZero::RSpec.server.load_data({ 'containers' => { name => data } }, current_org)
|
136
|
+
instance_eval(&block) if block_given?
|
98
137
|
end
|
99
138
|
end
|
100
139
|
|
101
|
-
def self.
|
102
|
-
before(:each)
|
103
|
-
|
140
|
+
def self.cookbook(name, version, data, options = {}, &block)
|
141
|
+
before(:each) { cookbook(name, version, data, &block) }
|
142
|
+
end
|
143
|
+
|
144
|
+
def cookbook(name, version, data, options = {}, &block)
|
145
|
+
with_object_path("cookbooks/#{name}") do
|
146
|
+
ChefZero::RSpec.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => data.merge(options) }}, current_org)
|
147
|
+
instance_eval(&block) if block_given?
|
104
148
|
end
|
105
149
|
end
|
106
150
|
|
107
|
-
def self.
|
108
|
-
before(:each)
|
109
|
-
|
110
|
-
|
111
|
-
|
151
|
+
def self.data_bag(name, data, &block)
|
152
|
+
before(:each) { data_bag(name, data, &block) }
|
153
|
+
end
|
154
|
+
|
155
|
+
def data_bag(name, data, &block)
|
156
|
+
with_object_path("data/#{name}") do
|
157
|
+
ChefZero::RSpec.server.load_data({ 'data' => { name => data }}, current_org)
|
158
|
+
instance_eval(&block) if block_given?
|
112
159
|
end
|
113
160
|
end
|
114
161
|
|
115
|
-
def self.
|
116
|
-
before(:each) {
|
162
|
+
def self.environment(name, data, &block)
|
163
|
+
before(:each) { environment(name, data, &block) }
|
117
164
|
end
|
118
165
|
|
119
|
-
def
|
120
|
-
|
166
|
+
def environment(name, data, &block)
|
167
|
+
with_object_path("environments/#{name}") do
|
168
|
+
ChefZero::RSpec.server.load_data({ 'environments' => { name => data } }, current_org)
|
169
|
+
instance_eval(&block) if block_given?
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.group(name, data, &block)
|
174
|
+
before(:each) { group(name, data, &block) }
|
121
175
|
end
|
122
176
|
|
123
|
-
def
|
124
|
-
|
177
|
+
def group(name, data, &block)
|
178
|
+
with_object_path("groups/#{name}") do
|
179
|
+
ChefZero::RSpec.server.load_data({ 'groups' => { name => data } }, current_org)
|
180
|
+
instance_eval(&block) if block_given?
|
181
|
+
end
|
125
182
|
end
|
126
183
|
|
127
|
-
def self.
|
128
|
-
before(:each) {
|
184
|
+
def self.node(name, data, &block)
|
185
|
+
before(:each) { node(name, data, &block) }
|
129
186
|
end
|
130
187
|
|
131
|
-
def
|
132
|
-
|
188
|
+
def node(name, data, &block)
|
189
|
+
with_object_path("nodes/#{name}") do
|
190
|
+
ChefZero::RSpec.server.load_data({ 'nodes' => { name => data } }, current_org)
|
191
|
+
instance_eval(&block) if block_given?
|
192
|
+
end
|
133
193
|
end
|
134
194
|
|
135
|
-
def self.
|
136
|
-
before(:each) {
|
195
|
+
def self.org_invite(*usernames)
|
196
|
+
before(:each) { org_invite(*usernames) }
|
137
197
|
end
|
138
198
|
|
139
|
-
def
|
199
|
+
def org_invite(*usernames)
|
200
|
+
ChefZero::RSpec.server.load_data({ 'invites' => usernames }, current_org)
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.org_member(*usernames)
|
204
|
+
before(:each) { org_member(*usernames) }
|
205
|
+
end
|
206
|
+
|
207
|
+
def org_member(*usernames)
|
208
|
+
ChefZero::RSpec.server.load_data({ 'members' => usernames }, current_org)
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.role(name, data, &block)
|
212
|
+
before(:each) { role(name, data, &block) }
|
213
|
+
end
|
214
|
+
|
215
|
+
def role(name, data, &block)
|
216
|
+
with_object_path("roles/#{name}") do
|
217
|
+
ChefZero::RSpec.server.load_data({ 'roles' => { name => data } }, current_org)
|
218
|
+
instance_eval(&block) if block_given?
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.sandbox(name, data, &block)
|
223
|
+
before(:each) { sandbox(name, data, &block) }
|
224
|
+
end
|
225
|
+
|
226
|
+
def sandbox(name, data, &block)
|
227
|
+
with_object_path("sandboxes/#{name}") do
|
228
|
+
ChefZero::RSpec.server.load_data({ 'sandboxes' => { name => data } }, current_org)
|
229
|
+
instance_eval(&block) if block_given?
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.user(name, data, &block)
|
234
|
+
before(:each) { user(name, data, &block) }
|
235
|
+
end
|
236
|
+
|
237
|
+
def user(name, data, &block)
|
140
238
|
if ChefZero::RSpec.server.options[:osc_compat]
|
141
|
-
|
239
|
+
with_object_path("users/#{name}") do
|
240
|
+
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
241
|
+
instance_eval(&block) if block_given?
|
242
|
+
end
|
142
243
|
else
|
143
|
-
|
244
|
+
old_object_path = @current_object_path
|
245
|
+
@current_object_path = "users/#{name}"
|
246
|
+
begin
|
247
|
+
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
248
|
+
instance_eval(&block) if block_given?
|
249
|
+
ensure
|
250
|
+
@current_object_path = old_object_path
|
251
|
+
end
|
144
252
|
end
|
145
253
|
end
|
146
254
|
|
147
|
-
def
|
255
|
+
def dejsonize(data)
|
148
256
|
if data.is_a?(String)
|
149
257
|
data
|
150
258
|
else
|
151
|
-
JSON.pretty_generate(
|
259
|
+
JSON.pretty_generate(data)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def current_org
|
264
|
+
@current_org || ChefZero::RSpec.server.options[:single_org] || nil
|
265
|
+
end
|
266
|
+
|
267
|
+
def with_object_path(object_path)
|
268
|
+
old_object_path = @current_object_path
|
269
|
+
@current_object_path = object_path
|
270
|
+
begin
|
271
|
+
yield if block_given?
|
152
272
|
end
|
273
|
+
@current_object_path = old_object_path
|
153
274
|
end
|
154
275
|
|
155
276
|
# after :each do
|
data/lib/chef_zero/server.rb
CHANGED
@@ -28,6 +28,7 @@ require 'webrick/https'
|
|
28
28
|
|
29
29
|
require 'chef_zero'
|
30
30
|
require 'chef_zero/chef_data/cookbook_data'
|
31
|
+
require 'chef_zero/chef_data/acl_path'
|
31
32
|
require 'chef_zero/rest_router'
|
32
33
|
require 'chef_zero/data_store/memory_store_v2'
|
33
34
|
require 'chef_zero/data_store/v1_to_v2_adapter'
|
@@ -99,7 +100,6 @@ module ChefZero
|
|
99
100
|
@options[:osc_compat] = true
|
100
101
|
end
|
101
102
|
@options.freeze
|
102
|
-
|
103
103
|
ChefZero::Log.level = @options[:log_level].to_sym
|
104
104
|
end
|
105
105
|
|
@@ -356,14 +356,55 @@ module ChefZero
|
|
356
356
|
# }
|
357
357
|
# }
|
358
358
|
# }
|
359
|
-
def load_data(contents, org_name =
|
360
|
-
|
359
|
+
def load_data(contents, org_name = nil)
|
360
|
+
passed_org = !!org_name
|
361
|
+
org_name ||= options[:single_org]
|
362
|
+
if org_name.nil? && contents.keys != [ 'users' ]
|
363
|
+
raise "Must pass an org name to load_data or run in single_org mode"
|
364
|
+
end
|
365
|
+
|
366
|
+
%w(clients containers environments groups nodes roles sandboxes).each do |data_type|
|
361
367
|
if contents[data_type]
|
362
368
|
dejsonize_children(contents[data_type]).each_pair do |name, data|
|
363
369
|
data_store.set(['organizations', org_name, data_type, name], data, :create)
|
364
370
|
end
|
365
371
|
end
|
366
372
|
end
|
373
|
+
|
374
|
+
if contents['users']
|
375
|
+
dejsonize_children(contents['users']).each_pair do |name, data|
|
376
|
+
if options[:osc_compat]
|
377
|
+
data_store.set(['organizations', org_name, 'users', name], data, :create)
|
378
|
+
else
|
379
|
+
# Create the user and put them in the org
|
380
|
+
data_store.set(['users', name], data, :create)
|
381
|
+
if org_name
|
382
|
+
data_store.set(['organizations', org_name, 'users', name], '{}', :create)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
if contents['members']
|
389
|
+
contents['members'].each do |name|
|
390
|
+
data_store.set(['organizations', org_name, 'users', name], '{}', :create)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
if contents['invites']
|
395
|
+
contents['invites'].each do |name|
|
396
|
+
data_store.set(['organizations', org_name, 'association_requests', name], '{}', :create)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
if contents['acls']
|
401
|
+
dejsonize_children(contents['acls']).each do |path, acl|
|
402
|
+
path = [ 'organizations', org_name ] + path.split('/')
|
403
|
+
path = ChefData::AclPath.get_acl_data_path(path)
|
404
|
+
ChefZero::RSpec.server.data_store.set(path, acl)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
367
408
|
if contents['data']
|
368
409
|
contents['data'].each_pair do |key, data_bag|
|
369
410
|
data_store.create_dir(['organizations', org_name, 'data'], key, :recursive)
|
@@ -372,6 +413,7 @@ module ChefZero
|
|
372
413
|
end
|
373
414
|
end
|
374
415
|
end
|
416
|
+
|
375
417
|
if contents['cookbooks']
|
376
418
|
contents['cookbooks'].each_pair do |name_version, cookbook|
|
377
419
|
if name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
|
@@ -425,8 +467,8 @@ module ChefZero
|
|
425
467
|
[ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
|
426
468
|
[ "/users", ActorsEndpoint.new(self, 'username') ],
|
427
469
|
[ "/users/*", ActorEndpoint.new(self, 'username') ],
|
428
|
-
[ "/users
|
429
|
-
[ "/users
|
470
|
+
[ "/users/*/_acl", AclsEndpoint.new(self) ],
|
471
|
+
[ "/users/*/_acl/*", AclEndpoint.new(self) ],
|
430
472
|
[ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
|
431
473
|
[ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
|
432
474
|
[ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
|
@@ -533,11 +575,15 @@ module ChefZero
|
|
533
575
|
def dejsonize_children(hash)
|
534
576
|
result = {}
|
535
577
|
hash.each_pair do |key, value|
|
536
|
-
result[key] =
|
578
|
+
result[key] = dejsonize(value)
|
537
579
|
end
|
538
580
|
result
|
539
581
|
end
|
540
582
|
|
583
|
+
def dejsonize(value)
|
584
|
+
value.is_a?(Hash) ? JSON.pretty_generate(value) : value
|
585
|
+
end
|
586
|
+
|
541
587
|
def get_file(directory, path)
|
542
588
|
value = directory
|
543
589
|
path.split('/').each do |part|
|
data/lib/chef_zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '3.
|
4
|
+
version: '3.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|