chef-zero 4.3.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/README.md +155 -155
  4. data/Rakefile +31 -31
  5. data/bin/chef-zero +100 -100
  6. data/lib/chef_zero.rb +10 -10
  7. data/lib/chef_zero/chef_data/acl_path.rb +139 -139
  8. data/lib/chef_zero/chef_data/cookbook_data.rb +240 -240
  9. data/lib/chef_zero/chef_data/data_normalizer.rb +208 -207
  10. data/lib/chef_zero/chef_data/default_creator.rb +446 -446
  11. data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
  12. data/lib/chef_zero/data_store/data_error.rb +31 -31
  13. data/lib/chef_zero/data_store/data_not_found_error.rb +28 -28
  14. data/lib/chef_zero/data_store/default_facade.rb +149 -149
  15. data/lib/chef_zero/data_store/interface_v1.rb +67 -67
  16. data/lib/chef_zero/data_store/interface_v2.rb +18 -18
  17. data/lib/chef_zero/data_store/memory_store.rb +33 -33
  18. data/lib/chef_zero/data_store/memory_store_v2.rb +155 -155
  19. data/lib/chef_zero/data_store/raw_file_store.rb +147 -147
  20. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +142 -142
  21. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -107
  22. data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -38
  23. data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -29
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +94 -94
  25. data/lib/chef_zero/endpoints/actors_endpoint.rb +64 -64
  26. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +31 -31
  27. data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
  28. data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -13
  29. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
  30. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +119 -119
  31. data/lib/chef_zero/endpoints/cookbooks_base.rb +65 -65
  32. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
  33. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
  34. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
  35. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
  36. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
  37. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +123 -123
  38. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
  39. data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
  40. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
  41. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
  42. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
  43. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
  44. data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
  45. data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
  46. data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
  47. data/lib/chef_zero/endpoints/node_endpoint.rb +17 -17
  48. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
  49. data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
  50. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
  51. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -30
  52. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
  53. data/lib/chef_zero/endpoints/organization_endpoint.rb +46 -46
  54. data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
  55. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
  56. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -43
  57. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
  58. data/lib/chef_zero/endpoints/organizations_endpoint.rb +62 -62
  59. data/lib/chef_zero/endpoints/policies_endpoint.rb +151 -151
  60. data/lib/chef_zero/endpoints/principal_endpoint.rb +42 -42
  61. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
  62. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +63 -63
  63. data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
  64. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
  65. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
  66. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +50 -50
  67. data/lib/chef_zero/endpoints/search_endpoint.rb +194 -194
  68. data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
  69. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -14
  70. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
  71. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -40
  72. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
  73. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
  74. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
  75. data/lib/chef_zero/endpoints/version_endpoint.rb +12 -12
  76. data/lib/chef_zero/log.rb +7 -7
  77. data/lib/chef_zero/rest_base.rb +242 -242
  78. data/lib/chef_zero/rest_error_response.rb +11 -11
  79. data/lib/chef_zero/rest_request.rb +69 -69
  80. data/lib/chef_zero/rest_router.rb +45 -45
  81. data/lib/chef_zero/rspec.rb +308 -308
  82. data/lib/chef_zero/server.rb +642 -642
  83. data/lib/chef_zero/socketless_server_map.rb +92 -92
  84. data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
  85. data/lib/chef_zero/solr/query/phrase.rb +23 -23
  86. data/lib/chef_zero/solr/query/range_query.rb +46 -46
  87. data/lib/chef_zero/solr/query/regexpable_query.rb +29 -29
  88. data/lib/chef_zero/solr/query/subquery.rb +37 -37
  89. data/lib/chef_zero/solr/query/term.rb +45 -45
  90. data/lib/chef_zero/solr/query/unary_operator.rb +43 -43
  91. data/lib/chef_zero/solr/solr_doc.rb +53 -53
  92. data/lib/chef_zero/solr/solr_parser.rb +203 -203
  93. data/lib/chef_zero/version.rb +3 -3
  94. data/spec/run_oc_pedant.rb +63 -63
  95. data/spec/search_spec.rb +32 -32
  96. data/spec/server_spec.rb +92 -92
  97. data/spec/socketless_server_map_spec.rb +76 -76
  98. data/spec/support/oc_pedant.rb +132 -132
  99. data/spec/support/stickywicket.pem +27 -27
  100. metadata +3 -3
