knife-essentials 0.9.4 → 0.9.5

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 (29) hide show
  1. data/lib/chef/knife/diff_essentials.rb +2 -5
  2. data/lib/chef/knife/raw_essentials.rb +2 -2
  3. data/lib/chef_fs/command_line.rb +98 -79
  4. data/lib/chef_fs/data_handler/acl_data_handler.rb +22 -0
  5. data/lib/chef_fs/data_handler/container_data_handler.rb +20 -0
  6. data/lib/chef_fs/data_handler/group_data_handler.rb +33 -0
  7. data/lib/chef_fs/data_handler/user_data_handler.rb +6 -1
  8. data/lib/chef_fs/file_system/acl_dir.rb +62 -0
  9. data/lib/chef_fs/file_system/acl_entry.rb +54 -0
  10. data/lib/chef_fs/file_system/acls_dir.rb +66 -0
  11. data/lib/chef_fs/file_system/base_fs_object.rb +0 -74
  12. data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +9 -0
  13. data/lib/chef_fs/file_system/chef_server_root_dir.rb +21 -2
  14. data/lib/chef_fs/file_system/cookbook_dir.rb +1 -1
  15. data/lib/chef_fs/file_system/cookbooks_acl_dir.rb +39 -0
  16. data/lib/chef_fs/file_system/cookbooks_dir.rb +3 -2
  17. data/lib/chef_fs/file_system/data_bags_dir.rb +1 -5
  18. data/lib/chef_fs/file_system/nodes_dir.rb +13 -3
  19. data/lib/chef_fs/file_system/rest_list_dir.rb +5 -7
  20. data/lib/chef_fs/file_system/rest_list_entry.rb +18 -18
  21. data/lib/chef_fs/knife.rb +7 -4
  22. data/lib/chef_fs/raw_request.rb +73 -0
  23. data/lib/chef_fs/version.rb +1 -1
  24. data/spec/support/integration_helper.rb +12 -1
  25. metadata +10 -6
  26. data/spec/chef_fs/file_system/chef_server_root_dir_spec.rb +0 -252
  27. data/spec/chef_fs/file_system/cookbook_dir_spec.rb +0 -582
  28. data/spec/chef_fs/file_system/cookbooks_dir_spec.rb +0 -165
  29. data/spec/chef_fs/file_system/data_bags_dir_spec.rb +0 -235
