chef-zero 2.0.2 → 2.1

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef_zero/data_normalizer.rb +6 -2
  3. data/lib/chef_zero/data_store/interface_v1.rb +49 -0
  4. data/lib/chef_zero/data_store/interface_v2.rb +18 -0
  5. data/lib/chef_zero/data_store/memory_store.rb +6 -141
  6. data/lib/chef_zero/data_store/memory_store_v2.rb +188 -0
  7. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +190 -0
  8. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -0
  9. data/lib/chef_zero/endpoints/actor_endpoint.rb +6 -12
  10. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +1 -1
  11. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
  12. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +16 -16
  13. data/lib/chef_zero/endpoints/cookbooks_base.rb +5 -5
  14. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +1 -1
  15. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +2 -2
  16. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +1 -1
  17. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +2 -2
  18. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +3 -3
  19. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +9 -9
  20. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
  21. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  22. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +5 -5
  23. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +3 -3
  24. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +6 -6
  25. data/lib/chef_zero/endpoints/node_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/principal_endpoint.rb +2 -2
  27. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +3 -3
  28. data/lib/chef_zero/endpoints/role_endpoint.rb +1 -1
  29. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +1 -1
  30. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +3 -3
  31. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +2 -3
  32. data/lib/chef_zero/endpoints/search_endpoint.rb +13 -9
  33. data/lib/chef_zero/endpoints/searches_endpoint.rb +1 -1
  34. data/lib/chef_zero/rest_base.rb +10 -2
  35. data/lib/chef_zero/rest_request.rb +4 -3
  36. data/lib/chef_zero/server.rb +83 -52
  37. data/lib/chef_zero/version.rb +1 -1
  38. data/spec/run.rb +72 -25
  39. data/spec/support/pedant.rb +4 -0
  40. metadata +10 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 724196a25d016237466c1536eff497dbdd1e2a1e
4
- data.tar.gz: 4ebf2ae81da945160926ba408be3e6ce802d1d8d
3
+ metadata.gz: 7f471a666e1d3e6bf940a786920438a6a956e10b
4
+ data.tar.gz: 15d364fda6c211d6f306909c5c7380830d9e66ad
5
5
  SHA512:
6
- metadata.gz: 5e6869dfcfee74354fa1438fa6b6289d7bccf7d24f932e0af67b8fc2bfe8499466ed624a78715a2e80f13280eb11a6c3fd49f5acf648c224bd8ef54890a9d39b
7
- data.tar.gz: 7f03e15a3e895e1e7423c0061ce8e78ff7399d178a40f1da13ca99d0a79419d3baead62d4fc9546ccd0f4121f057bef2658bbc02f977ac9c8c2ce74e7a5be955
6
+ metadata.gz: b3333fe38f5a88350b324ffae8889cd9440b66db783338aca651a77a1480b9e6f5aac3e122e57d046776ac327ede11f8422bb8f4cf260ff4326951771e7219dd
7
+ data.tar.gz: 1aaeb7212a5c29090a6b3f83d6a0a66f565c104e92e32c421cb1830c865c51f2377341b5e046f2e173ccd89ffd8f504abe44a5f6e703dc25fd2095318e2858dc
@@ -6,8 +6,10 @@ module ChefZero
6
6
  def self.normalize_client(client, name)
7
7
  client['name'] ||= name
8
8
  client['admin'] ||= false
9
+ client['admin'] = !!client['admin']
9
10
  client['public_key'] ||= PUBLIC_KEY
10
11
  client['validator'] ||= false
12
+ client['validator'] = !!client['validator']
11
13
  client['json_class'] ||= "Chef::ApiClient"
12
14
  client['chef_type'] ||= "client"
13
15
  client
@@ -16,6 +18,8 @@ module ChefZero
16
18
  def self.normalize_user(user, name)
17
19
  user['name'] ||= name
18
20
  user['admin'] ||= false