@@ -1,240 +1,240 @@
1
- require 'digest/md5'
2
- require 'hashie/mash'
3
-
4
- module ChefZero
5
- module ChefData
6
- module CookbookData
7
- def self.to_hash(cookbook, name, version=nil)
8
- frozen = false
9
- if cookbook.has_key?(:frozen)
10
- frozen = cookbook[:frozen]
11
- cookbook = cookbook.dup
12
- cookbook.delete(:frozen)
13
- end
14
-
15
- result = files_from(cookbook)
16
- recipe_names = result[:recipes].map do |recipe|
17
- recipe_name = recipe[:name][0..-2]
18
- recipe_name == 'default' ? name : "#{name}::#{recipe_name}"
19
- end
20
- result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
21
- result[:name] = "#{name}-#{result[:metadata][:version]}"
22
- result[:json_class] = 'Chef::CookbookVersion'
23
- result[:cookbook_name] = name
24
- result[:version] = result[:metadata][:version]
25
- result[:chef_type] = 'cookbook_version'
26
- result[:frozen?] = true if frozen
27
- result
28
- end
29
-
30
- def self.metadata_from(directory, name, version, recipe_names)
31
- metadata = PretendCookbookMetadata.new(PretendCookbook.new(name, recipe_names))
32
- # If both .rb and .json exist, read .rb
33
- # TODO if recipes has 3 recipes in it, and the Ruby/JSON has only one, should
34
- # the resulting recipe list have 1, or 3-4 recipes in it?
35
- if has_child(directory, 'metadata.rb')
36
- begin
37
- file = filename(directory, 'metadata.rb') || "(#{name}/metadata.rb)"
38
- metadata.instance_eval(read_file(directory, 'metadata.rb'), file)
39
- rescue
40
- ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
41
- end
42
- elsif has_child(directory, 'metadata.json')
43
- metadata.from_json(read_file(directory, 'metadata.json'))
44
- end
45
- result = {}
46
- metadata.to_hash.each_pair do |key,value|
47
- result[key.to_sym] = value
48
- end
49
- result[:version] = version if version
50
- result
51
- end
52
-
53
- private
54
-
55
- # Just enough cookbook to make a Metadata object
56
- class PretendCookbook
57
- def initialize(name, fully_qualified_recipe_names)
58
- @name = name
59
- @fully_qualified_recipe_names = fully_qualified_recipe_names
60
- end
61
- attr_reader :name, :fully_qualified_recipe_names
62
- end
63
-
64
- # Handles loading configuration values from a Chef config file
65
- #
66
- # @author Justin Campbell <justin.campbell@riotgames.com>
67
- class PretendCookbookMetadata < Hash
68
- # @param [String] path
69
- def initialize(cookbook)
70
- self.name(cookbook.name)
71
- self.recipes(cookbook.fully_qualified_recipe_names)
72
- %w(attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes).each do |hash_arg|
73
- self[hash_arg.to_sym] = Hashie::Mash.new
74
- end
75
- end
76
-
77
- def from_json(json)
78
- self.merge!(FFI_Yajl::Parser.parse(json))
79
- end
80
-
81
- private
82
-
83
- def depends(cookbook, *version_constraints)
84
- cookbook_arg(:dependencies, cookbook, version_constraints)
85
- end
86
-
87
- def supports(cookbook, *version_constraints)
88
- cookbook_arg(:supports, cookbook, version_constraints)
89
- end
90
-
91
- def recommends(cookbook, *version_constraints)
92
- cookbook_arg(:recommendations, cookbook, version_constraints)
93
- end
94
-
95
- def suggests(cookbook, *version_constraints)
96
- cookbook_arg(:suggestions, cookbook, version_constraints)
97
- end
98
-
99
- def conflicts(cookbook, *version_constraints)
100
- cookbook_arg(:conflicting, cookbook, version_constraints)
101
- end
102
-
103
- def provides(cookbook, *version_constraints)
104
- cookbook_arg(:providing, cookbook, version_constraints)
105
- end
106
-
107
- def replaces(cookbook, *version_constraints)
108
- cookbook_arg(:replacing, cookbook, version_constraints)
109
- end
110
-
111
- def recipe(recipe, description)
112
- self[:recipes][recipe] = description
113
- end
114
-
115
- def attribute(name, options)
116
- self[:attributes][name] = options
117
- end
118
-
119
- def grouping(name, options)
120
- self[:grouping][name] = options
121
- end
122
-
123
- def cookbook_arg(key, cookbook, version_constraints)
124
- self[key][cookbook] = version_constraints.first || ">= 0.0.0"
125
- end
126
-
127
- def method_missing(key, value = nil)
128
- if value.nil?
129
- self[key.to_sym]
130
- else
131
- store key.to_sym, value
132
- end
133
- end
134
- end
135
-
136
- def self.files_from(directory)
137
- # TODO some support .rb only
138
- result = {
139
- :attributes => load_child_files(directory, 'attributes', false),
140
- :definitions => load_child_files(directory, 'definitions', false),
141
- :recipes => load_child_files(directory, 'recipes', false),
142
- :libraries => load_child_files(directory, 'libraries', false),
143
- :templates => load_child_files(directory, 'templates', true),
144
- :files => load_child_files(directory, 'files', true),
145
- :resources => load_child_files(directory, 'resources', true),
146
- :providers => load_child_files(directory, 'providers', true),
147
- :root_files => load_files(directory, false)
148
- }
149
- set_specificity(result[:templates])
150
- set_specificity(result[:files])
151
- result
152
- end
153
-
154
- def self.has_child(directory, name)
155
- if directory.is_a?(Hash)
156
- directory.has_key?(name)
157
- else
158
- directory.child(name).exists?
159
- end
160
- end
161
-
162
- def self.read_file(directory, name)
163
- if directory.is_a?(Hash)
164
- directory[name]
165
- else
166
- directory.child(name).read
167
- end
168
- end
169
-
170
- def self.filename(directory, name)
171
- if directory.respond_to?(:file_path)
172
- File.join(directory.file_path, name)
173
- else
174
- nil
175
- end
176
- end
177
-
178
- def self.get_directory(directory, name)
179
- if directory.is_a?(Hash)
180
- directory[name].is_a?(Hash) ? directory[name] : nil
181
- else
182
- result = directory.child(name)
183
- result.dir? ? result : nil
184
- end
185
- end
186
-
187
- def self.list(directory)
188
- if directory.is_a?(Hash)
189
- directory.keys
190
- else
191
- directory.children.map { |c| c.name }
192
- end
193
- end
194
-
195
- def self.load_child_files(parent, key, recursive)
196
- result = load_files(get_directory(parent, key), recursive)
197
- result.each do |file|
198
- file[:path] = "#{key}/#{file[:path]}"
199
- end
200
- result
201
- end
202
-
203
- def self.load_files(directory, recursive)
204
- result = []
205
- if directory
206
- list(directory).each do |child_name|
207
- dir = get_directory(directory, child_name)
208
- if dir
209
- if recursive
210
- result += load_child_files(directory, child_name, recursive)
211
- end
212
- else
213
- result += load_file(read_file(directory, child_name), child_name)
214
- end
215
- end
216
- end
217
- result
218
- end
219
-
220
- def self.load_file(value, name)
221
- [{
222
- :name => name,
223
- :path => name,
224
- :checksum => Digest::MD5.hexdigest(value),
225
- :specificity => 'default'
226
- }]
227
- end
228
-
229
- def self.set_specificity(files)
230
- files.each do |file|
231
- parts = file[:path].split('/')
232
- raise "Only directories are allowed directly under templates or files: #{file[:path]}" if parts.size == 2
233
- file[:specificity] = parts[1]
234
- end
235
- end
236
- end
237
- end
238
-
239
- CookbookData = ChefData::CookbookData
240
- end
1
+ require 'digest/md5'
2
+ require 'hashie/mash'
3
+
4
+ module ChefZero
5
+ module ChefData
6
+ module CookbookData
7
+ def self.to_hash(cookbook, name, version=nil)
8
+ frozen = false
9
+ if cookbook.has_key?(:frozen)
10
+ frozen = cookbook[:frozen]
11
+ cookbook = cookbook.dup
12
+ cookbook.delete(:frozen)
13
+ end
14
+
15
+ result = files_from(cookbook)
16
+ recipe_names = result[:recipes].map do |recipe|
17
+ recipe_name = recipe[:name][0..-2]
18
+ recipe_name == 'default' ? name : "#{name}::#{recipe_name}"
19
+ end
20
+ result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
21
+ result[:name] = "#{name}-#{result[:metadata][:version]}"
22
+ result[:json_class] = 'Chef::CookbookVersion'
23
+ result[:cookbook_name] = name
24
+ result[:version] = result[:metadata][:version]
25
+ result[:chef_type] = 'cookbook_version'
26
+ result[:frozen?] = true if frozen
27
+ result
28
+ end
29
+
30
+ def self.metadata_from(directory, name, version, recipe_names)
31
+ metadata = PretendCookbookMetadata.new(PretendCookbook.new(name, recipe_names))
32
+ # If both .rb and .json exist, read .rb
33
+ # TODO if recipes has 3 recipes in it, and the Ruby/JSON has only one, should
34
+ # the resulting recipe list have 1, or 3-4 recipes in it?
35
+ if has_child(directory, 'metadata.rb')
36
+ begin
37
+ file = filename(directory, 'metadata.rb') || "(#{name}/metadata.rb)"
38
+ metadata.instance_eval(read_file(directory, 'metadata.rb'), file)
39
+ rescue
40
+ ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
41
+ end
42
+ elsif has_child(directory, 'metadata.json')
43
+ metadata.from_json(read_file(directory, 'metadata.json'))
44
+ end
45
+ result = {}
46
+ metadata.to_hash.each_pair do |key,value|
47
+ result[key.to_sym] = value
48
+ end
49
+ result[:version] = version if version
50
+ result
51
+ end
52
+
53
+ private
54
+
55
+ # Just enough cookbook to make a Metadata object
56
+ class PretendCookbook
57
+ def initialize(name, fully_qualified_recipe_names)
58
+ @name = name
59
+ @fully_qualified_recipe_names = fully_qualified_recipe_names
60
+ end
61
+ attr_reader :name, :fully_qualified_recipe_names
62
+ end
63
+
64
+ # Handles loading configuration values from a Chef config file
65
+ #
66
+ # @author Justin Campbell <justin.campbell@riotgames.com>
67
+ class PretendCookbookMetadata < Hash
68
+ # @param [String] path
69
+ def initialize(cookbook)
70
+ self.name(cookbook.name)
71
+ self.recipes(cookbook.fully_qualified_recipe_names)
72
+ %w(attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes).each do |hash_arg|
73
+ self[hash_arg.to_sym] = Hashie::Mash.new
74
+ end
75
+ end
76
+
77
+ def from_json(json)
78
+ self.merge!(FFI_Yajl::Parser.parse(json))
79
+ end
80
+
81
+ private
82
+
83
+ def depends(cookbook, *version_constraints)
84
+ cookbook_arg(:dependencies, cookbook, version_constraints)
85
+ end
86
+
87
+ def supports(cookbook, *version_constraints)
88
+ cookbook_arg(:supports, cookbook, version_constraints)
89
+ end
90
+
91
+ def recommends(cookbook, *version_constraints)
92
+ cookbook_arg(:recommendations, cookbook, version_constraints)
93
+ end
94
+
95
+ def suggests(cookbook, *version_constraints)
96
+ cookbook_arg(:suggestions, cookbook, version_constraints)
97
+ end
98
+
99
+ def conflicts(cookbook, *version_constraints)
100
+ cookbook_arg(:conflicting, cookbook, version_constraints)
101
+ end
102
+
103
+ def provides(cookbook, *version_constraints)
104
+ cookbook_arg(:providing, cookbook, version_constraints)
105
+ end
106
+
107
+ def replaces(cookbook, *version_constraints)
108
+ cookbook_arg(:replacing, cookbook, version_constraints)
109
+ end
110
+
111
+ def recipe(recipe, description)
112
+ self[:recipes][recipe] = description
113
+ end
114
+
115
+ def attribute(name, options)
116
+ self[:attributes][name] = options
117
+ end
118
+
119
+ def grouping(name, options)
120
+ self[:grouping][name] = options
121
+ end
122
+
123
+ def cookbook_arg(key, cookbook, version_constraints)
124
+ self[key][cookbook] = version_constraints.first || ">= 0.0.0"
125
+ end
126
+
127
+ def method_missing(key, value = nil)
128
+ if value.nil?
129
+ self[key.to_sym]
130
+ else
131
+ store key.to_sym, value
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.files_from(directory)
137
+ # TODO some support .rb only
138
+ result = {
139
+ :attributes => load_child_files(directory, 'attributes', false),
140
+ :definitions => load_child_files(directory, 'definitions', false),
141
+ :recipes => load_child_files(directory, 'recipes', false),
142
+ :libraries => load_child_files(directory, 'libraries', false),
143
+ :templates => load_child_files(directory, 'templates', true),
144
+ :files => load_child_files(directory, 'files', true),
145
+ :resources => load_child_files(directory, 'resources', true),
146
+ :providers => load_child_files(directory, 'providers', true),
147
+ :root_files => load_files(directory, false)
148
+ }
149
+ set_specificity(result[:templates])
150
+ set_specificity(result[:files])
151
+ result
152
+ end
153
+
154
+ def self.has_child(directory, name)
155
+ if directory.is_a?(Hash)
156
+ directory.has_key?(name)
157
+ else
158
+ directory.child(name).exists?
159
+ end
160
+ end
161
+
162
+ def self.read_file(directory, name)
163
+ if directory.is_a?(Hash)
164
+ directory[name]
165
+ else
166
+ directory.child(name).read
167
+ end
168
+ end
169
+
170
+ def self.filename(directory, name)
171
+ if directory.respond_to?(:file_path)
172
+ File.join(directory.file_path, name)
173
+ else
174
+ nil
175
+ end
176
+ end
177
+
178
+ def self.get_directory(directory, name)
179
+ if directory.is_a?(Hash)
180
+ directory[name].is_a?(Hash) ? directory[name] : nil
181
+ else
182
+ result = directory.child(name)
183
+ result.dir? ? result : nil
184
+ end
185
+ end
186
+
187
+ def self.list(directory)
188
+ if directory.is_a?(Hash)
189
+ directory.keys
190
+ else
191
+ directory.children.map { |c| c.name }
192
+ end
193
+ end
194
+
195
+ def self.load_child_files(parent, key, recursive)
196
+ result = load_files(get_directory(parent, key), recursive)
197
+ result.each do |file|
198
+ file[:path] = "#{key}/#{file[:path]}"
199
+ end
200
+ result
201
+ end
202
+
203
+ def self.load_files(directory, recursive)
204
+ result = []
205
+ if directory
206
+ list(directory).each do |child_name|
207
+ dir = get_directory(directory, child_name)
208
+ if dir
209
+ if recursive
210
+ result += load_child_files(directory, child_name, recursive)
211
+ end
212
+ else
213
+ result += load_file(read_file(directory, child_name), child_name)
214
+ end
215
+ end
216
+ end
217
+ result
218
+ end
219
+
220
+ def self.load_file(value, name)
221
+ [{
222
+ :name => name,
223
+ :path => name,
224
+ :checksum => Digest::MD5.hexdigest(value),
225
+ :specificity => 'default'
226
+ }]
227
+ end
228
+
229
+ def self.set_specificity(files)
230
+ files.each do |file|
231
+ parts = file[:path].split('/')
232
+ raise "Only directories are allowed directly under templates or files: #{file[:path]}" if parts.size == 2
233
+ file[:specificity] = parts[1]
234
+ end
235
+ end
236
+ end
237
+ end
238
+
239
+ CookbookData = ChefData::CookbookData
240
+ end