chef-zero 15.0.17 → 15.0.21
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/Gemfile +36 -31
- data/LICENSE +201 -201
- data/Rakefile +73 -68
- data/bin/chef-zero +111 -111
- data/chef-zero.gemspec +34 -33
- data/lib/chef_zero/chef_data/acl_path.rb +140 -140
- data/lib/chef_zero/chef_data/cookbook_data.rb +237 -237
- data/lib/chef_zero/chef_data/data_normalizer.rb +276 -276
- data/lib/chef_zero/chef_data/default_creator.rb +476 -476
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +32 -32
- data/lib/chef_zero/data_store/data_not_found_error.rb +29 -29
- data/lib/chef_zero/data_store/default_facade.rb +143 -147
- 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 +159 -159
- data/lib/chef_zero/data_store/raw_file_store.rb +143 -143
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +150 -150
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +105 -105
- data/lib/chef_zero/dist.rb +9 -9
- data/lib/chef_zero/endpoints/acl_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/acls_endpoint.rb +41 -41
- data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +78 -78
- data/lib/chef_zero/endpoints/actor_endpoint.rb +184 -184
- data/lib/chef_zero/endpoints/actor_key_endpoint.rb +62 -62
- data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +129 -129
- data/lib/chef_zero/endpoints/actors_endpoint.rb +104 -104
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +32 -32
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/controls_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +68 -68
- data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +34 -34
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +136 -136
- data/lib/chef_zero/endpoints/cookbooks_base.rb +80 -80
- 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/dummy_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +126 -126
- 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 +34 -34
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/nodes_endpoint.rb +34 -34
- 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 +47 -47
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
- data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +17 -17
- 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 +61 -61
- data/lib/chef_zero/endpoints/policies_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/policy_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/policy_group_endpoint.rb +46 -46
- data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +83 -83
- data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +66 -66
- data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/principal_endpoint.rb +55 -55
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +78 -78
- 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 +51 -51
- data/lib/chef_zero/endpoints/search_endpoint.rb +208 -208
- 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/universe_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +41 -41
- 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 +13 -13
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +332 -332
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +84 -88
- data/lib/chef_zero/rest_router.rb +72 -72
- data/lib/chef_zero/rspec.rb +355 -355
- data/lib/chef_zero/server.rb +730 -730
- data/lib/chef_zero/socketless_server_map.rb +92 -93
- 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 +30 -30
- 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 +41 -41
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +208 -208
- data/lib/chef_zero/version.rb +3 -3
- data/lib/chef_zero.rb +10 -10
- data/spec/run_oc_pedant.rb +226 -226
- data/spec/search_spec.rb +36 -36
- data/spec/server_spec.rb +96 -96
- data/spec/socketless_server_map_spec.rb +74 -74
- data/spec/support/oc_pedant.rb +149 -149
- data/spec/support/secrets.json +6 -6
- data/spec/support/stickywicket.pem +27 -27
- metadata +35 -18
@@ -1,29 +1,29 @@
|
|
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
|
-
# https://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_relative "data_error"
|
20
|
-
|
21
|
-
module ChefZero
|
22
|
-
module DataStore
|
23
|
-
class DataAlreadyExistsError < DataError
|
24
|
-
def initialize(path, cause = nil)
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
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
|
+
# https://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_relative "data_error"
|
20
|
+
|
21
|
+
module ChefZero
|
22
|
+
module DataStore
|
23
|
+
class DataAlreadyExistsError < DataError
|
24
|
+
def initialize(path, cause = nil)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,32 +1,32 @@
|
|
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
|
-
# https://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
|
-
module ChefZero
|
20
|
-
module DataStore
|
21
|
-
class DataError < StandardError
|
22
|
-
attr_reader :path, :cause
|
23
|
-
|
24
|
-
def initialize(path, cause = nil)
|
25
|
-
@path = path
|
26
|
-
@cause = cause
|
27
|
-
path_for_msg = path.nil? ? "nil" : "/#{path.join("/")}"
|
28
|
-
super "Data path: #{path_for_msg}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
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
|
+
# https://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
|
+
module ChefZero
|
20
|
+
module DataStore
|
21
|
+
class DataError < StandardError
|
22
|
+
attr_reader :path, :cause
|
23
|
+
|
24
|
+
def initialize(path, cause = nil)
|
25
|
+
@path = path
|
26
|
+
@cause = cause
|
27
|
+
path_for_msg = path.nil? ? "nil" : "/#{path.join("/")}"
|
28
|
+
super "Data path: #{path_for_msg}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,29 +1,29 @@
|
|
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
|
-
# https://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_relative "data_error"
|
20
|
-
|
21
|
-
module ChefZero
|
22
|
-
module DataStore
|
23
|
-
class DataNotFoundError < DataError
|
24
|
-
def initialize(path, cause = nil)
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
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
|
+
# https://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_relative "data_error"
|
20
|
+
|
21
|
+
module ChefZero
|
22
|
+
module DataStore
|
23
|
+
class DataNotFoundError < DataError
|
24
|
+
def initialize(path, cause = nil)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,147 +1,143 @@
|
|
1
|
-
require_relative "interface_v2"
|
2
|
-
require_relative "../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?(:create_dir))
|
66
|
-
end
|
67
|
-
|
68
|
-
def get(path, request = nil)
|
69
|
-
real_store.get(path, request)
|
70
|
-
rescue DataNotFoundError
|
71
|
-
result = default_creator.get(path)
|
72
|
-
if result
|
73
|
-
FFI_Yajl::Encoder.encode(result, pretty: true)
|
74
|
-
else
|
75
|
-
raise
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def set(path, data, *options)
|
80
|
-
begin
|
81
|
-
real_store.set(path, data, *options)
|
82
|
-
rescue DataNotFoundError
|
83
|
-
if options.include?(:create_dir) ||
|
84
|
-
options.include?(:create) && default_creator.exists?(path[0..-2]) ||
|
85
|
-
default_creator.exists?(path)
|
86
|
-
real_store.set(path, data, :create, :create_dir, *options)
|
87
|
-
else
|
88
|
-
raise
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
if options.include?(:create)
|
93
|
-
options_hash = options.last.is_a?(Hash) ? options.last : {}
|
94
|
-
default_creator.created(path, options_hash[:requestor], options.include?(:create_dir))
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def delete(path, *options)
|
99
|
-
deleted = default_creator.deleted(path)
|
100
|
-
begin
|
101
|
-
real_store.delete(path)
|
102
|
-
rescue DataNotFoundError
|
103
|
-
unless deleted
|
104
|
-
raise
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def delete_dir(path, *options)
|
110
|
-
deleted = default_creator.deleted(path)
|
111
|
-
begin
|
112
|
-
real_store.delete_dir(path, *options)
|
113
|
-
rescue DataNotFoundError
|
114
|
-
unless deleted
|
115
|
-
raise
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def list(path)
|
121
|
-
default_results = default_creator.list(path)
|
122
|
-
begin
|
123
|
-
real_results = real_store.list(path)
|
124
|
-
if default_results
|
125
|
-
(real_results + default_results).uniq
|
126
|
-
else
|
127
|
-
real_results
|
128
|
-
end
|
129
|
-
rescue DataNotFoundError
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
def
|
139
|
-
real_store.
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
1
|
+
require_relative "interface_v2"
|
2
|
+
require_relative "../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?(:create_dir))
|
66
|
+
end
|
67
|
+
|
68
|
+
def get(path, request = nil)
|
69
|
+
real_store.get(path, request)
|
70
|
+
rescue DataNotFoundError
|
71
|
+
result = default_creator.get(path)
|
72
|
+
if result
|
73
|
+
FFI_Yajl::Encoder.encode(result, pretty: true)
|
74
|
+
else
|
75
|
+
raise
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def set(path, data, *options)
|
80
|
+
begin
|
81
|
+
real_store.set(path, data, *options)
|
82
|
+
rescue DataNotFoundError
|
83
|
+
if options.include?(:create_dir) ||
|
84
|
+
options.include?(:create) && default_creator.exists?(path[0..-2]) ||
|
85
|
+
default_creator.exists?(path)
|
86
|
+
real_store.set(path, data, :create, :create_dir, *options)
|
87
|
+
else
|
88
|
+
raise
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
if options.include?(:create)
|
93
|
+
options_hash = options.last.is_a?(Hash) ? options.last : {}
|
94
|
+
default_creator.created(path, options_hash[:requestor], options.include?(:create_dir))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def delete(path, *options)
|
99
|
+
deleted = default_creator.deleted(path)
|
100
|
+
begin
|
101
|
+
real_store.delete(path)
|
102
|
+
rescue DataNotFoundError
|
103
|
+
unless deleted
|
104
|
+
raise
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete_dir(path, *options)
|
110
|
+
deleted = default_creator.deleted(path)
|
111
|
+
begin
|
112
|
+
real_store.delete_dir(path, *options)
|
113
|
+
rescue DataNotFoundError
|
114
|
+
unless deleted
|
115
|
+
raise
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def list(path)
|
121
|
+
default_results = default_creator.list(path)
|
122
|
+
begin
|
123
|
+
real_results = real_store.list(path)
|
124
|
+
if default_results
|
125
|
+
(real_results + default_results).uniq
|
126
|
+
else
|
127
|
+
real_results
|
128
|
+
end
|
129
|
+
rescue DataNotFoundError
|
130
|
+
default_results || raise
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def exists?(path)
|
135
|
+
real_store.exists?(path) || default_creator.exists?(path)
|
136
|
+
end
|
137
|
+
|
138
|
+
def exists_dir?(path)
|
139
|
+
real_store.exists_dir?(path) || default_creator.exists?(path)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module DataStore
|
3
|
-
class InterfaceV1
|
4
|
-
def interface_version
|
5
|
-
1
|
6
|
-
end
|
7
|
-
|
8
|
-
def clear
|
9
|
-
raise "clear not implemented by class #{self.class}"
|
10
|
-
end
|
11
|
-
|
12
|
-
# Create a directory.
|
13
|
-
# options is a list of symbols, including:
|
14
|
-
# :recursive - create any parents needed
|
15
|
-
def create_dir(path, name, *options)
|
16
|
-
raise "create_dir not implemented by class #{self.class}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Create a file.
|
20
|
-
# options is a list of symbols, including:
|
21
|
-
# :create_dir - create any parents needed
|
22
|
-
def create(path, name, data, *options)
|
23
|
-
raise "create not implemented by class #{self.class}"
|
24
|
-
end
|
25
|
-
|
26
|
-
# Get a file.
|
27
|
-
def get(path, request = nil)
|
28
|
-
raise "get not implemented by class #{self.class}"
|
29
|
-
end
|
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
|
35
|
-
def set(path, data, *options)
|
36
|
-
raise "set not implemented by class #{self.class}"
|
37
|
-
end
|
38
|
-
|
39
|
-
# Delete a file.
|
40
|
-
def delete(path)
|
41
|
-
raise "delete not implemented by class #{self.class}"
|
42
|
-
end
|
43
|
-
|
44
|
-
# Delete a directory.
|
45
|
-
# options is a list of symbols, including:
|
46
|
-
# :recursive - delete even if empty
|
47
|
-
def delete_dir(path, *options)
|
48
|
-
raise "delete_dir not implemented by class #{self.class}"
|
49
|
-
end
|
50
|
-
|
51
|
-
# List a directory.
|
52
|
-
def list(path)
|
53
|
-
raise "list not implemented by class #{self.class}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# Check a file's existence.
|
57
|
-
def exists?(path)
|
58
|
-
raise "exists? not implemented by class #{self.class}"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Check a directory's existence.
|
62
|
-
def exists_dir?(path)
|
63
|
-
raise "exists_dir? not implemented by class #{self.class}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module DataStore
|
3
|
+
class InterfaceV1
|
4
|
+
def interface_version
|
5
|
+
1
|
6
|
+
end
|
7
|
+
|
8
|
+
def clear
|
9
|
+
raise "clear not implemented by class #{self.class}"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create a directory.
|
13
|
+
# options is a list of symbols, including:
|
14
|
+
# :recursive - create any parents needed
|
15
|
+
def create_dir(path, name, *options)
|
16
|
+
raise "create_dir not implemented by class #{self.class}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Create a file.
|
20
|
+
# options is a list of symbols, including:
|
21
|
+
# :create_dir - create any parents needed
|
22
|
+
def create(path, name, data, *options)
|
23
|
+
raise "create not implemented by class #{self.class}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get a file.
|
27
|
+
def get(path, request = nil)
|
28
|
+
raise "get not implemented by class #{self.class}"
|
29
|
+
end
|
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
|
35
|
+
def set(path, data, *options)
|
36
|
+
raise "set not implemented by class #{self.class}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Delete a file.
|
40
|
+
def delete(path)
|
41
|
+
raise "delete not implemented by class #{self.class}"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Delete a directory.
|
45
|
+
# options is a list of symbols, including:
|
46
|
+
# :recursive - delete even if empty
|
47
|
+
def delete_dir(path, *options)
|
48
|
+
raise "delete_dir not implemented by class #{self.class}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# List a directory.
|
52
|
+
def list(path)
|
53
|
+
raise "list not implemented by class #{self.class}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Check a file's existence.
|
57
|
+
def exists?(path)
|
58
|
+
raise "exists? not implemented by class #{self.class}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check a directory's existence.
|
62
|
+
def exists_dir?(path)
|
63
|
+
raise "exists_dir? not implemented by class #{self.class}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require_relative "interface_v1"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module DataStore
|
5
|
-
# V2 assumes paths starting with /organizations/ORGNAME. It also REQUIRES that
|
6
|
-
# new organizations have these defaults:
|
7
|
-
# chef-validator client: '{ "validator": true }',
|
8
|
-
# chef-webui client: '{ "admin": true }'
|
9
|
-
# _default environment: '{ "description": "The default Chef environment" }'
|
10
|
-
# admin user: '{ "admin": "true" }'
|
11
|
-
|
12
|
-
class InterfaceV2 < ChefZero::DataStore::InterfaceV1
|
13
|
-
def interface_version
|
14
|
-
2
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require_relative "interface_v1"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module DataStore
|
5
|
+
# V2 assumes paths starting with /organizations/ORGNAME. It also REQUIRES that
|
6
|
+
# new organizations have these defaults:
|
7
|
+
# chef-validator client: '{ "validator": true }',
|
8
|
+
# chef-webui client: '{ "admin": true }'
|
9
|
+
# _default environment: '{ "description": "The default Chef environment" }'
|
10
|
+
# admin user: '{ "admin": "true" }'
|
11
|
+
|
12
|
+
class InterfaceV2 < ChefZero::DataStore::InterfaceV1
|
13
|
+
def interface_version
|
14
|
+
2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|