knife-essentials 1.0.0.beta4 → 1.0.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/deps_essentials.rb +1 -1
- data/lib/chef_fs/data_handler/container_data_handler.rb +9 -2
- data/lib/chef_fs/data_handler/data_bag_item_data_handler.rb +14 -3
- data/lib/chef_fs/data_handler/data_handler_base.rb +11 -0
- data/lib/chef_fs/file_system/chef_server_root_dir.rb +1 -2
- data/lib/chef_fs/file_system/data_bag_dir.rb +0 -4
- data/lib/chef_fs/file_system/rest_list_dir.rb +4 -10
- data/lib/chef_fs/file_system/rest_list_entry.rb +3 -9
- data/lib/chef_fs/version.rb +1 -1
- data/spec/integration/deps_spec.rb +1 -1
- data/spec/integration/download_spec.rb +1 -1
- data/spec/integration/upload_spec.rb +6 -6
- data/spec/support/integration_helper.rb +1 -1
- metadata +1 -2
- data/lib/chef_fs/file_system/containers_dir.rb +0 -33
@@ -73,7 +73,7 @@ class Chef
|
|
73
73
|
def get_dependencies(entry)
|
74
74
|
begin
|
75
75
|
if entry.parent && entry.parent.path == '/cookbooks'
|
76
|
-
return entry.chef_object.metadata.dependencies.keys.map { |cookbook| "/cookbooks/#{cookbook}"}
|
76
|
+
return entry.chef_object.metadata.dependencies.keys.map { |cookbook| "/cookbooks/#{cookbook}" }
|
77
77
|
|
78
78
|
elsif entry.parent && entry.parent.path == '/nodes'
|
79
79
|
node = JSON.parse(entry.read, :create_additions => false)
|
@@ -3,8 +3,8 @@ require 'chef_fs/data_handler/data_handler_base'
|
|
3
3
|
module ChefFS
|
4
4
|
module DataHandler
|
5
5
|
class ContainerDataHandler < DataHandlerBase
|
6
|
-
def normalize(
|
7
|
-
super(
|
6
|
+
def normalize(container, entry)
|
7
|
+
super(container, {
|
8
8
|
'containername' => remove_dot_json(entry.name),
|
9
9
|
'containerpath' => remove_dot_json(entry.name)
|
10
10
|
})
|
@@ -14,6 +14,13 @@ module ChefFS
|
|
14
14
|
return key == 'containername'
|
15
15
|
end
|
16
16
|
|
17
|
+
def verify_integrity(object, entry, &on_error)
|
18
|
+
base_name = remove_dot_json(entry.name)
|
19
|
+
if object['containername'] != base_name
|
20
|
+
on_error.call("Name in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['name']}')")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
17
24
|
# There is no chef_class for users, nor does to_ruby work.
|
18
25
|
end
|
19
26
|
end
|
@@ -18,16 +18,20 @@ module ChefFS
|
|
18
18
|
})
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def normalize_for_post(data_bag_item, entry)
|
22
22
|
{
|
23
|
-
"name" => "data_bag_item_#{entry.parent.name}_#{entry.name}",
|
23
|
+
"name" => "data_bag_item_#{entry.parent.name}_#{remove_dot_json(entry.name)}",
|
24
24
|
"json_class" => "Chef::DataBagItem",
|
25
25
|
"chef_type" => "data_bag_item",
|
26
26
|
"data_bag" => entry.parent.name,
|
27
|
-
"raw_data" => normalize(data_bag_item)
|
27
|
+
"raw_data" => normalize(data_bag_item, entry)
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
|
+
def normalize_for_put(data_bag_item, entry)
|
32
|
+
normalize_for_post(data_bag_item, entry)
|
33
|
+
end
|
34
|
+
|
31
35
|
def preserve_key(key)
|
32
36
|
return key == 'id'
|
33
37
|
end
|
@@ -36,6 +40,13 @@ module ChefFS
|
|
36
40
|
Chef::DataBagItem
|
37
41
|
end
|
38
42
|
|
43
|
+
def verify_integrity(object, entry, &on_error)
|
44
|
+
base_name = remove_dot_json(entry.name)
|
45
|
+
if object['raw_data']['id'] != base_name
|
46
|
+
on_error.call("ID in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['raw_data']['id']}')")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
# Data bags do not support .rb files (or if they do, it's undocumented)
|
40
51
|
end
|
41
52
|
end
|
@@ -38,6 +38,10 @@ module ChefFS
|
|
38
38
|
result
|
39
39
|
end
|
40
40
|
|
41
|
+
def normalize_for_post(object, entry)
|
42
|
+
normalize(object, entry)
|
43
|
+
end
|
44
|
+
|
41
45
|
def normalize_for_put(object, entry)
|
42
46
|
normalize(object, entry)
|
43
47
|
end
|
@@ -110,6 +114,13 @@ module ChefFS
|
|
110
114
|
result
|
111
115
|
end
|
112
116
|
|
117
|
+
def verify_integrity(object, entry, &on_error)
|
118
|
+
base_name = remove_dot_json(entry.name)
|
119
|
+
if object['name'] != base_name
|
120
|
+
on_error.call("Name must be '#{base_name}' (is '#{object['name']}')")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
113
124
|
end # class DataHandlerBase
|
114
125
|
end
|
115
126
|
end
|
@@ -19,7 +19,6 @@
|
|
19
19
|
require 'chef_fs/file_system/acls_dir'
|
20
20
|
require 'chef_fs/file_system/base_fs_dir'
|
21
21
|
require 'chef_fs/file_system/rest_list_dir'
|
22
|
-
require 'chef_fs/file_system/containers_dir'
|
23
22
|
require 'chef_fs/file_system/cookbooks_dir'
|
24
23
|
require 'chef_fs/file_system/data_bags_dir'
|
25
24
|
require 'chef_fs/file_system/nodes_dir'
|
@@ -86,7 +85,7 @@ module ChefFS
|
|
86
85
|
result += [
|
87
86
|
AclsDir.new(self),
|
88
87
|
RestListDir.new("clients", self, nil, ChefFS::DataHandler::ClientDataHandler.new),
|
89
|
-
|
88
|
+
RestListDir.new("containers", self, nil, ChefFS::DataHandler::ContainerDataHandler.new),
|
90
89
|
RestListDir.new("groups", self, nil, ChefFS::DataHandler::GroupDataHandler.new),
|
91
90
|
NodesDir.new(self)
|
92
91
|
]
|
@@ -56,10 +56,6 @@ module ChefFS
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def identity_key
|
60
|
-
'name'
|
61
|
-
end
|
62
|
-
|
63
59
|
def create_child(name, file_contents)
|
64
60
|
begin
|
65
61
|
object = JSON.parse(file_contents, :create_additions => false)
|
@@ -70,12 +66,10 @@ module ChefFS
|
|
70
66
|
result = _make_child_entry(name, true)
|
71
67
|
|
72
68
|
if data_handler
|
73
|
-
object = data_handler.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if object[identity_key] != base_name
|
78
|
-
raise ChefFS::FileSystem::OperationFailedError.new(:create_child, self), "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{object[identity_key]}')"
|
69
|
+
object = data_handler.normalize_for_post(object, result)
|
70
|
+
data_handler.verify_integrity(object, result) do |error|
|
71
|
+
raise ChefFS::FileSystem::OperationFailedError.new(:create_child, self), "Error creating '#{name}': #{error}"
|
72
|
+
end
|
79
73
|
end
|
80
74
|
|
81
75
|
begin
|
@@ -141,10 +141,6 @@ module ChefFS
|
|
141
141
|
parent.rest
|
142
142
|
end
|
143
143
|
|
144
|
-
def identity_key
|
145
|
-
parent.identity_key
|
146
|
-
end
|
147
|
-
|
148
144
|
def write(file_contents)
|
149
145
|
begin
|
150
146
|
#object = Chef::JSONCompat.from_json(file_contents).to_hash
|
@@ -155,11 +151,9 @@ module ChefFS
|
|
155
151
|
|
156
152
|
if data_handler
|
157
153
|
object = data_handler.normalize_for_put(object, self)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
if object[identity_key] != base_name
|
162
|
-
raise ChefFS::FileSystem::OperationFailedError.new(:write, self), "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{object['name']}')"
|
154
|
+
data_handler.verify_integrity(object, self) do |error|
|
155
|
+
raise ChefFS::FileSystem::OperationFailedError.new(:write, self), "#{error}"
|
156
|
+
end
|
163
157
|
end
|
164
158
|
|
165
159
|
begin
|
data/lib/chef_fs/version.rb
CHANGED
@@ -396,7 +396,7 @@ EOM
|
|
396
396
|
when_the_chef_server 'has a cookbook with dependencies' do
|
397
397
|
cookbook 'kettle', '1.0.0', { 'metadata.rb' => "name 'kettle'\nversion '1.0.0'\n" }
|
398
398
|
cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\ndepends 'kettle'\n", 'recipes' => { 'default.rb' => '' } }
|
399
|
-
it 'knife deps reports
|
399
|
+
it 'knife deps reports the cookbook and its dependencies' do
|
400
400
|
knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n"
|
401
401
|
end
|
402
402
|
end
|
@@ -192,7 +192,7 @@ EOM
|
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'knife download --no-diff creates the extra files' do
|
195
|
-
knife('download /').should_succeed <<EOM
|
195
|
+
knife('download --no-diff /').should_succeed <<EOM
|
196
196
|
Created /clients
|
197
197
|
Created /clients/chef-validator.json
|
198
198
|
Created /clients/chef-webui.json
|
@@ -91,7 +91,7 @@ EOM
|
|
91
91
|
knife('diff --name-status /').should_succeed ''
|
92
92
|
end
|
93
93
|
it 'knife upload --no-diff does not change the role' do
|
94
|
-
knife('upload /').should_succeed ''
|
94
|
+
knife('upload --no-diff /').should_succeed ''
|
95
95
|
knife('diff --name-status /').should_succeed "M\t/roles/x.json\n"
|
96
96
|
end
|
97
97
|
end
|
@@ -148,7 +148,7 @@ EOM
|
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'knife upload --no-diff adds the new files' do
|
151
|
-
knife('upload /').should_succeed <<EOM
|
151
|
+
knife('upload --no-diff /').should_succeed <<EOM
|
152
152
|
Created /clients/y.json
|
153
153
|
Updated /cookbooks/x
|
154
154
|
Created /cookbooks/y
|
@@ -451,7 +451,7 @@ EOM
|
|
451
451
|
when_the_repository 'has the same environment with the wrong name in the file' do
|
452
452
|
file 'environments/x.json', { 'name' => 'y' }
|
453
453
|
it 'knife upload fails' do
|
454
|
-
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name
|
454
|
+
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n"
|
455
455
|
knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n"
|
456
456
|
end
|
457
457
|
end
|
@@ -477,7 +477,7 @@ EOM
|
|
477
477
|
when_the_repository 'has an environment with the wrong name in the file' do
|
478
478
|
file 'environments/x.json', { 'name' => 'y' }
|
479
479
|
it 'knife upload fails' do
|
480
|
-
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child:
|
480
|
+
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n"
|
481
481
|
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
|
482
482
|
end
|
483
483
|
end
|
@@ -930,7 +930,7 @@ EOM
|
|
930
930
|
when_the_repository 'has the same environment with the wrong name in the file' do
|
931
931
|
file 'environments/x.json', { 'name' => 'y' }
|
932
932
|
it 'knife upload fails' do
|
933
|
-
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name
|
933
|
+
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n"
|
934
934
|
knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n"
|
935
935
|
end
|
936
936
|
end
|
@@ -956,7 +956,7 @@ EOM
|
|
956
956
|
when_the_repository 'has an environment with the wrong name in the file' do
|
957
957
|
file 'environments/x.json', { 'name' => 'y' }
|
958
958
|
it 'knife upload fails' do
|
959
|
-
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child:
|
959
|
+
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n"
|
960
960
|
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
|
961
961
|
end
|
962
962
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,7 +87,6 @@ files:
|
|
87
87
|
- lib/chef_fs/file_system/chef_repository_file_system_entry.rb
|
88
88
|
- lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb
|
89
89
|
- lib/chef_fs/file_system/chef_server_root_dir.rb
|
90
|
-
- lib/chef_fs/file_system/containers_dir.rb
|
91
90
|
- lib/chef_fs/file_system/cookbook_dir.rb
|
92
91
|
- lib/chef_fs/file_system/cookbook_file.rb
|
93
92
|
- lib/chef_fs/file_system/cookbook_subdir.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: John Keiser (<jkeiser@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2012 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_fs/file_system/rest_list_entry'
|
20
|
-
|
21
|
-
module ChefFS
|
22
|
-
module FileSystem
|
23
|
-
class ContainersDir < RestListDir
|
24
|
-
def initialize(parent)
|
25
|
-
super("containers", parent, nil, ChefFS::DataHandler::ContainerDataHandler.new)
|
26
|
-
end
|
27
|
-
|
28
|
-
def identity_key
|
29
|
-
'containername'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|