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,237 +1,237 @@
|
|
1
|
-
require "digest/md5" unless defined?(Digest::MD5)
|
2
|
-
require "hashie"
|
3
|
-
|
4
|
-
module ChefZero
|
5
|
-
class Mash < ::Hashie::Mash
|
6
|
-
disable_warnings
|
7
|
-
end
|
8
|
-
|
9
|
-
module ChefData
|
10
|
-
module CookbookData
|
11
|
-
class << self
|
12
|
-
def to_hash(cookbook, name, version = nil)
|
13
|
-
frozen = false
|
14
|
-
if cookbook.key?(:frozen)
|
15
|
-
frozen = cookbook[:frozen]
|
16
|
-
cookbook = cookbook.dup
|
17
|
-
cookbook.delete(:frozen)
|
18
|
-
end
|
19
|
-
|
20
|
-
result = files_from(cookbook)
|
21
|
-
recipe_names = result[:all_files].select do |file|
|
22
|
-
file[:name].start_with?("recipes/")
|
23
|
-
end.map do |recipe|
|
24
|
-
recipe_name = recipe[:name][0..-2]
|
25
|
-
recipe_name == "default" ? name : "#{name}::#{recipe_name}"
|
26
|
-
end
|
27
|
-
result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
|
28
|
-
result[:name] = "#{name}-#{result[:metadata][:version]}"
|
29
|
-
result[:json_class] = "Chef::CookbookVersion"
|
30
|
-
result[:cookbook_name] = name
|
31
|
-
result[:version] = result[:metadata][:version]
|
32
|
-
result[:chef_type] = "cookbook_version"
|
33
|
-
result[:frozen?] = true if frozen
|
34
|
-
result
|
35
|
-
end
|
36
|
-
|
37
|
-
def metadata_from(directory, name, version, recipe_names)
|
38
|
-
metadata = PretendCookbookMetadata.new(PretendCookbook.new(name, recipe_names))
|
39
|
-
# If both .rb and .json exist, read .json
|
40
|
-
if has_child(directory, "metadata.json")
|
41
|
-
metadata.from_json(read_file(directory, "metadata.json"))
|
42
|
-
elsif has_child(directory, "metadata.rb")
|
43
|
-
begin
|
44
|
-
file = filename(directory, "metadata.rb") || "(#{name}/metadata.rb)"
|
45
|
-
metadata.instance_eval(read_file(directory, "metadata.rb"), file)
|
46
|
-
rescue
|
47
|
-
ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
result = {}
|
51
|
-
metadata.to_hash.each_pair do |key, value|
|
52
|
-
result[key.to_sym] = value
|
53
|
-
end
|
54
|
-
result[:version] = version if version
|
55
|
-
result
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def files_from(directory)
|
61
|
-
# TODO some support .rb only
|
62
|
-
result = load_files(directory)
|
63
|
-
|
64
|
-
set_specificity(result, :templates)
|
65
|
-
set_specificity(result, :files)
|
66
|
-
|
67
|
-
result = {
|
68
|
-
all_files: result,
|
69
|
-
}
|
70
|
-
result
|
71
|
-
end
|
72
|
-
|
73
|
-
def has_child(directory, name)
|
74
|
-
if directory.is_a?(Hash)
|
75
|
-
directory.key?(name)
|
76
|
-
else
|
77
|
-
directory.child(name).exists?
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def read_file(directory, name)
|
82
|
-
if directory.is_a?(Hash)
|
83
|
-
directory[name]
|
84
|
-
else
|
85
|
-
directory.child(name).read
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def filename(directory, name)
|
90
|
-
if directory.respond_to?(:file_path)
|
91
|
-
File.join(directory.file_path, name)
|
92
|
-
else
|
93
|
-
nil
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def get_directory(directory, name)
|
98
|
-
if directory.is_a?(Hash)
|
99
|
-
directory[name].is_a?(Hash) ? directory[name] : nil
|
100
|
-
else
|
101
|
-
result = directory.child(name)
|
102
|
-
result.dir? ? result : nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def list(directory)
|
107
|
-
if directory.is_a?(Hash)
|
108
|
-
directory.keys
|
109
|
-
else
|
110
|
-
directory.children.map(&:name)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def load_child_files(parent, key, recursive, part)
|
115
|
-
result = load_files(get_directory(parent, key), recursive, part)
|
116
|
-
result.each do |file|
|
117
|
-
file[:path] = "#{key}/#{file[:path]}"
|
118
|
-
end
|
119
|
-
result
|
120
|
-
end
|
121
|
-
|
122
|
-
def load_files(directory, recursive = true, part = nil)
|
123
|
-
result = []
|
124
|
-
if directory
|
125
|
-
list(directory).each do |child_name|
|
126
|
-
dir = get_directory(directory, child_name)
|
127
|
-
if dir
|
128
|
-
child_part = child_name if part.nil?
|
129
|
-
if recursive
|
130
|
-
result += load_child_files(directory, child_name, recursive, child_part)
|
131
|
-
end
|
132
|
-
else
|
133
|
-
result += load_file(read_file(directory, child_name), child_name, part)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
result
|
138
|
-
end
|
139
|
-
|
140
|
-
def load_file(value, name, part = nil)
|
141
|
-
specific_name = part ? "#{part}/#{name}" : name
|
142
|
-
[{
|
143
|
-
name: specific_name,
|
144
|
-
path: name,
|
145
|
-
checksum: Digest::MD5.hexdigest(value),
|
146
|
-
specificity: "default",
|
147
|
-
}]
|
148
|
-
end
|
149
|
-
|
150
|
-
def set_specificity(files, type)
|
151
|
-
files.each do |file|
|
152
|
-
next unless file[:name].split("/")[0] == type.to_s
|
153
|
-
|
154
|
-
parts = file[:path].split("/")
|
155
|
-
file[:specificity] = if parts.size == 2
|
156
|
-
"default"
|
157
|
-
else
|
158
|
-
parts[1]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Just enough cookbook to make a Metadata object
|
165
|
-
class PretendCookbook
|
166
|
-
def initialize(name, fully_qualified_recipe_names)
|
167
|
-
@name = name
|
168
|
-
@fully_qualified_recipe_names = fully_qualified_recipe_names
|
169
|
-
end
|
170
|
-
attr_reader :name, :fully_qualified_recipe_names
|
171
|
-
end
|
172
|
-
|
173
|
-
# Handles loading configuration values from a Chef config file
|
174
|
-
#
|
175
|
-
# @author Justin Campbell <justin.campbell@riotgames.com>
|
176
|
-
class PretendCookbookMetadata < Hash
|
177
|
-
# @param [String] path
|
178
|
-
def initialize(cookbook)
|
179
|
-
name(cookbook.name)
|
180
|
-
recipes(cookbook.fully_qualified_recipe_names)
|
181
|
-
%w{attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes}.each do |hash_arg|
|
182
|
-
self[hash_arg.to_sym] = Mash.new
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def from_json(json)
|
187
|
-
merge!(FFI_Yajl::Parser.parse(json))
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def depends(cookbook, *version_constraints)
|
193
|
-
cookbook_arg(:dependencies, cookbook, version_constraints)
|
194
|
-
end
|
195
|
-
|
196
|
-
def supports(cookbook, *version_constraints)
|
197
|
-
cookbook_arg(:supports, cookbook, version_constraints)
|
198
|
-
end
|
199
|
-
|
200
|
-
def provides(cookbook, *version_constraints)
|
201
|
-
cookbook_arg(:providing, cookbook, version_constraints)
|
202
|
-
end
|
203
|
-
|
204
|
-
def gem(*opts)
|
205
|
-
self[:gems] ||= []
|
206
|
-
self[:gems] << opts
|
207
|
-
end
|
208
|
-
|
209
|
-
def recipe(recipe, description)
|
210
|
-
self[:recipes][recipe] = description
|
211
|
-
end
|
212
|
-
|
213
|
-
def attribute(name, options)
|
214
|
-
self[:attributes][name] = options
|
215
|
-
end
|
216
|
-
|
217
|
-
def cookbook_arg(key, cookbook, version_constraints)
|
218
|
-
self[key][cookbook] = version_constraints.first || ">= 0.0.0"
|
219
|
-
end
|
220
|
-
|
221
|
-
def method_missing(key, *values)
|
222
|
-
if values.nil?
|
223
|
-
self[key.to_sym]
|
224
|
-
else
|
225
|
-
if values.length > 1
|
226
|
-
store key.to_sym, values
|
227
|
-
else
|
228
|
-
store key.to_sym, values.first
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
CookbookData = ChefData::CookbookData
|
237
|
-
end
|
1
|
+
require "digest/md5" unless defined?(Digest::MD5)
|
2
|
+
require "hashie"
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
class Mash < ::Hashie::Mash
|
6
|
+
disable_warnings
|
7
|
+
end
|
8
|
+
|
9
|
+
module ChefData
|
10
|
+
module CookbookData
|
11
|
+
class << self
|
12
|
+
def to_hash(cookbook, name, version = nil)
|
13
|
+
frozen = false
|
14
|
+
if cookbook.key?(:frozen)
|
15
|
+
frozen = cookbook[:frozen]
|
16
|
+
cookbook = cookbook.dup
|
17
|
+
cookbook.delete(:frozen)
|
18
|
+
end
|
19
|
+
|
20
|
+
result = files_from(cookbook)
|
21
|
+
recipe_names = result[:all_files].select do |file|
|
22
|
+
file[:name].start_with?("recipes/")
|
23
|
+
end.map do |recipe|
|
24
|
+
recipe_name = recipe[:name][0..-2]
|
25
|
+
recipe_name == "default" ? name : "#{name}::#{recipe_name}"
|
26
|
+
end
|
27
|
+
result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
|
28
|
+
result[:name] = "#{name}-#{result[:metadata][:version]}"
|
29
|
+
result[:json_class] = "Chef::CookbookVersion"
|
30
|
+
result[:cookbook_name] = name
|
31
|
+
result[:version] = result[:metadata][:version]
|
32
|
+
result[:chef_type] = "cookbook_version"
|
33
|
+
result[:frozen?] = true if frozen
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def metadata_from(directory, name, version, recipe_names)
|
38
|
+
metadata = PretendCookbookMetadata.new(PretendCookbook.new(name, recipe_names))
|
39
|
+
# If both .rb and .json exist, read .json
|
40
|
+
if has_child(directory, "metadata.json")
|
41
|
+
metadata.from_json(read_file(directory, "metadata.json"))
|
42
|
+
elsif has_child(directory, "metadata.rb")
|
43
|
+
begin
|
44
|
+
file = filename(directory, "metadata.rb") || "(#{name}/metadata.rb)"
|
45
|
+
metadata.instance_eval(read_file(directory, "metadata.rb"), file)
|
46
|
+
rescue
|
47
|
+
ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
result = {}
|
51
|
+
metadata.to_hash.each_pair do |key, value|
|
52
|
+
result[key.to_sym] = value
|
53
|
+
end
|
54
|
+
result[:version] = version if version
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def files_from(directory)
|
61
|
+
# TODO some support .rb only
|
62
|
+
result = load_files(directory)
|
63
|
+
|
64
|
+
set_specificity(result, :templates)
|
65
|
+
set_specificity(result, :files)
|
66
|
+
|
67
|
+
result = {
|
68
|
+
all_files: result,
|
69
|
+
}
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def has_child(directory, name)
|
74
|
+
if directory.is_a?(Hash)
|
75
|
+
directory.key?(name)
|
76
|
+
else
|
77
|
+
directory.child(name).exists?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def read_file(directory, name)
|
82
|
+
if directory.is_a?(Hash)
|
83
|
+
directory[name]
|
84
|
+
else
|
85
|
+
directory.child(name).read
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def filename(directory, name)
|
90
|
+
if directory.respond_to?(:file_path)
|
91
|
+
File.join(directory.file_path, name)
|
92
|
+
else
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_directory(directory, name)
|
98
|
+
if directory.is_a?(Hash)
|
99
|
+
directory[name].is_a?(Hash) ? directory[name] : nil
|
100
|
+
else
|
101
|
+
result = directory.child(name)
|
102
|
+
result.dir? ? result : nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def list(directory)
|
107
|
+
if directory.is_a?(Hash)
|
108
|
+
directory.keys
|
109
|
+
else
|
110
|
+
directory.children.map(&:name)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def load_child_files(parent, key, recursive, part)
|
115
|
+
result = load_files(get_directory(parent, key), recursive, part)
|
116
|
+
result.each do |file|
|
117
|
+
file[:path] = "#{key}/#{file[:path]}"
|
118
|
+
end
|
119
|
+
result
|
120
|
+
end
|
121
|
+
|
122
|
+
def load_files(directory, recursive = true, part = nil)
|
123
|
+
result = []
|
124
|
+
if directory
|
125
|
+
list(directory).each do |child_name|
|
126
|
+
dir = get_directory(directory, child_name)
|
127
|
+
if dir
|
128
|
+
child_part = child_name if part.nil?
|
129
|
+
if recursive
|
130
|
+
result += load_child_files(directory, child_name, recursive, child_part)
|
131
|
+
end
|
132
|
+
else
|
133
|
+
result += load_file(read_file(directory, child_name), child_name, part)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
result
|
138
|
+
end
|
139
|
+
|
140
|
+
def load_file(value, name, part = nil)
|
141
|
+
specific_name = part ? "#{part}/#{name}" : name
|
142
|
+
[{
|
143
|
+
name: specific_name,
|
144
|
+
path: name,
|
145
|
+
checksum: Digest::MD5.hexdigest(value),
|
146
|
+
specificity: "default",
|
147
|
+
}]
|
148
|
+
end
|
149
|
+
|
150
|
+
def set_specificity(files, type)
|
151
|
+
files.each do |file|
|
152
|
+
next unless file[:name].split("/")[0] == type.to_s
|
153
|
+
|
154
|
+
parts = file[:path].split("/")
|
155
|
+
file[:specificity] = if parts.size == 2
|
156
|
+
"default"
|
157
|
+
else
|
158
|
+
parts[1]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Just enough cookbook to make a Metadata object
|
165
|
+
class PretendCookbook
|
166
|
+
def initialize(name, fully_qualified_recipe_names)
|
167
|
+
@name = name
|
168
|
+
@fully_qualified_recipe_names = fully_qualified_recipe_names
|
169
|
+
end
|
170
|
+
attr_reader :name, :fully_qualified_recipe_names
|
171
|
+
end
|
172
|
+
|
173
|
+
# Handles loading configuration values from a Chef config file
|
174
|
+
#
|
175
|
+
# @author Justin Campbell <justin.campbell@riotgames.com>
|
176
|
+
class PretendCookbookMetadata < Hash
|
177
|
+
# @param [String] path
|
178
|
+
def initialize(cookbook)
|
179
|
+
name(cookbook.name)
|
180
|
+
recipes(cookbook.fully_qualified_recipe_names)
|
181
|
+
%w{attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes}.each do |hash_arg|
|
182
|
+
self[hash_arg.to_sym] = Mash.new
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def from_json(json)
|
187
|
+
merge!(FFI_Yajl::Parser.parse(json))
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def depends(cookbook, *version_constraints)
|
193
|
+
cookbook_arg(:dependencies, cookbook, version_constraints)
|
194
|
+
end
|
195
|
+
|
196
|
+
def supports(cookbook, *version_constraints)
|
197
|
+
cookbook_arg(:supports, cookbook, version_constraints)
|
198
|
+
end
|
199
|
+
|
200
|
+
def provides(cookbook, *version_constraints)
|
201
|
+
cookbook_arg(:providing, cookbook, version_constraints)
|
202
|
+
end
|
203
|
+
|
204
|
+
def gem(*opts)
|
205
|
+
self[:gems] ||= []
|
206
|
+
self[:gems] << opts
|
207
|
+
end
|
208
|
+
|
209
|
+
def recipe(recipe, description)
|
210
|
+
self[:recipes][recipe] = description
|
211
|
+
end
|
212
|
+
|
213
|
+
def attribute(name, options)
|
214
|
+
self[:attributes][name] = options
|
215
|
+
end
|
216
|
+
|
217
|
+
def cookbook_arg(key, cookbook, version_constraints)
|
218
|
+
self[key][cookbook] = version_constraints.first || ">= 0.0.0"
|
219
|
+
end
|
220
|
+
|
221
|
+
def method_missing(key, *values)
|
222
|
+
if values.nil?
|
223
|
+
self[key.to_sym]
|
224
|
+
else
|
225
|
+
if values.length > 1
|
226
|
+
store key.to_sym, values
|
227
|
+
else
|
228
|
+
store key.to_sym, values.first
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
CookbookData = ChefData::CookbookData
|
237
|
+
end
|