21
+ user['admin'] = !!user['admin']
22
+ user['openid'] ||= nil
19
23
  user['public_key'] ||= PUBLIC_KEY
20
24
  user
21
25
  end
@@ -57,14 +61,14 @@ module ChefZero
57
61
  environment
58
62
  end
59
63
 
60
- def self.normalize_cookbook(cookbook, name, version, base_uri, method)
64
+ def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method)
61
65
  # TODO I feel dirty
62
66
  if method != 'PUT'
63
67
  cookbook.each_pair do |key, value|
64
68
  if value.is_a?(Array)
65
69
  value.each do |file|
66
70
  if file.is_a?(Hash) && file.has_key?('checksum')
67
- file['url'] ||= RestBase::build_uri(base_uri, ['file_store', 'checksums', file['checksum']])
71
+ file['url'] ||= endpoint.build_uri(base_uri, org_prefix + ['file_store', 'checksums', file['checksum']])
68
72
  end
69
73
  end
70
74
  end
@@ -0,0 +1,49 @@
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
+ def create_dir(path, name, *options)
13
+ raise "create_dir not implemented by class #{self.class}"
14
+ end
15
+
16
+ def create(path, name, data, *options)
17
+ raise "create not implemented by class #{self.class}"
18
+ end
19
+
20
+ def get(path, request=nil)
21
+ raise "get not implemented by class #{self.class}"
22
+ end
23
+
24
+ def set(path, data, *options)
25
+ raise "set not implemented by class #{self.class}"
26
+ end
27
+
28
+ def delete(path)
29
+ raise "delete not implemented by class #{self.class}"
30
+ end
31
+
32
+ def delete_dir(path, *options)
33
+ raise "delete_dir not implemented by class #{self.class}"
34
+ end
35
+
36
+ def list(path)
37
+ raise "list not implemented by class #{self.class}"
38
+ end
39
+
40
+ def exists?(path)
41
+ raise "exists? not implemented by class #{self.class}"
42
+ end
43
+
44
+ def exists_dir?(path)
45
+ raise "exists_dir? not implemented by class #{self.class}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ require 'chef_zero/data_store/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
@@ -16,152 +16,17 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef_zero/data_store/data_already_exists_error'
20
- require 'chef_zero/data_store/data_not_found_error'
19
+ require 'chef_zero/data_store/v2_to_v1_adapter'
20
+ require 'chef_zero/data_store/memory_store_v2'
21
21
 
22
22
  module ChefZero
23
23
  module DataStore
24
- class MemoryStore
24
+ class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
25
25
  def initialize
26
+ super
27
+ @real_store = ChefZero::DataStore::MemoryStoreV2.new
26
28
  clear
27
29
  end