@@ -1,165 +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 'support/spec_helper'
20
- require 'chef_fs/file_system/chef_server_root_dir'
21
- require 'chef_fs/file_system'
22
-
23
- describe ChefFS::FileSystem::CookbooksDir do
24
- let(:root_dir) {
25
- ChefFS::FileSystem::ChefServerRootDir.new('remote',
26
- {
27
- :chef_server_url => 'url',
28
- :node_name => 'username',
29
- :client_key => 'key'
30
- },
31
- 'everything')
32
- }
33
-
34
- let(:cookbook_response) do
35
- {
36
- "achild" => {
37
- "url" => "http://example.com/cookbooks/achild",
38
- 'versions' => [
39
- { "version" => '2.0.0', 'url' => 'http://example.com/cookbooks/achild/2.0.0' },
40
- { "version" => '1.0.0', 'url' => 'http://example.com/cookbooks/achild/2.0.0' }, ] },
41
- "bchild" => {
42
- "url" => "http://example.com/cookbokks/bchild",
43
- 'versions' => [ { "version" => '1.0.0', 'url' => 'http://example.com/cookbooks/achild/2.0.0' }, ] },
44
-
45
- }
46
- end
47
-
48
- let(:cookbooks_dir) { root_dir.child('cookbooks') }
49
- let(:api_url) { 'cookbooks' }
50
- let(:should_list_cookbooks) { rest.should_receive(:get_rest).with(api_url).once.and_return(cookbook_response) }
51
-
52
- let(:rest) { double 'rest' }
53
- before(:each) { Chef::REST.stub(:new).with('url','username','key') { rest } }
54
-
55
- def self.with_versioned_cookbooks
56
- before(:each) { Chef::Config[:versioned_cookbooks] = true }
57
- after(:each) { Chef::Config[:versioned_cookbooks] = false }
58
-
59
- let(:api_url) { 'cookbooks/?num_versions=all' }
60
- end
61
-
62
- it 'has / as parent' do
63
- cookbooks_dir.parent.should == root_dir
64
- end
65
-
66
- it 'is a directory' do
67
- cookbooks_dir.dir?.should be_true
68
- end
69
-
70
- it 'exists' do
71
- cookbooks_dir.exists?.should be_true
72
- end
73
-
74
- it 'has name cookbooks' do
75
- cookbooks_dir.name.should == 'cookbooks'
76
- end
77
-
78
- it 'has path /cookbooks' do
79
- cookbooks_dir.path.should == '/cookbooks'
80
- end
81
-
82
- it 'has path_for_printing remote/cookbooks' do
83
- cookbooks_dir.path_for_printing.should == 'remote/cookbooks'
84
- end
85
-
86
- it 'has correct children' do
87
- should_list_cookbooks
88
- cookbooks_dir.children.map { |child| child.name }.should =~ %w(achild bchild)
89
- end
90
-
91
- describe '#can_have_child?' do
92
- subject { cookbooks_dir.can_have_child? cookbook_name, is_dir? }
93
-
94
- let(:cookbook_name) { 'blah' }
95
- let(:is_dir?) { true }
96
-
97
- # /cookbooks should contain only directories
98
- context 'when child is a directory' do
99
- let(:is_dir?) { true }
100
- it { should be_true }
101
- end
102
-
103
- context 'when child is a file' do
104
- let(:is_dir?) { false }
105
- it { should be_false }
106
- end
107
-
108
- context 'with versioned cookbooks' do
109
- with_versioned_cookbooks
110
-
111
- context 'when name conforms to <cookbook_name>-<verson>' do
112
- let(:cookbook_name) { 'apt-1.8.4' }
113
- it { should be_true }
114
- end
115
-
116
- context 'when name does not conform to <cookbook_name>-<version>' do
117
- let(:cookbook_name) { 'apt' }
118
- it { should be_false }
119
- end
120
- end
121
- end
122
-
123
- describe '#children' do
124
- subject { cookbooks_dir.children }
125
- before(:each) { should_list_cookbooks }
126
-
127
- let(:entity_names) { subject.map(&:name) }
128
- let(:cookbook_names) { subject.map(&:cookbook_name) }
129
- let(:versions) { subject.map(&:version) }
130
-
131
- context 'with versioned cookbooks' do
132
- with_versioned_cookbooks
133
-
134
- it 'should return all versions of cookbooks in <cookbook_name>-<version> format' do
135
- entity_names.should include('achild-2.0.0')
136
- entity_names.should include('achild-1.0.0')
137
- entity_names.should include('bchild-1.0.0')
138
- end
139
-
140
- it 'should return cookbooks with server canonical cookbook name' do
141
- cookbook_names.should include('achild')
142
- cookbook_names.should include('bchild')
143
- end
144
-
145
- it 'should return cookbooks with version numbers' do
146
- versions.should include('2.0.0')
147
- versions.should include('1.0.0')
148
- versions.uniq.size.should eql 2
149
- end
150
- end
151
-
152
- context 'without versioned cookbooks' do
153
- it 'should return a single version for each cookbook' do
154
- entity_names.should include('achild')
155
- entity_names.should include('bchild')
156
- end
157
-
158
- it "should return nil for version numbers" do
159
- versions.should == [ nil, nil ]
160
- versions.uniq.size.should eql 1
161
- end
162
- end
163
- end
164
-
165
- end
@@ -1,235 +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 'support/spec_helper'
20
- require 'chef_fs/file_system/chef_server_root_dir'
21
-
22
- describe ChefFS::FileSystem::DataBagsDir do
23
- let(:root_dir) {
24
- ChefFS::FileSystem::ChefServerRootDir.new('remote',
25
- {
26
- :chef_server_url => 'url',
27
- :node_name => 'username',
28
- :client_key => 'key'
29
- }, 'everything')
30
- }
31
-
32
- let(:data_bags_dir) do
33
- root_dir.child('data_bags').tap do |artifact|
34
- artifact.stub(:chef_collection).and_return(chef_collection)
35
- end
36
- end
37
-
38
- let(:should_list_data_bags) { } # noop. Remove before committing
39
-
40
- let(:chef_collection) do
41
- {
42
- "achild" => "http://opscode.com/achild",
43
- "bchild" => "http://opscode.com/bchild"
44
- }
45
- end
46
-
47
- let(:item_collection) do
48
- {
49
- "aitem" => "http://opscode.com/achild",
50
- "bitem" => "http://opscode.com/bchild"
51
- }
52
- end
53
-
54
- context 'code contract' do
55
-
56
- it 'has / as parent' do
57
- data_bags_dir.parent.should == root_dir
58
- end
59
- it 'is a directory' do
60
- data_bags_dir.dir?.should be_true
61
- end
62
- it 'exists' do
63
- data_bags_dir.exists?.should be_true
64
- end
65
- it 'has name data_bags' do
66
- data_bags_dir.name.should == 'data_bags'
67
- end
68
- it 'has path /data_bags' do
69
- data_bags_dir.path.should == '/data_bags'
70
- end
71
- it 'has path_for_printing remote/data_bags' do
72
- data_bags_dir.path_for_printing.should == 'remote/data_bags'
73
- end
74
- it 'has correct children' do
75
- should_list_data_bags
76
- data_bags_dir.children.map { |child| child.name }.should =~ %w(achild bchild)
77
- end
78
- it 'can have directories as children' do
79
- data_bags_dir.can_have_child?('blah', true).should be_true
80
- end
81
- it 'cannot have files as children' do
82
- data_bags_dir.can_have_child?('blah', false).should be_false
83
- end
84
- end
85
-
86
- shared_examples_for 'a data bag item' do
87
- it 'has data bag as parent' do
88
- data_bag_item.parent.should == data_bag_dir
89
- end
90
- it 'is not a directory' do
91
- data_bag_item.dir?.should be_false
92
- end
93
- it 'exists' do
94
- should_list_data_bag_items
95
- data_bag_item.exists?.should be_true
96
- end
97
- it 'has correct name' do
98
- data_bag_item.name.should == data_bag_item_name
99
- end
100
- it 'has correct path' do
101
- data_bag_item.path.should == "/data_bags/#{data_bag_dir_name}/#{data_bag_item_name}"
102
- end
103
- it 'has correct path_for_printing' do
104
- data_bag_item.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}/#{data_bag_item_name}"
105
- end
106
-
107
- it 'reads correctly' do
108
- data_bag_item.should_receive(:raw_request).
109
- with("data/#{data_bag_dir_name}/#{data_bag_item_short_name}").
110
- once.and_return({'a' => 'b'}.to_json)
111
-
112
- data_bag_item.read.should ==
113
- '{
114
- "id": "aitem",
115
- "a": "b"
116
- }'
117
- end
118
- end
119
-
120
- shared_examples_for 'a data bag' do
121
- let(:should_list_data_bag_items) { data_bag_dir.should_receive(:chef_collection).once.and_return(item_collection) }
122
-
123
- it 'has /data as a parent' do
124
- data_bag_dir.parent.should == data_bags_dir
125
- end
126
- it 'is a directory' do
127
- should_list_data_bags
128
- data_bag_dir.dir?.should be_true
129
- end
130
- it 'exists' do
131
- should_list_data_bags
132
- data_bag_dir.exists?.should be_true
133
- end
134
- it 'has correct name' do
135
- data_bag_dir.name.should == data_bag_dir_name
136
- end
137
- it 'has correct path' do
138
- data_bag_dir.path.should == "/data_bags/#{data_bag_dir_name}"
139
- end
140
- it 'has correct path_for_printing' do
141
- data_bag_dir.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}"
142
- end
143
- it 'has correct children' do
144
- should_list_data_bag_items
145
- data_bag_dir.children.map { |child| child.name }.should =~ %w(aitem.json bitem.json)
146
- end
147
- it 'can have json files as children' do
148
- data_bag_dir.can_have_child?('blah.json', false).should be_true
149
- end
150
- it 'cannot have non-json files as children' do
151
- data_bag_dir.can_have_child?('blah', false).should be_false
152
- end
153
- it 'cannot have directories as children' do
154
- data_bag_dir.can_have_child?('blah', true).should be_false
155
- data_bag_dir.can_have_child?('blah.json', true).should be_false
156
- end
157
- context 'aitem from data_bag.children' do
158
- let(:data_bag_item) do
159
- should_list_data_bag_items
160
- data_bag_dir.children.select { |child| child.name == 'aitem.json' }.first
161
- end
162
- let(:data_bag_item_short_name) { 'aitem' }
163
- let(:data_bag_item_name) { 'aitem.json' }
164
- it_behaves_like 'a data bag item'
165
- end
166
- context 'data_bag.child(aitem)' do
167
- let(:data_bag_item) { data_bag_dir.child('aitem.json') }
168
- let(:data_bag_item_short_name) { 'aitem' }
169
- let(:data_bag_item_name) { 'aitem.json' }
170
- it_behaves_like 'a data bag item'
171
- end
172
- context 'nonexistent child()' do
173
- let(:nonexistent_child) { data_bag_dir.child('blah.json') }
174
- it 'has correct parent, name, path and path_for_printing' do
175
- nonexistent_child.parent.should == data_bag_dir
176
- nonexistent_child.name.should == "blah.json"
177
- nonexistent_child.path.should == "/data_bags/#{data_bag_dir_name}/blah.json"
178
- nonexistent_child.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}/blah.json"
179
- end
180
- it 'does not exist' do
181
- should_list_data_bag_items
182
- nonexistent_child.exists?.should be_false
183
- end
184
- it 'is not a directory' do
185
- nonexistent_child.dir?.should be_false
186
- end
187
- it 'read returns NotFoundError' do
188
- nonexistent_child.should_receive(:raw_request).
189
- with("data/#{data_bag_dir_name}/blah").
190
- once.
191
- and_raise(Net::HTTPServerException.new(nil,Net::HTTPResponse.new(nil,'404',nil)))
192
-
193
- expect { nonexistent_child.read }.to raise_error(ChefFS::FileSystem::NotFoundError)
194
- end
195
- end
196
- end
197
-
198
- context 'achild from data_bags.children' do
199
- let(:data_bag_dir) do
200
- data_bags_dir.children.select { |child| child.name == 'achild' }.first
201
- end
202
- let(:data_bag_dir_name) { 'achild' }
203
- it_behaves_like 'a data bag'
204
- end
205
-
206
- context 'data_bags.child(achild)' do
207
- let(:data_bag_dir) do
208
- data_bags_dir.child('achild')
209
- end
210
- let(:data_bag_dir_name) { 'achild' }
211
- it_behaves_like 'a data bag'
212
- end
213
-
214
- context 'nonexistent child()' do
215
- let(:nonexistent_child) { data_bags_dir.child('blah') }
216
- it 'has correct parent, name, path and path_for_printing' do
217
- nonexistent_child.parent.should == data_bags_dir
218
- nonexistent_child.name.should == "blah"
219
- nonexistent_child.path.should == "/data_bags/blah"
220
- nonexistent_child.path_for_printing.should == "remote/data_bags/blah"
221
- end
222
- it 'does not exist' do
223
- should_list_data_bags
224
- nonexistent_child.exists?.should be_false
225
- end
226
- it 'is not a directory' do
227
- should_list_data_bags
228
- nonexistent_child.dir?.should be_false
229
- end
230
- it 'read returns NotFoundError' do
231
- expect { nonexistent_child.read }.to raise_error(ChefFS::FileSystem::NotFoundError)
232
- end
233
- end
234
-
235
- end