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,33 +1,33 @@
|
|
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 "v2_to_v1_adapter"
|
20
|
-
require_relative "memory_store_v2"
|
21
|
-
require_relative "default_facade"
|
22
|
-
|
23
|
-
module ChefZero
|
24
|
-
module DataStore
|
25
|
-
class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
|
26
|
-
def initialize
|
27
|
-
super
|
28
|
-
@real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, "chef", true)
|
29
|
-
clear
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
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 "v2_to_v1_adapter"
|
20
|
+
require_relative "memory_store_v2"
|
21
|
+
require_relative "default_facade"
|
22
|
+
|
23
|
+
module ChefZero
|
24
|
+
module DataStore
|
25
|
+
class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
@real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, "chef", true)
|
29
|
+
clear
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,159 +1,159 @@
|
|
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_already_exists_error"
|
20
|
-
require_relative "data_not_found_error"
|
21
|
-
require_relative "interface_v2"
|
22
|
-
|
23
|
-
module ChefZero
|
24
|
-
module DataStore
|
25
|
-
class MemoryStoreV2 < ChefZero::DataStore::InterfaceV2
|
26
|
-
def initialize
|
27
|
-
clear
|
28
|
-
end
|
29
|
-
|
30
|
-
attr_reader :data
|
31
|
-
|
32
|
-
def clear
|
33
|
-
@data = {}
|
34
|
-
end
|
35
|
-
|
36
|
-
def create_dir(path, name, *options)
|
37
|
-
parent = _get(path, options.include?(:recursive))
|
38
|
-
|
39
|
-
if parent.key?(name)
|
40
|
-
unless options.include?(:recursive)
|
41
|
-
raise DataAlreadyExistsError.new(path + [name])
|
42
|
-
end
|
43
|
-
else
|
44
|
-
parent[name] = {}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def create(path, name, data, *options)
|
49
|
-
unless data.is_a?(String)
|
50
|
-
raise "set only works with strings (given data: #{data.inspect})"
|
51
|
-
end
|
52
|
-
|
53
|
-
parent = _get(path, options.include?(:create_dir))
|
54
|
-
|
55
|
-
if parent.key?(name)
|
56
|
-
raise DataAlreadyExistsError.new(path + [name])
|
57
|
-
end
|
58
|
-
|
59
|
-
parent[name] = data
|
60
|
-
end
|
61
|
-
|
62
|
-
def get(path, request = nil)
|
63
|
-
value = _get(path)
|
64
|
-
if value.is_a?(Hash)
|
65
|
-
raise "get() called on directory #{path.join("/")}"
|
66
|
-
end
|
67
|
-
|
68
|
-
value
|
69
|
-
end
|
70
|
-
|
71
|
-
def set(path, data, *options)
|
72
|
-
unless data.is_a?(String)
|
73
|
-
raise "set only works with strings: #{path} = #{data.inspect}"
|
74
|
-
end
|
75
|
-
|
76
|
-
# Get the parent
|
77
|
-
parent = _get(path[0..-2], options.include?(:create_dir))
|
78
|
-
|
79
|
-
if !options.include?(:create) && !parent[path[-1]]
|
80
|
-
raise DataNotFoundError.new(path)
|
81
|
-
end
|
82
|
-
|
83
|
-
parent[path[-1]] = data
|
84
|
-
end
|
85
|
-
|
86
|
-
def delete(path)
|
87
|
-
parent = _get(path[0, path.length - 1])
|
88
|
-
unless parent.key?(path[-1])
|
89
|
-
raise DataNotFoundError.new(path)
|
90
|
-
end
|
91
|
-
unless parent[path[-1]].is_a?(String)
|
92
|
-
raise "delete only works with strings: #{path}"
|
93
|
-
end
|
94
|
-
|
95
|
-
parent.delete(path[-1])
|
96
|
-
end
|
97
|
-
|
98
|
-
def delete_dir(path, *options)
|
99
|
-
parent = _get(path[0, path.length - 1])
|
100
|
-
unless parent.key?(path[-1])
|
101
|
-
raise DataNotFoundError.new(path)
|
102
|
-
end
|
103
|
-
unless parent[path[-1]].is_a?(Hash)
|
104
|
-
raise "delete_dir only works with directories: #{path}"
|
105
|
-
end
|
106
|
-
|
107
|
-
parent.delete(path[-1])
|
108
|
-
end
|
109
|
-
|
110
|
-
def list(path)
|
111
|
-
dir = _get(path)
|
112
|
-
unless dir.is_a? Hash
|
113
|
-
raise "list only works with directories (#{path} = #{dir.class})"
|
114
|
-
end
|
115
|
-
|
116
|
-
dir.keys.sort
|
117
|
-
end
|
118
|
-
|
119
|
-
def exists?(path, options = {})
|
120
|
-
value = _get(path)
|
121
|
-
if value.is_a?(Hash) && !options[:allow_dirs]
|
122
|
-
raise "exists? does not work with directories (#{path} = #{value.class})"
|
123
|
-
end
|
124
|
-
|
125
|
-
true
|
126
|
-
rescue DataNotFoundError
|
127
|
-
false
|
128
|
-
end
|
129
|
-
|
130
|
-
def exists_dir?(path)
|
131
|
-
dir = _get(path)
|
132
|
-
unless dir.is_a? Hash
|
133
|
-
raise "exists_dir? only works with directories (#{path} = #{dir.class})"
|
134
|
-
end
|
135
|
-
|
136
|
-
true
|
137
|
-
rescue DataNotFoundError
|
138
|
-
false
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
def _get(path, create_dir = false)
|
144
|
-
value = @data
|
145
|
-
path.each_with_index do |path_part, index|
|
146
|
-
unless value.key?(path_part)
|
147
|
-
if create_dir
|
148
|
-
value[path_part] = {}
|
149
|
-
else
|
150
|
-
raise DataNotFoundError.new(path[0, index + 1])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
value = value[path_part]
|
154
|
-
end
|
155
|
-
value
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
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_already_exists_error"
|
20
|
+
require_relative "data_not_found_error"
|
21
|
+
require_relative "interface_v2"
|
22
|
+
|
23
|
+
module ChefZero
|
24
|
+
module DataStore
|
25
|
+
class MemoryStoreV2 < ChefZero::DataStore::InterfaceV2
|
26
|
+
def initialize
|
27
|
+
clear
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :data
|
31
|
+
|
32
|
+
def clear
|
33
|
+
@data = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_dir(path, name, *options)
|
37
|
+
parent = _get(path, options.include?(:recursive))
|
38
|
+
|
39
|
+
if parent.key?(name)
|
40
|
+
unless options.include?(:recursive)
|
41
|
+
raise DataAlreadyExistsError.new(path + [name])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
parent[name] = {}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create(path, name, data, *options)
|
49
|
+
unless data.is_a?(String)
|
50
|
+
raise "set only works with strings (given data: #{data.inspect})"
|
51
|
+
end
|
52
|
+
|
53
|
+
parent = _get(path, options.include?(:create_dir))
|
54
|
+
|
55
|
+
if parent.key?(name)
|
56
|
+
raise DataAlreadyExistsError.new(path + [name])
|
57
|
+
end
|
58
|
+
|
59
|
+
parent[name] = data
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(path, request = nil)
|
63
|
+
value = _get(path)
|
64
|
+
if value.is_a?(Hash)
|
65
|
+
raise "get() called on directory #{path.join("/")}"
|
66
|
+
end
|
67
|
+
|
68
|
+
value
|
69
|
+
end
|
70
|
+
|
71
|
+
def set(path, data, *options)
|
72
|
+
unless data.is_a?(String)
|
73
|
+
raise "set only works with strings: #{path} = #{data.inspect}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get the parent
|
77
|
+
parent = _get(path[0..-2], options.include?(:create_dir))
|
78
|
+
|
79
|
+
if !options.include?(:create) && !parent[path[-1]]
|
80
|
+
raise DataNotFoundError.new(path)
|
81
|
+
end
|
82
|
+
|
83
|
+
parent[path[-1]] = data
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete(path)
|
87
|
+
parent = _get(path[0, path.length - 1])
|
88
|
+
unless parent.key?(path[-1])
|
89
|
+
raise DataNotFoundError.new(path)
|
90
|
+
end
|
91
|
+
unless parent[path[-1]].is_a?(String)
|
92
|
+
raise "delete only works with strings: #{path}"
|
93
|
+
end
|
94
|
+
|
95
|
+
parent.delete(path[-1])
|
96
|
+
end
|
97
|
+
|
98
|
+
def delete_dir(path, *options)
|
99
|
+
parent = _get(path[0, path.length - 1])
|
100
|
+
unless parent.key?(path[-1])
|
101
|
+
raise DataNotFoundError.new(path)
|
102
|
+
end
|
103
|
+
unless parent[path[-1]].is_a?(Hash)
|
104
|
+
raise "delete_dir only works with directories: #{path}"
|
105
|
+
end
|
106
|
+
|
107
|
+
parent.delete(path[-1])
|
108
|
+
end
|
109
|
+
|
110
|
+
def list(path)
|
111
|
+
dir = _get(path)
|
112
|
+
unless dir.is_a? Hash
|
113
|
+
raise "list only works with directories (#{path} = #{dir.class})"
|
114
|
+
end
|
115
|
+
|
116
|
+
dir.keys.sort
|
117
|
+
end
|
118
|
+
|
119
|
+
def exists?(path, options = {})
|
120
|
+
value = _get(path)
|
121
|
+
if value.is_a?(Hash) && !options[:allow_dirs]
|
122
|
+
raise "exists? does not work with directories (#{path} = #{value.class})"
|
123
|
+
end
|
124
|
+
|
125
|
+
true
|
126
|
+
rescue DataNotFoundError
|
127
|
+
false
|
128
|
+
end
|
129
|
+
|
130
|
+
def exists_dir?(path)
|
131
|
+
dir = _get(path)
|
132
|
+
unless dir.is_a? Hash
|
133
|
+
raise "exists_dir? only works with directories (#{path} = #{dir.class})"
|
134
|
+
end
|
135
|
+
|
136
|
+
true
|
137
|
+
rescue DataNotFoundError
|
138
|
+
false
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def _get(path, create_dir = false)
|
144
|
+
value = @data
|
145
|
+
path.each_with_index do |path_part, index|
|
146
|
+
unless value.key?(path_part)
|
147
|
+
if create_dir
|
148
|
+
value[path_part] = {}
|
149
|
+
else
|
150
|
+
raise DataNotFoundError.new(path[0, index + 1])
|
151
|
+
end
|
152
|
+
end
|
153
|
+
value = value[path_part]
|
154
|
+
end
|
155
|
+
value
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -1,143 +1,143 @@
|
|
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_already_exists_error"
|
20
|
-
require_relative "data_not_found_error"
|
21
|
-
require_relative "interface_v2"
|
22
|
-
require "fileutils" unless defined?(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
|
-
|
48
|
-
FileUtils.rm_rf(Path.join(root, entry))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def create_dir(path, name, *options)
|
54
|
-
real_path = path_to(path, name)
|
55
|
-
if options.include?(:recursive)
|
56
|
-
FileUtils.mkdir_p(real_path)
|
57
|
-
else
|
58
|
-
begin
|
59
|
-
Dir.mkdir(File.join(path, name))
|
60
|
-
rescue Errno::ENOENT
|
61
|
-
raise DataNotFoundError.new(path)
|
62
|
-
rescue Errno::EEXIST
|
63
|
-
raise DataAlreadyExistsError.new(path + [name])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def create(path, name, data, *options)
|
69
|
-
if options.include?(:create_dir)
|
70
|
-
FileUtils.mkdir_p(path_to(path))
|
71
|
-
end
|
72
|
-
begin
|
73
|
-
File.open(path_to(path, name), File::WRONLY | File::CREAT | File::EXCL | File::BINARY, internal_encoding: nil) do |file|
|
74
|
-
file.write data
|
75
|
-
end
|
76
|
-
rescue Errno::ENOENT
|
77
|
-
raise DataNotFoundError.new(path)
|
78
|
-
rescue Errno::EEXIST
|
79
|
-
raise DataAlreadyExistsError.new(path + [name])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def get(path, request = nil)
|
84
|
-
IO.read(path_to(path))
|
85
|
-
rescue Errno::ENOENT
|
86
|
-
raise DataNotFoundError.new(path)
|
87
|
-
end
|
88
|
-
|
89
|
-
def set(path, data, *options)
|
90
|
-
if options.include?(:create_dir)
|
91
|
-
FileUtils.mkdir_p(path_to(path[0..-2]))
|
92
|
-
end
|
93
|
-
begin
|
94
|
-
mode = File::WRONLY | File::TRUNC | File::BINARY
|
95
|
-
if options.include?(:create)
|
96
|
-
mode |= File::CREAT
|
97
|
-
end
|
98
|
-
File.open(path_to(path), mode, internal_encoding: nil) do |file|
|
99
|
-
file.write data
|
100
|
-
end
|
101
|
-
rescue Errno::ENOENT
|
102
|
-
raise DataNotFoundError.new(path)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def delete(path)
|
107
|
-
File.delete(path_to(path))
|
108
|
-
rescue Errno::ENOENT
|
109
|
-
raise DataNotFoundError.new(path)
|
110
|
-
end
|
111
|
-
|
112
|
-
def delete_dir(path, *options)
|
113
|
-
if options.include?(:recursive)
|
114
|
-
unless File.exist?(path_to(path))
|
115
|
-
raise DataNotFoundError.new(path)
|
116
|
-
end
|
117
|
-
|
118
|
-
FileUtils.rm_rf(path_to(path))
|
119
|
-
else
|
120
|
-
begin
|
121
|
-
Dir.rmdir(path_to(path))
|
122
|
-
rescue Errno::ENOENT
|
123
|
-
raise DataNotFoundError.new(path)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def list(path)
|
129
|
-
Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
|
130
|
-
rescue Errno::ENOENT
|
131
|
-
raise DataNotFoundError.new(path)
|
132
|
-
end
|
133
|
-
|
134
|
-
def exists?(path, options = {})
|
135
|
-
File.exist?(path_to(path))
|
136
|
-
end
|
137
|
-
|
138
|
-
def exists_dir?(path)
|
139
|
-
File.exist?(path_to(path))
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
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_already_exists_error"
|
20
|
+
require_relative "data_not_found_error"
|
21
|
+
require_relative "interface_v2"
|
22
|
+
require "fileutils" unless defined?(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
|
+
|
48
|
+
FileUtils.rm_rf(Path.join(root, entry))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_dir(path, name, *options)
|
54
|
+
real_path = path_to(path, name)
|
55
|
+
if options.include?(:recursive)
|
56
|
+
FileUtils.mkdir_p(real_path)
|
57
|
+
else
|
58
|
+
begin
|
59
|
+
Dir.mkdir(File.join(path, name))
|
60
|
+
rescue Errno::ENOENT
|
61
|
+
raise DataNotFoundError.new(path)
|
62
|
+
rescue Errno::EEXIST
|
63
|
+
raise DataAlreadyExistsError.new(path + [name])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create(path, name, data, *options)
|
69
|
+
if options.include?(:create_dir)
|
70
|
+
FileUtils.mkdir_p(path_to(path))
|
71
|
+
end
|
72
|
+
begin
|
73
|
+
File.open(path_to(path, name), File::WRONLY | File::CREAT | File::EXCL | File::BINARY, internal_encoding: nil) do |file|
|
74
|
+
file.write data
|
75
|
+
end
|
76
|
+
rescue Errno::ENOENT
|
77
|
+
raise DataNotFoundError.new(path)
|
78
|
+
rescue Errno::EEXIST
|
79
|
+
raise DataAlreadyExistsError.new(path + [name])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def get(path, request = nil)
|
84
|
+
IO.read(path_to(path))
|
85
|
+
rescue Errno::ENOENT
|
86
|
+
raise DataNotFoundError.new(path)
|
87
|
+
end
|
88
|
+
|
89
|
+
def set(path, data, *options)
|
90
|
+
if options.include?(:create_dir)
|
91
|
+
FileUtils.mkdir_p(path_to(path[0..-2]))
|
92
|
+
end
|
93
|
+
begin
|
94
|
+
mode = File::WRONLY | File::TRUNC | File::BINARY
|
95
|
+
if options.include?(:create)
|
96
|
+
mode |= File::CREAT
|
97
|
+
end
|
98
|
+
File.open(path_to(path), mode, internal_encoding: nil) do |file|
|
99
|
+
file.write data
|
100
|
+
end
|
101
|
+
rescue Errno::ENOENT
|
102
|
+
raise DataNotFoundError.new(path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def delete(path)
|
107
|
+
File.delete(path_to(path))
|
108
|
+
rescue Errno::ENOENT
|
109
|
+
raise DataNotFoundError.new(path)
|
110
|
+
end
|
111
|
+
|
112
|
+
def delete_dir(path, *options)
|
113
|
+
if options.include?(:recursive)
|
114
|
+
unless File.exist?(path_to(path))
|
115
|
+
raise DataNotFoundError.new(path)
|
116
|
+
end
|
117
|
+
|
118
|
+
FileUtils.rm_rf(path_to(path))
|
119
|
+
else
|
120
|
+
begin
|
121
|
+
Dir.rmdir(path_to(path))
|
122
|
+
rescue Errno::ENOENT
|
123
|
+
raise DataNotFoundError.new(path)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def list(path)
|
129
|
+
Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
|
130
|
+
rescue Errno::ENOENT
|
131
|
+
raise DataNotFoundError.new(path)
|
132
|
+
end
|
133
|
+
|
134
|
+
def exists?(path, options = {})
|
135
|
+
File.exist?(path_to(path))
|
136
|
+
end
|
137
|
+
|
138
|
+
def exists_dir?(path)
|
139
|
+
File.exist?(path_to(path))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|