28
-
29
- def clear
30
- @data = {}
31
-
32
- # Create containers
33
- create_dir([], 'clients')
34
- create_dir([], 'cookbooks')
35
- create_dir([], 'data')
36
- create_dir([], 'environments')
37
- create_dir([], 'file_store')
38
- create_dir(['file_store'], 'checksums')
39
- create_dir([], 'nodes')
40
- create_dir([], 'roles')
41
- create_dir([], 'sandboxes')
42
- create_dir([], 'users')
43
-
44
- # Set defaults
45
- create(['clients'], 'chef-validator', '{ "validator": true }')
46
- create(['clients'], 'chef-webui', '{ "admin": true }')
47
- create(['environments'], '_default', '{ "description": "The default Chef environment" }')
48
- create(['users'], 'admin', '{ "admin": true }')
49
- end
50
-
51
- def create_dir(path, name, *options)
52
- parent = _get(path, options.include?(:recursive))
53
-
54
- if parent.has_key?(name)
55
- if !options.include?(:recursive)
56
- raise DataAlreadyExistsError.new(path + [name])
57
- end
58
- else
59
- parent[name] = {}
60
- end
61
- end
62
-
63
- def create(path, name, data, *options)
64
- if !data.is_a?(String)
65
- raise "set only works with strings"
66
- end
67
-
68
- parent = _get(path, options.include?(:create_dir))
69
-
70
- if parent.has_key?(name)
71
- raise DataAlreadyExistsError.new(path + [name])
72
- end
73
- parent[name] = data
74
- end
75
-
76
- def get(path, request=nil)
77
- value = _get(path)
78
- if value.is_a?(Hash)
79
- raise "get() called on directory #{path.join('/')}"
80
- end
81
- value
82
- end
83
-
84
- def set(path, data, *options)
85
- if !data.is_a?(String)
86
- raise "set only works with strings: #{path} = #{data.inspect}"
87
- end
88
-
89
- # Get the parent
90
- parent = _get(path[0..-2], options.include?(:create_dir))
91
-
92
- if !options.include?(:create) && !parent[path[-1]]
93
- raise DataNotFoundError.new(path)
94
- end
95
- parent[path[-1]] = data
96
- end
97
-
98
- def delete(path)
99
- parent = _get(path[0,path.length-1])
100
- if !parent.has_key?(path[-1])
101
- raise DataNotFoundError.new(path)
102
- end
103
- if !parent[path[-1]].is_a?(String)
104
- raise "delete only works with strings: #{path}"
105
- end
106
- parent.delete(path[-1])
107
- end
108
-
109
- def delete_dir(path, *options)
110
- parent = _get(path[0,path.length-1])
111
- if !parent.has_key?(path[-1])
112
- raise DataNotFoundError.new(path)
113
- end
114
- if !parent[path[-1]].is_a?(Hash)
115
- raise "delete_dir only works with directories: #{path}"
116
- end
117
- parent.delete(path[-1])
118
- end
119
-
120
- def list(path)
121
- dir = _get(path)
122
- if !dir.is_a? Hash
123
- raise "list only works with directories (#{path} = #{dir.class}"
124
- end
125
- dir.keys.sort
126
- end
127
-
128
- def exists?(path)
129
- begin
130
- get(path)
131
- return true
132
- rescue DataNotFoundError
133
- return false
134
- end
135
- end
136
-
137
- def exists_dir?(path)
138
- begin
139
- dir = _get(path)
140
- if !dir.is_a? Hash
141
- raise "exists_dir? only works with directories (#{path} = #{dir.class}"
142
- end
143
- return true
144
- rescue DataNotFoundError
145
- return false
146
- end
147
- end
148
-
149
- private
150
-
151
- def _get(path, create_dir=false)
152
- value = @data
153
- path.each_with_index do |path_part, index|
154
- if !value.has_key?(path_part)
155
- if create_dir
156
- value[path_part] = {}
157
- else
158
- raise DataNotFoundError.new(path[0,index+1])
159
- end
160
- end
161
- value = value[path_part]
162
- end
163
- value
164
- end
165
30
  end
166
31
  end
