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
data/lib/chef_zero/server.rb
CHANGED
@@ -16,113 +16,113 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
59
|
-
require
|
60
|
-
require
|
61
|
-
require
|
62
|
-
require
|
63
|
-
require
|
64
|
-
require
|
65
|
-
require
|
66
|
-
require
|
67
|
-
require
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require
|
71
|
-
require
|
72
|
-
require
|
73
|
-
require
|
74
|
-
require
|
75
|
-
require
|
76
|
-
require
|
77
|
-
require
|
78
|
-
require
|
79
|
-
require
|
80
|
-
require
|
81
|
-
require
|
82
|
-
require
|
83
|
-
require
|
84
|
-
require
|
85
|
-
require
|
86
|
-
require
|
87
|
-
require
|
88
|
-
require
|
89
|
-
require
|
90
|
-
require
|
91
|
-
require
|
92
|
-
require
|
93
|
-
require
|
94
|
-
require
|
95
|
-
require
|
96
|
-
require
|
97
|
-
require
|
98
|
-
require
|
99
|
-
require
|
100
|
-
require
|
101
|
-
require
|
102
|
-
require
|
103
|
-
require
|
104
|
-
require
|
105
|
-
require
|
106
|
-
require
|
107
|
-
require
|
19
|
+
require "openssl"
|
20
|
+
require "open-uri"
|
21
|
+
require "rubygems"
|
22
|
+
require "timeout"
|
23
|
+
require "stringio"
|
24
|
+
|
25
|
+
require "rack"
|
26
|
+
require "webrick"
|
27
|
+
require "webrick/https"
|
28
|
+
|
29
|
+
require "chef_zero"
|
30
|
+
require "chef_zero/socketless_server_map"
|
31
|
+
require "chef_zero/chef_data/cookbook_data"
|
32
|
+
require "chef_zero/chef_data/acl_path"
|
33
|
+
require "chef_zero/rest_router"
|
34
|
+
require "chef_zero/data_store/memory_store_v2"
|
35
|
+
require "chef_zero/data_store/v1_to_v2_adapter"
|
36
|
+
require "chef_zero/data_store/default_facade"
|
37
|
+
require "chef_zero/version"
|
38
|
+
|
39
|
+
require "chef_zero/endpoints/rest_list_endpoint"
|
40
|
+
require "chef_zero/endpoints/authenticate_user_endpoint"
|
41
|
+
require "chef_zero/endpoints/acls_endpoint"
|
42
|
+
require "chef_zero/endpoints/acl_endpoint"
|
43
|
+
require "chef_zero/endpoints/actor_endpoint"
|
44
|
+
require "chef_zero/endpoints/actors_endpoint"
|
45
|
+
require "chef_zero/endpoints/actor_key_endpoint"
|
46
|
+
require "chef_zero/endpoints/organization_user_key_endpoint"
|
47
|
+
require "chef_zero/endpoints/organization_user_default_key_endpoint"
|
48
|
+
require "chef_zero/endpoints/organization_user_keys_endpoint"
|
49
|
+
require "chef_zero/endpoints/actor_default_key_endpoint"
|
50
|
+
require "chef_zero/endpoints/actor_keys_endpoint"
|
51
|
+
require "chef_zero/endpoints/cookbooks_endpoint"
|
52
|
+
require "chef_zero/endpoints/cookbook_endpoint"
|
53
|
+
require "chef_zero/endpoints/cookbook_version_endpoint"
|
54
|
+
require "chef_zero/endpoints/cookbook_artifacts_endpoint"
|
55
|
+
require "chef_zero/endpoints/cookbook_artifact_endpoint"
|
56
|
+
require "chef_zero/endpoints/cookbook_artifact_identifier_endpoint"
|
57
|
+
require "chef_zero/endpoints/containers_endpoint"
|
58
|
+
require "chef_zero/endpoints/container_endpoint"
|
59
|
+
require "chef_zero/endpoints/controls_endpoint"
|
60
|
+
require "chef_zero/endpoints/dummy_endpoint"
|
61
|
+
require "chef_zero/endpoints/data_bags_endpoint"
|
62
|
+
require "chef_zero/endpoints/data_bag_endpoint"
|
63
|
+
require "chef_zero/endpoints/data_bag_item_endpoint"
|
64
|
+
require "chef_zero/endpoints/groups_endpoint"
|
65
|
+
require "chef_zero/endpoints/group_endpoint"
|
66
|
+
require "chef_zero/endpoints/environment_endpoint"
|
67
|
+
require "chef_zero/endpoints/environment_cookbooks_endpoint"
|
68
|
+
require "chef_zero/endpoints/environment_cookbook_endpoint"
|
69
|
+
require "chef_zero/endpoints/environment_cookbook_versions_endpoint"
|
70
|
+
require "chef_zero/endpoints/environment_nodes_endpoint"
|
71
|
+
require "chef_zero/endpoints/environment_recipes_endpoint"
|
72
|
+
require "chef_zero/endpoints/environment_role_endpoint"
|
73
|
+
require "chef_zero/endpoints/license_endpoint"
|
74
|
+
require "chef_zero/endpoints/node_endpoint"
|
75
|
+
require "chef_zero/endpoints/nodes_endpoint"
|
76
|
+
require "chef_zero/endpoints/node_identifiers_endpoint"
|
77
|
+
require "chef_zero/endpoints/organizations_endpoint"
|
78
|
+
require "chef_zero/endpoints/organization_endpoint"
|
79
|
+
require "chef_zero/endpoints/organization_association_requests_endpoint"
|
80
|
+
require "chef_zero/endpoints/organization_association_request_endpoint"
|
81
|
+
require "chef_zero/endpoints/organization_authenticate_user_endpoint"
|
82
|
+
require "chef_zero/endpoints/organization_users_endpoint"
|
83
|
+
require "chef_zero/endpoints/organization_user_endpoint"
|
84
|
+
require "chef_zero/endpoints/organization_validator_key_endpoint"
|
85
|
+
require "chef_zero/endpoints/policies_endpoint"
|
86
|
+
require "chef_zero/endpoints/policy_endpoint"
|
87
|
+
require "chef_zero/endpoints/policy_revisions_endpoint"
|
88
|
+
require "chef_zero/endpoints/policy_revision_endpoint"
|
89
|
+
require "chef_zero/endpoints/policy_groups_endpoint"
|
90
|
+
require "chef_zero/endpoints/policy_group_endpoint"
|
91
|
+
require "chef_zero/endpoints/policy_group_policy_endpoint"
|
92
|
+
require "chef_zero/endpoints/principal_endpoint"
|
93
|
+
require "chef_zero/endpoints/role_endpoint"
|
94
|
+
require "chef_zero/endpoints/role_environments_endpoint"
|
95
|
+
require "chef_zero/endpoints/sandboxes_endpoint"
|
96
|
+
require "chef_zero/endpoints/sandbox_endpoint"
|
97
|
+
require "chef_zero/endpoints/searches_endpoint"
|
98
|
+
require "chef_zero/endpoints/search_endpoint"
|
99
|
+
require "chef_zero/endpoints/system_recovery_endpoint"
|
100
|
+
require "chef_zero/endpoints/user_association_requests_endpoint"
|
101
|
+
require "chef_zero/endpoints/user_association_requests_count_endpoint"
|
102
|
+
require "chef_zero/endpoints/user_association_request_endpoint"
|
103
|
+
require "chef_zero/endpoints/user_organizations_endpoint"
|
104
|
+
require "chef_zero/endpoints/file_store_file_endpoint"
|
105
|
+
require "chef_zero/endpoints/not_found_endpoint"
|
106
|
+
require "chef_zero/endpoints/version_endpoint"
|
107
|
+
require "chef_zero/endpoints/server_api_version_endpoint"
|
108
108
|
|
109
109
|
module ChefZero
|
110
110
|
|
111
111
|
class Server
|
112
112
|
|
113
113
|
DEFAULT_OPTIONS = {
|
114
|
-
:host => [
|
114
|
+
:host => ["127.0.0.1"],
|
115
115
|
:port => 8889,
|
116
116
|
:log_level => :warn,
|
117
117
|
:generate_real_keys => true,
|
118
|
-
:single_org =>
|
119
|
-
:ssl => false
|
118
|
+
:single_org => "chef",
|
119
|
+
:ssl => false,
|
120
120
|
}.freeze
|
121
121
|
|
122
122
|
GLOBAL_ENDPOINTS = [
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
"/license",
|
124
|
+
"/version",
|
125
|
+
"/server_api_version",
|
126
126
|
]
|
127
127
|
|
128
128
|
def initialize(options = {})
|
@@ -164,9 +164,9 @@ module ChefZero
|
|
164
164
|
# @return [String]
|
165
165
|
#
|
166
166
|
def url
|
167
|
-
sch = @options[:ssl] ?
|
167
|
+
sch = @options[:ssl] ? "https" : "http"
|
168
168
|
hosts = Array(@options[:host])
|
169
|
-
@url ||= if hosts.first.include?(
|
169
|
+
@url ||= if hosts.first.include?(":")
|
170
170
|
URI("#{sch}://[#{hosts.first}]:#{port}").to_s
|
171
171
|
else
|
172
172
|
URI("#{sch}://#{hosts.first}:#{port}").to_s
|
@@ -178,7 +178,6 @@ module ChefZero
|
|
178
178
|
"chefzero://localhost:#{port}"
|
179
179
|
end
|
180
180
|
|
181
|
-
|
182
181
|
#
|
183
182
|
# The data store for this server (default is in-memory).
|
184
183
|
#
|
@@ -230,7 +229,7 @@ module ChefZero
|
|
230
229
|
|
231
230
|
if publish
|
232
231
|
output = publish.respond_to?(:puts) ? publish : STDOUT
|
233
|
-
output.puts <<-EOH.gsub(/^ {10}/,
|
232
|
+
output.puts <<-EOH.gsub(/^ {10}/, "")
|
234
233
|
>> Starting Chef Zero (v#{ChefZero::VERSION})...
|
235
234
|
EOH
|
236
235
|
end
|
@@ -239,14 +238,14 @@ module ChefZero
|
|
239
238
|
|
240
239
|
if publish
|
241
240
|
output = publish.respond_to?(:puts) ? publish : STDOUT
|
242
|
-
output.puts <<-EOH.gsub(/^ {10}/,
|
241
|
+
output.puts <<-EOH.gsub(/^ {10}/, "")
|
243
242
|
>> WEBrick (v#{WEBrick::VERSION}) on Rack (v#{Rack.release}) is listening at #{url}
|
244
243
|
>> Press CTRL+C to stop
|
245
244
|
|
246
245
|
EOH
|
247
246
|
end
|
248
247
|
|
249
|
-
%w
|
248
|
+
%w{INT TERM}.each do |signal|
|
250
249
|
Signal.trap(signal) do
|
251
250
|
puts "\n>> Stopping Chef Zero..."
|
252
251
|
@server.shutdown
|
@@ -285,15 +284,15 @@ module ChefZero
|
|
285
284
|
:AccessLog => [],
|
286
285
|
:Logger => WEBrick::Log.new(StringIO.new, 7),
|
287
286
|
:RequestTimeout => 300,
|
288
|
-
:SSLEnable
|
289
|
-
:SSLOptions
|
290
|
-
:SSLCertName
|
287
|
+
:SSLEnable => options[:ssl],
|
288
|
+
:SSLOptions => ssl_opts,
|
289
|
+
:SSLCertName => [ [ "CN", WEBrick::Utils.getservername ] ],
|
291
290
|
:StartCallback => proc {
|
292
291
|
@running = true
|
293
292
|
}
|
294
293
|
)
|
295
|
-
ENV[
|
296
|
-
@server.mount(
|
294
|
+
ENV["HTTPS"] = "on" if options[:ssl]
|
295
|
+
@server.mount("/", Rack::Handler::WEBrick, app)
|
297
296
|
|
298
297
|
# Pick a port
|
299
298
|
# If options[:port] can be an Enumerator, an Array, or an Integer,
|
@@ -377,7 +376,7 @@ module ChefZero
|
|
377
376
|
if generate_real_keys?
|
378
377
|
private_key = OpenSSL::PKey::RSA.new(2048)
|
379
378
|
public_key = private_key.public_key.to_s
|
380
|
-
public_key.sub!(/^-----BEGIN RSA PUBLIC KEY-----/,
|
379
|
+
public_key.sub!(/^-----BEGIN RSA PUBLIC KEY-----/, "-----BEGIN PUBLIC KEY-----")
|
381
380
|
public_key.sub!(/-----END RSA PUBLIC KEY-----(\s+)$/, '-----END PUBLIC KEY-----\1')
|
382
381
|
[private_key.to_s, public_key]
|
383
382
|
else
|
@@ -418,84 +417,84 @@ module ChefZero
|
|
418
417
|
# }
|
419
418
|
def load_data(contents, org_name = nil)
|
420
419
|
org_name ||= options[:single_org]
|
421
|
-
if org_name.nil? && contents.keys != [
|
420
|
+
if org_name.nil? && contents.keys != [ "users" ]
|
422
421
|
raise "Must pass an org name to load_data or run in single_org mode"
|
423
422
|
end
|
424
423
|
|
425
|
-
%w
|
424
|
+
%w{clients containers environments groups nodes roles sandboxes}.each do |data_type|
|
426
425
|
if contents[data_type]
|
427
426
|
dejsonize_children(contents[data_type]).each_pair do |name, data|
|
428
|
-
data_store.set([
|
427
|
+
data_store.set(["organizations", org_name, data_type, name], data, :create)
|
429
428
|
end
|
430
429
|
end
|
431
430
|
end
|
432
431
|
|
433
|
-
if contents[
|
434
|
-
dejsonize_children(contents[
|
432
|
+
if contents["users"]
|
433
|
+
dejsonize_children(contents["users"]).each_pair do |name, data|
|
435
434
|
if options[:osc_compat]
|
436
|
-
data_store.set([
|
435
|
+
data_store.set(["organizations", org_name, "users", name], data, :create)
|
437
436
|
else
|
438
437
|
# Create the user and put them in the org
|
439
|
-
data_store.set([
|
438
|
+
data_store.set(["users", name], data, :create)
|
440
439
|
if org_name
|
441
|
-
data_store.set([
|
440
|
+
data_store.set(["organizations", org_name, "users", name], "{}", :create)
|
442
441
|
end
|
443
442
|
end
|
444
443
|
end
|
445
444
|
end
|
446
445
|
|
447
|
-
if contents[
|
448
|
-
contents[
|
449
|
-
data_store.set([
|
446
|
+
if contents["members"]
|
447
|
+
contents["members"].each do |name|
|
448
|
+
data_store.set(["organizations", org_name, "users", name], "{}", :create)
|
450
449
|
end
|
451
450
|
end
|
452
451
|
|
453
|
-
if contents[
|
454
|
-
contents[
|
455
|
-
data_store.set([
|
452
|
+
if contents["invites"]
|
453
|
+
contents["invites"].each do |name|
|
454
|
+
data_store.set(["organizations", org_name, "association_requests", name], "{}", :create)
|
456
455
|
end
|
457
456
|
end
|
458
457
|
|
459
|
-
if contents[
|
460
|
-
dejsonize_children(contents[
|
461
|
-
path = [
|
458
|
+
if contents["acls"]
|
459
|
+
dejsonize_children(contents["acls"]).each do |path, acl|
|
460
|
+
path = [ "organizations", org_name ] + path.split("/")
|
462
461
|
path = ChefData::AclPath.get_acl_data_path(path)
|
463
462
|
ChefZero::RSpec.server.data_store.set(path, acl)
|
464
463
|
end
|
465
464
|
end
|
466
465
|
|
467
|
-
if contents[
|
468
|
-
contents[
|
469
|
-
data_store.create_dir([
|
466
|
+
if contents["data"]
|
467
|
+
contents["data"].each_pair do |key, data_bag|
|
468
|
+
data_store.create_dir(["organizations", org_name, "data"], key, :recursive)
|
470
469
|
dejsonize_children(data_bag).each do |item_name, item|
|
471
|
-
data_store.set([
|
470
|
+
data_store.set(["organizations", org_name, "data", key, item_name], item, :create)
|
472
471
|
end
|
473
472
|
end
|
474
473
|
end
|
475
474
|
|
476
|
-
if contents[
|
477
|
-
contents[
|
475
|
+
if contents["policies"]
|
476
|
+
contents["policies"].each_pair do |policy_name, policy_struct|
|
478
477
|
# data_store.create_dir(['organizations', org_name, 'policies', policy_name], "revisions", :recursive)
|
479
478
|
dejsonize_children(policy_struct).each do |revision, policy_data|
|
480
|
-
data_store.set([
|
479
|
+
data_store.set(["organizations", org_name, "policies", policy_name,
|
481
480
|
"revisions", revision], policy_data, :create, :create_dir)
|
482
481
|
end
|
483
482
|
end
|
484
483
|
end
|
485
484
|
|
486
|
-
if contents[
|
487
|
-
contents[
|
488
|
-
group[
|
489
|
-
data_store.set([
|
485
|
+
if contents["policy_groups"]
|
486
|
+
contents["policy_groups"].each_pair do |group_name, group|
|
487
|
+
group["policies"].each do |policy_name, policy_revision|
|
488
|
+
data_store.set(["organizations", org_name, "policy_groups", group_name, "policies", policy_name], FFI_Yajl::Encoder.encode(policy_revision["revision_id"], :pretty => true), :create, :create_dir)
|
490
489
|
end
|
491
490
|
end
|
492
491
|
end
|
493
492
|
|
494
|
-
%w
|
493
|
+
%w{cookbooks cookbook_artifacts}.each do |cookbook_type|
|
495
494
|
if contents[cookbook_type]
|
496
495
|
contents[cookbook_type].each_pair do |name_version, cookbook|
|
497
|
-
if cookbook_type ==
|
498
|
-
name, dash, identifier = name_version.rpartition(
|
496
|
+
if cookbook_type == "cookbook_artifacts"
|
497
|
+
name, dash, identifier = name_version.rpartition("-")
|
499
498
|
cookbook_data = ChefData::CookbookData.to_hash(cookbook, name, identifier)
|
500
499
|
elsif name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
|
501
500
|
cookbook_data = ChefData::CookbookData.to_hash(cookbook, $1, $2)
|
@@ -503,12 +502,12 @@ module ChefZero
|
|
503
502
|
cookbook_data = ChefData::CookbookData.to_hash(cookbook, name_version)
|
504
503
|
end
|
505
504
|
raise "No version specified" if !cookbook_data[:version]
|
506
|
-
data_store.create_dir([
|
507
|
-
data_store.set([
|
505
|
+
data_store.create_dir(["organizations", org_name, cookbook_type], cookbook_data[:cookbook_name], :recursive)
|
506
|
+
data_store.set(["organizations", org_name, cookbook_type, cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
|
508
507
|
cookbook_data.values.each do |files|
|
509
508
|
next unless files.is_a? Array
|
510
509
|
files.each do |file|
|
511
|
-
data_store.set([
|
510
|
+
data_store.set(["organizations", org_name, "file_store", "checksums", file[:checksum]], get_file(cookbook, file[:path]), :create)
|
512
511
|
end
|
513
512
|
end
|
514
513
|
end
|
@@ -536,48 +535,48 @@ module ChefZero
|
|
536
535
|
|
537
536
|
def endpoints
|
538
537
|
result = if options[:osc_compat]
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
538
|
+
# OSC-only
|
539
|
+
[
|
540
|
+
[ "/organizations/*/users", ActorsEndpoint.new(self) ],
|
541
|
+
[ "/organizations/*/users/*", ActorEndpoint.new(self) ],
|
542
|
+
[ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ],
|
543
|
+
]
|
544
|
+
else
|
545
|
+
# EC-only
|
546
|
+
[
|
547
|
+
[ "/organizations/*/users", OrganizationUsersEndpoint.new(self) ],
|
548
|
+
[ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
|
549
|
+
[ "/users", ActorsEndpoint.new(self, "username") ],
|
550
|
+
[ "/users/*", ActorEndpoint.new(self, "username") ],
|
551
|
+
[ "/users/*/_acl", AclsEndpoint.new(self) ],
|
552
|
+
[ "/users/*/_acl/*", AclEndpoint.new(self) ],
|
553
|
+
[ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
|
554
|
+
[ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
|
555
|
+
[ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
|
556
|
+
[ "/users/*/keys", ActorKeysEndpoint.new(self) ],
|
557
|
+
[ "/users/*/keys/default", ActorDefaultKeyEndpoint.new(self) ],
|
558
|
+
[ "/users/*/keys/*", ActorKeyEndpoint.new(self) ],
|
559
|
+
[ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ],
|
560
|
+
[ "/authenticate_user", AuthenticateUserEndpoint.new(self) ],
|
561
|
+
[ "/system_recovery", SystemRecoveryEndpoint.new(self) ],
|
562
|
+
[ "/license", LicenseEndpoint.new(self) ],
|
563
|
+
[ "/organizations", OrganizationsEndpoint.new(self) ],
|
564
|
+
[ "/organizations/*", OrganizationEndpoint.new(self) ],
|
565
|
+
[ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
|
566
|
+
[ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ],
|
567
|
+
[ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ],
|
568
|
+
[ "/organizations/*/containers", ContainersEndpoint.new(self) ],
|
569
|
+
[ "/organizations/*/containers/*", ContainerEndpoint.new(self) ],
|
570
|
+
[ "/organizations/*/groups", GroupsEndpoint.new(self) ],
|
571
|
+
[ "/organizations/*/groups/*", GroupEndpoint.new(self) ],
|
572
|
+
[ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ],
|
573
|
+
[ "/organizations/*/organizations/_acl", AclsEndpoint.new(self) ],
|
574
|
+
[ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ],
|
575
|
+
[ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ],
|
576
|
+
[ "/organizations/*/organizations/_acl/*", AclEndpoint.new(self) ],
|
577
|
+
[ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ],
|
578
|
+
]
|
579
|
+
end
|
581
580
|
result + [
|
582
581
|
# Both
|
583
582
|
[ "/dummy", DummyEndpoint.new(self) ],
|
@@ -630,7 +629,7 @@ module ChefZero
|
|
630
629
|
[ "/server_api_version", ServerAPIVersionEndpoint.new(self) ],
|
631
630
|
|
632
631
|
# Internal
|
633
|
-
[ "/organizations/*/file_store/**", FileStoreFileEndpoint.new(self) ]
|
632
|
+
[ "/organizations/*/file_store/**", FileStoreFileEndpoint.new(self) ],
|
634
633
|
]
|
635
634
|
end
|
636
635
|
|
@@ -646,13 +645,13 @@ module ChefZero
|
|
646
645
|
router.not_found = NotFoundEndpoint.new
|
647
646
|
|
648
647
|
if options[:single_org]
|
649
|
-
rest_base_prefix = [
|
648
|
+
rest_base_prefix = [ "organizations", options[:single_org] ]
|
650
649
|
else
|
651
650
|
rest_base_prefix = []
|
652
651
|
end
|
653
652
|
@app = proc do |env|
|
654
653
|
begin
|
655
|
-
prefix = global_endpoint?(env[
|
654
|
+
prefix = global_endpoint?(env["PATH_INFO"]) ? [] : rest_base_prefix
|
656
655
|
|
657
656
|
request = RestRequest.new(env, prefix)
|
658
657
|
if @on_request_proc
|
@@ -670,10 +669,10 @@ module ChefZero
|
|
670
669
|
end
|
671
670
|
|
672
671
|
# Insert Server header
|
673
|
-
response[1][
|
672
|
+
response[1]["Server"] = "chef-zero"
|
674
673
|
|
675
674
|
# Add CORS header
|
676
|
-
response[1][
|
675
|
+
response[1]["Access-Control-Allow-Origin"] = "*"
|
677
676
|
|
678
677
|
# Puma expects the response to be an array (chunked responses). Since
|
679
678
|
# we are statically generating data, we won't ever have said chunked
|
@@ -705,7 +704,7 @@ module ChefZero
|
|
705
704
|
|
706
705
|
def get_file(directory, path)
|
707
706
|
value = directory
|
708
|
-
path.split(
|
707
|
+
path.split("/").each do |part|
|
709
708
|
value = value[part]
|
710
709
|
end
|
711
710
|
value
|