167
- end
32
+ end
@@ -0,0 +1,188 @@
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
+ # http://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 'chef_zero/data_store/data_already_exists_error'
20
+ require 'chef_zero/data_store/data_not_found_error'
21
+ require 'chef_zero/data_store/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
+
35
+ create_dir([], 'organizations')
36
+ end
37
+
38
+ def create_org
39
+ org = {
40
+ 'clients' => {
41
+ 'chef-validator' => '{ "validator": true }',
42
+ 'chef-webui' => '{ "admin": true }'
43
+ },
44
+ 'cookbooks' => {},
45
+ 'data' => {},
46
+ 'environments' => {
47
+ '_default' => '{ "description": "The default Chef environment" }'
48
+ },
49
+ 'file_store' => {
50
+ 'checksums' => {}
51
+ },
52
+ 'nodes' => {},
53
+ 'roles' => {},
54
+ 'sandboxes' => {},
55
+ 'users' => {
56
+ 'admin' => '{ "admin": "true" }'
57
+ }
58
+ }
59
+ end
60
+
61
+ def create_dir(path, name, *options)
62
+ parent = _get(path, options.include?(:recursive))
63
+
64
+ if parent.has_key?(name)
65
+ if !options.include?(:recursive)
66
+ raise DataAlreadyExistsError.new(path + [name])
67
+ end
68
+ else
69
+ _create_dir(path, parent, name)
70
+ end
71
+ end
72
+
73
+ def create(path, name, data, *options)
74
+ if !data.is_a?(String)
75
+ raise "set only works with strings"
76
+ end
77
+
78
+ parent = _get(path, options.include?(:create_dir))
79
+
80
+ if parent.has_key?(name)
81
+ raise DataAlreadyExistsError.new(path + [name])
82
+ end
83
+ parent[name] = data
84
+ end
85
+
86
+ def get(path, request=nil)
87
+ value = _get(path)
88
+ if value.is_a?(Hash)
89
+ raise "get() called on directory #{path.join('/')}"
90
+ end
91
+ value
92
+ end
93
+
94
+ def set(path, data, *options)
95
+ if !data.is_a?(String)
96
+ raise "set only works with strings: #{path} = #{data.inspect}"
97
+ end
98
+
99
+ # Get the parent
100
+ parent = _get(path[0..-2], options.include?(:create_dir))
101
+
102
+ if !options.include?(:create) && !parent[path[-1]]
103
+ raise DataNotFoundError.new(path)
104
+ end
105
+ parent[path[-1]] = data
106
+ end
107
+
108
+ def delete(path)
109
+ parent = _get(path[0,path.length-1])
110
+ if !parent.has_key?(path[-1])
111
+ raise DataNotFoundError.new(path)
112
+ end
113
+ if !parent[path[-1]].is_a?(String)
114
+ raise "delete only works with strings: #{path}"
115
+ end
116
+ parent.delete(path[-1])
117
+ end
118
+
119
+ def delete_dir(path, *options)
120
+ parent = _get(path[0,path.length-1])
121
+ if !parent.has_key?(path[-1])
122
+ raise DataNotFoundError.new(path)
123
+ end
124
+ if !parent[path[-1]].is_a?(Hash)
125
+ raise "delete_dir only works with directories: #{path}"
126
+ end
127
+ parent.delete(path[-1])
128
+ end
129
+
130
+ def list(path)
131
+ dir = _get(path)
132
+ if !dir.is_a? Hash
133
+ raise "list only works with directories (#{path} = #{dir.class})"
134
+ end
135
+ dir.keys.sort
136
+ end
137
+
138
+ def exists?(path, options = {})
139
+ begin
140
+ value = _get(path)
141
+ if value.is_a?(Hash) && !options[:allow_dirs]
142
+ raise "exists? does not work with directories (#{path} = #{dir.class})"
143
+ end
144
+ return true
145
+ rescue DataNotFoundError
146
+ return false
147
+ end
148
+ end
149
+
150
+ def exists_dir?(path)
151
+ begin
152
+ dir = _get(path)
153
+ if !dir.is_a? Hash
154
+ raise "exists_dir? only works with directories (#{path} = #{dir.class})"
155
+ end
156
+ return true
157
+ rescue DataNotFoundError
158
+ return false
159
+ end
160
+ end
161
+
162
+ private
163
+
164
+ def _get(path, create_dir=false)
165
+ value = @data
166
+ path.each_with_index do |path_part, index|
167
+ if !value.has_key?(path_part)
168
+ if create_dir
169
+ _create_dir(path[0,index], value, path_part)
170
+ else
171
+ raise DataNotFoundError.new(path[0,index+1])
172
+ end
173
+ end
174
+ value = value[path_part]
175
+ end
176
+ value
177
+ end
178
+
179
+ def _create_dir(parent_path, parent, name)
180
+ if parent_path == [ 'organizations' ]
181
+ parent[name] = create_org
182
+ else
183
+ parent[name] = {}
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end