knife-solo_data_bag 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf49bac07e42c95338783f5538307c3041fb42c3
4
+ data.tar.gz: 93ad9e80f4d7b1f42a59a7f130a04beb022cc8dd
5
+ SHA512:
6
+ metadata.gz: 58029e99bc35b17c56d4b9d5e323f4a33108aaff0d39b085e9b6cc024402950bb8e27cfeccd476ebd6c2af9fa8278327999646d987a368604a4aba59aa40a997
7
+ data.tar.gz: 2c1f8b1273fb493d825b986ac5e658f2b18fc7eebe3310ce8f5070099aa7fab71b9e1174e66b0bfdf4e0dd44b85ea0c98a0548168f52ee45b372706c873f86d8
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ /gemfiles/*.lock
6
7
  Gemfile.lock
7
8
  Guardfile
8
9
  InstalledFiles
@@ -1,12 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.2.2
4
+ - 2.3.0
5
+
6
+ before_install:
7
+ - gem install bundler
4
8
 
5
9
  gemfile:
6
- - ./gemfiles/Gemfile.chef.11.4.4
7
- - ./gemfiles/Gemfile.chef.11.6.2
8
- - ./gemfiles/Gemfile.chef.11.8.0
9
- - ./gemfiles/Gemfile.chef.11.8.2
10
- - ./gemfiles/Gemfile.chef.11.10.0
11
- - ./gemfiles/Gemfile.chef.11.10.2
12
- - ./gemfiles/Gemfile.chef.11.10.4
10
+ - ./gemfiles/Gemfile.chef.11.18.12
11
+ - ./gemfiles/Gemfile.chef.12.16.42
@@ -1,5 +1,12 @@
1
1
  ## head
2
2
 
3
+ # 2.0.0 (10/12/2016)
4
+
5
+ * Deprecate unsupported Ruby versions,
6
+ * Support supported Ruby versions (2.2 and 2.3),
7
+ * Update RSpec to 3.x,
8
+ * Update other gems.
9
+
3
10
  # 1.1.0 (04/10/2014)
4
11
 
5
12
  * add ability to correct incorrect text when editing a data bag
data/README.md CHANGED
@@ -4,8 +4,12 @@ A knife plugin to make working with data bags easier in a chef solo environment.
4
4
  If you are looking for a full featured chef solo management solution, you may
5
5
  want to check out [knife solo](https://github.com/matschaffer/knife-solo).
6
6
 
7
- *NOTE: Starting with 1.0.0, knife solo data bag only supports Chef versions >= 11.4.0.
8
- If you need support for an earlier version of chef, use a knife solo data bag version < 1.0.0.*
7
+ ## Deprecation Notices
8
+
9
+ * Versions >= 2 only support Ruby versions 2.2 and above.
10
+ If you need o use an earlier Ruby version, use `knife-solo_data_bag` < 2.0.0.
11
+ * Starting with 1.0.0, knife solo data bag only supports Chef versions >= 11.4.0.
12
+ If you need support for an earlier version of chef, use a knife solo data bag version < 1.0.0.
9
13
 
10
14
  ## Build Status
11
15
  ![Build Status](https://secure.travis-ci.org/thbishop/knife-solo_data_bag.png)
@@ -88,11 +92,13 @@ setting in knife.rb.
88
92
  This plugin has been tested on the following:
89
93
 
90
94
  Chef:
91
- * > 11.4.0
95
+ * ~> 11.8
96
+ * ~> 12.16
92
97
 
93
98
  Ruby:
94
- * 1.9.2
95
- * 1.9.3
99
+ * 2.1.8
100
+ * 2.2.2
101
+ * 2.3.0
96
102
 
97
103
  OS:
98
104
  * OSX
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ task :default => [:spec]
7
7
 
8
8
  desc 'Run specs'
9
9
  RSpec::Core::RakeTask.new do |t|
10
- t.rspec_opts = %w(-fs --color)
10
+ t.rspec_opts = %w(--format documentation --color)
11
11
  end
12
12
 
13
13
  begin
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '11.10.0'
3
+ gem 'chef', '11.18.12'
4
4
 
5
5
  gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '11.10.2'
3
+ gem 'chef', '12.16.42'
4
4
 
5
5
  gemspec :path => "../"
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Knife::SoloDataBag::VERSION
17
17
  gem.add_development_dependency 'rake'
18
- gem.add_development_dependency 'rspec', '~> 2.13.0'
19
- gem.add_development_dependency 'fakefs', '~> 0.4.0'
18
+ gem.add_development_dependency 'rspec', '>= 3.0'
19
+ gem.add_development_dependency 'fakefs'
20
20
  end
@@ -43,7 +43,8 @@ class Chef
43
43
  begin
44
44
  updated_content = Chef::JSONCompat.from_json(unparsed)
45
45
  break
46
- rescue Yajl::ParseError => e
46
+ rescue => e
47
+ raise e if !is_invalid_json_error?(e)
47
48
  loop do
48
49
  ui.stdout.puts e.to_s
49
50
  question = "Do you want to keep editing (Y/N)? If you choose 'N', all changes will be lost"
@@ -71,7 +72,8 @@ class Chef
71
72
  tf.puts text
72
73
  tf.close
73
74
 
74
- raise "Please set EDITOR environment variable" unless Kernel.system("#{config[:editor]} #{tf.path}")
75
+ exit_status = Kernel.system("#{config[:editor]} #{tf.path}")
76
+ raise "Please set EDITOR environment variable" if !exit_status
75
77
 
76
78
  output = File.read(tf.path)
77
79
  tf.unlink
@@ -105,6 +107,10 @@ class Chef
105
107
  end
106
108
  end
107
109
 
110
+ def is_invalid_json_error?(exception)
111
+ exception.class.to_s.end_with?("::ParseError")
112
+ end
113
+
108
114
  end
109
115
 
110
116
  end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module SoloDataBag
3
- VERSION = '1.1.0'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
@@ -1,11 +1,11 @@
1
1
  shared_context 'bag_name_not_provided' do
2
2
  context 'when a name is not supplied' do
3
3
  it 'should exit with an error message' do
4
- lambda {
4
+ expect do
5
5
  @knife.run
6
- }.should raise_error SystemExit
7
- @stdout.string.should match /usage/i
8
- @stderr.string.should match /name for the data bag/
6
+ end.to raise_error(SystemExit)
7
+ expect(@stdout.string).to match(/usage/i)
8
+ expect(@stderr.string).to match(/name for the data bag/)
9
9
  end
10
10
  end
11
11
  end
@@ -1,15 +1,21 @@
1
1
  shared_context 'bag_path_is_not_valid' do |args|
2
2
  context 'when the data bag path is not valid' do
3
3
  before do
4
- File.stub(:directory?).and_return(false)
4
+ allow(File).
5
+ to receive(:directory?).
6
+ and_call_original
7
+ allow(File).
8
+ to receive(:directory?).
9
+ with(/data_bags/).
10
+ and_return(false)
5
11
  @knife.name_args = ['foo']
6
12
  @knife.name_args.concat Array(args)
7
13
  end
8
14
 
9
15
  it 'should raise an invalid data bag path exception' do
10
- lambda {
16
+ expect do
11
17
  @knife.run
12
- }.should raise_error Chef::Exceptions::InvalidDataBagPath
18
+ end.to raise_error(Chef::Exceptions::InvalidDataBagPath)
13
19
  end
14
20
  end
15
21
  end
@@ -1,19 +1,25 @@
1
1
  shared_context 'secret_string_and_secret_file_are_both_provided' do |args|
2
2
  context 'when specifying -s and --secret-file' do
3
3
  before do
4
+ allow(File).
5
+ to receive(:directory?).
6
+ with(/data_bags/).
7
+ and_return(true)
8
+ allow(File).
9
+ to receive(:directory?).
10
+ and_call_original
4
11
  @knife.name_args = ['foo']
5
12
  @knife.name_args.concat Array(args)
6
13
  @knife.config[:secret] = 'foobar'
7
14
  @knife.config[:secret_file] = 'secret.txt'
8
- File.stub(:directory?).and_return(true)
9
15
  end
10
16
 
11
17
  it 'should exit with an error message' do
12
- lambda {
18
+ expect do
13
19
  @knife.run
14
- }.should raise_error SystemExit
15
- @stdout.string.should match /usage/i
16
- @stderr.string.should match /either --secret or --secret-file/
20
+ end.to raise_error(SystemExit)
21
+ expect(@stdout.string).to match(/usage/i)
22
+ expect(@stderr.string).to match(/either --secret or --secret-file/)
17
23
  end
18
24
 
19
25
  end
@@ -2,7 +2,7 @@ shared_context 'stubbed_out_stdout_and_stderr' do
2
2
  before do
3
3
  @stdout = StringIO.new
4
4
  @stderr = StringIO.new
5
- @knife.ui.stub!(:stdout).and_return(@stdout)
6
- @knife.ui.stub!(:stderr).and_return(@stderr)
5
+ allow(@knife.ui).to receive(:stdout) { @stdout }
6
+ allow(@knife.ui).to receive(:stderr) { @stderr }
7
7
  end
8
8
  end
@@ -8,9 +8,10 @@ describe Chef::Knife::SoloDataBagCreate do
8
8
  include_context 'stubbed_out_stdout_and_stderr'
9
9
 
10
10
  describe 'run' do
11
+ let(:secret_path) { '/var/chef/secret.txt' }
12
+
11
13
  include_context 'bag_name_not_provided'
12
14
  include_context 'bag_path_is_not_valid'
13
- include_context 'secret_string_and_secret_file_are_both_provided'
14
15
 
15
16
  context 'with valid arguments' do
16
17
  before do
@@ -21,8 +22,13 @@ describe Chef::Knife::SoloDataBagCreate do
21
22
 
22
23
  FakeFS.activate!
23
24
  FileUtils.mkdir_p @bags_path
25
+ allow(Chef::EncryptedDataBagItem).to receive(:load_secret).
26
+ with(secret_path).
27
+ and_return('psst')
24
28
  end
25
29
 
30
+ include_context 'secret_string_and_secret_file_are_both_provided'
31
+
26
32
  after do
27
33
  FakeFS.deactivate!
28
34
  FakeFS::FileSystem.clear
@@ -31,8 +37,8 @@ describe Chef::Knife::SoloDataBagCreate do
31
37
  context 'if an item is not specified' do
32
38
  it 'should create the data bag' do
33
39
  @knife.run
34
- File.directory?(@bags_path).should be_true
35
- File.directory?(@bag_path).should be_true
40
+ expect(File.directory?(@bags_path)).to be_truthy
41
+ expect(File.directory?(@bag_path)).to be_truthy
36
42
  end
37
43
  end
38
44
 
@@ -41,17 +47,18 @@ describe Chef::Knife::SoloDataBagCreate do
41
47
  @knife.name_args << 'bar'
42
48
  @input_data = {'id' => 'foo', 'key_1' => 'value_1', 'key_2' => 'value_2'}
43
49
  @item_path = "#{@bag_path}/bar.json"
44
- @knife.stub(:create_object).and_yield(@input_data).and_return(nil)
50
+ allow(@knife).to receive(:create_object).
51
+ and_yield(@input_data).and_return(nil)
45
52
  end
46
53
 
47
54
  it 'should create the data bag item' do
48
55
  @knife.run
49
- JSON.parse(File.read(@item_path)).should == @input_data
56
+ expect(JSON.parse(File.read(@item_path))).to eq(@input_data)
50
57
  end
51
58
 
52
59
  it 'should write pretty json' do
53
60
  @knife.run
54
- File.read(@item_path).should == JSON.pretty_generate(@input_data)
61
+ expect(File.read(@item_path)).to eq(JSON.pretty_generate(@input_data))
55
62
  end
56
63
 
57
64
  context 'with --data-bag-path' do
@@ -64,7 +71,7 @@ describe Chef::Knife::SoloDataBagCreate do
64
71
 
65
72
  it 'uses the data bag path from the override' do
66
73
  @knife.run
67
- File.directory?(@override_bag_path).should be_true
74
+ expect(File.directory?(@override_bag_path)).to be_truthy
68
75
  end
69
76
  end
70
77
 
@@ -78,39 +85,32 @@ describe Chef::Knife::SoloDataBagCreate do
78
85
  @knife.run
79
86
  content = JSON.parse(File.read(@item_path))
80
87
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
81
- content.should have_key k
82
- content[k].should_not == @input_data[k]
88
+ expect(content).to have_key(k)
89
+ expect(content[k]).not_to eq(@input_data[k])
83
90
  end
84
91
  end
85
92
  end
86
93
 
87
94
  context 'when encrypting with --secret-file' do
95
+
88
96
  before do
89
97
  @knife.name_args << 'bar'
90
- @secret_path = '/var/chef/secret.txt'
91
- @knife.config[:secret_file] = @secret_path
92
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
93
- with(@secret_path).
94
- and_return('psst')
98
+ @knife.config[:secret_file] = secret_path
95
99
  end
96
100
 
97
101
  it 'should create the encrypted data bag item' do
98
102
  @knife.run
99
103
  content = JSON.parse(File.read(@item_path))
100
104
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
101
- content.should have_key k
102
- content[k].should_not == @input_data[k]
105
+ expect(content).to have_key(k)
106
+ expect(content[k]).to_not eq(@input_data[k])
103
107
  end
104
108
  end
105
109
  end
106
110
 
107
111
  context 'when encrypting with secret set in knife config' do
108
112
  before do
109
- @secret_path = '/var/chef/secret.txt'
110
- Chef::Config[:encrypted_data_bag_secret] = @secret_path
111
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
112
- with(@secret_path).
113
- and_return('psst')
113
+ Chef::Config[:encrypted_data_bag_secret] = secret_path
114
114
  end
115
115
 
116
116
  after { Chef::Config[:encrypted_data_bag_secret] = nil }
@@ -119,8 +119,8 @@ describe Chef::Knife::SoloDataBagCreate do
119
119
  @knife.run
120
120
  content = JSON.parse(File.read(@item_path))
121
121
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
122
- content.should have_key k
123
- content[k].should_not == @input_data[k]
122
+ expect(content).to have_key(k)
123
+ expect(content[k]).to_not eq(@input_data[k])
124
124
  end
125
125
  end
126
126
 
@@ -138,7 +138,7 @@ describe Chef::Knife::SoloDataBagCreate do
138
138
 
139
139
  it 'should create the data bag item' do
140
140
  @knife.run
141
- JSON.parse(File.read(@item_path)).should == @input_data
141
+ expect(JSON.parse(File.read(@item_path))).to eq(@input_data)
142
142
  end
143
143
 
144
144
  context 'when encrypting with -s or --secret' do
@@ -151,8 +151,8 @@ describe Chef::Knife::SoloDataBagCreate do
151
151
  @knife.run
152
152
  content = JSON.parse(File.read(@item_path))
153
153
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
154
- content.should have_key k
155
- content[k].should_not == @input_data[k]
154
+ expect(content).to have_key(k)
155
+ expect(content[k]).to_not eq(@input_data[k])
156
156
  end
157
157
  end
158
158
  end
@@ -160,30 +160,22 @@ describe Chef::Knife::SoloDataBagCreate do
160
160
  context 'when encrypting with --secret-file' do
161
161
  before do
162
162
  @knife.name_args << 'bar'
163
- @secret_path = '/var/chef/secret.txt'
164
- @knife.config[:secret_file] = @secret_path
165
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
166
- with(@secret_path).
167
- and_return('psst')
163
+ @knife.config[:secret_file] = secret_path
168
164
  end
169
165
 
170
166
  it 'should create the encrypted data bag item' do
171
167
  @knife.run
172
168
  content = JSON.parse(File.read(@item_path))
173
169
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
174
- content.should have_key k
175
- content[k].should_not == @input_data[k]
170
+ expect(content).to have_key(k)
171
+ expect(content[k]).to_not eq(@input_data[k])
176
172
  end
177
173
  end
178
174
  end
179
175
 
180
176
  context 'when encrypting with secret set in knife config' do
181
177
  before do
182
- @secret_path = '/var/chef/secret.txt'
183
- Chef::Config[:encrypted_data_bag_secret] = @secret_path
184
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
185
- with(@secret_path).
186
- and_return('psst')
178
+ Chef::Config[:encrypted_data_bag_secret] = secret_path
187
179
  end
188
180
 
189
181
  after { Chef::Config[:encrypted_data_bag_secret] = nil }
@@ -192,8 +184,8 @@ describe Chef::Knife::SoloDataBagCreate do
192
184
  @knife.run
193
185
  content = JSON.parse(File.read(@item_path))
194
186
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
195
- content.should have_key k
196
- content[k].should_not == @input_data[k]
187
+ expect(content).to have_key(k)
188
+ expect(content[k]).to_not eq(@input_data[k])
197
189
  end
198
190
  end
199
191
 
@@ -212,7 +204,7 @@ describe Chef::Knife::SoloDataBagCreate do
212
204
 
213
205
  it 'creates the data bag item' do
214
206
  @knife.run
215
- JSON.parse(File.read(@item_path)).should == @input_data
207
+ expect(JSON.parse(File.read(@item_path))).to eq(@input_data)
216
208
  end
217
209
  end
218
210
 
@@ -1,13 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chef::Knife::SoloDataBagEdit do
3
+ RSpec.describe Chef::Knife::SoloDataBagEdit do
4
4
  before do
5
- @knife = subject
5
+ @knife = subject
6
6
  end
7
7
 
8
8
  include_context 'stubbed_out_stdout_and_stderr'
9
9
 
10
10
  describe 'run' do
11
+ let(:bags_path) { '/var/chef/data_bags' }
12
+ let(:bag_path) { "#{bags_path}/bag_1" }
13
+
14
+ before do
15
+ FakeFS.activate!
16
+ FileUtils.mkdir_p bag_path
17
+ end
18
+
19
+ after do
20
+ FakeFS.deactivate!
21
+ FakeFS::FileSystem.clear
22
+ end
23
+
11
24
  include_context 'bag_name_not_provided'
12
25
  include_context 'bag_path_is_not_valid', ['foo']
13
26
  include_context 'secret_string_and_secret_file_are_both_provided', ['bar']
@@ -18,11 +31,11 @@ describe Chef::Knife::SoloDataBagEdit do
18
31
  end
19
32
 
20
33
  it 'should exit with an error message' do
21
- lambda {
34
+ expect do
22
35
  @knife.run
23
- }.should raise_error SystemExit
24
- @stdout.string.should match(/usage/i)
25
- @stderr.string.should match(/name for the item/)
36
+ end.to raise_error(SystemExit)
37
+ expect(@stdout.string).to match(/usage/i)
38
+ expect(@stderr.string).to match(/name for the item/)
26
39
  end
27
40
  end
28
41
 
@@ -38,11 +51,11 @@ describe Chef::Knife::SoloDataBagEdit do
38
51
  )
39
52
  end
40
53
  let(:tempfile_name) { '/tmp/foo' }
54
+ let(:editor) { 'vimacs' }
55
+ let(:edit_command) { "#{editor} #{tempfile_name}" }
41
56
 
42
57
  before do
43
- @bags_path = '/var/chef/data_bags'
44
- @bag_path = "#{@bags_path}/bag_1"
45
- @item_path = "#{@bag_path}/foo.json"
58
+ @item_path = "#{bag_path}/foo.json"
46
59
  @knife.name_args = ['bag_1', 'foo']
47
60
  @orig_data = {'id' => 'foo', 'who' => 'bob'}
48
61
  @updated_data = {'id' => 'foo', 'who' => 'sue'}
@@ -50,33 +63,32 @@ describe Chef::Knife::SoloDataBagEdit do
50
63
  @bag_item_foo.data_bag 'bag_1'
51
64
  @updated_bag_item = Chef::DataBagItem.from_hash @updated_data
52
65
  @updated_bag_item.data_bag 'bag_1'
53
-
54
- FakeFS.activate!
55
- FileUtils.mkdir_p @bag_path
56
-
57
- Chef::DataBagItem.should_receive(:load).with('bag_1', 'foo').
58
- and_return(@bag_item_foo)
59
- Tempfile.stub(:new).and_return(tf)
60
- Kernel.stub(:system => true)
61
- File.stub(:read).and_call_original
62
- File.stub(:read).with(tempfile_name).and_return(@updated_data.to_json)
63
- Chef::Config[:data_bag_path] = @bags_path
64
- end
65
-
66
- after do
67
- FakeFS.deactivate!
68
- FakeFS::FileSystem.clear
66
+ @knife.config[:editor] = 'vimacs'
67
+
68
+ allow(Chef::DataBagItem).to receive(:load).
69
+ with('bag_1', 'foo').
70
+ and_return(@bag_item_foo)
71
+ allow(Tempfile).to receive(:new).
72
+ with(['knife-edit', '.json']).
73
+ and_return(tf)
74
+ allow(Kernel).to receive(:system).and_call_original
75
+ allow(Kernel).to receive(:system).with(edit_command) { true }
76
+ allow(File).to receive(:read).and_call_original
77
+ allow(File).to receive(:read).
78
+ with(tempfile_name).
79
+ and_return(@updated_data.to_json)
80
+ Chef::Config[:data_bag_path] = bags_path
69
81
  end
70
82
 
71
83
  it 'should edit the data bag item' do
72
84
  @knife.run
73
- JSON.parse(File.read(@item_path)).should == @updated_data
85
+ expect(JSON.parse(File.read(@item_path))).to eq(@updated_data)
74
86
  end
75
87
 
76
88
  it 'should write pretty json' do
77
89
  @knife.run
78
90
  data = JSON.pretty_generate(:id => 'foo', :who => 'sue')
79
- File.read(@item_path).should == data
91
+ expect(File.read(@item_path)).to eq(data)
80
92
  end
81
93
 
82
94
  context 'with --data-bag-path' do
@@ -91,23 +103,24 @@ describe Chef::Knife::SoloDataBagEdit do
91
103
  it 'uses the data bag path from the override' do
92
104
  @knife.run
93
105
  data = JSON.parse(File.read(@override_item_path))
94
- data.should == @updated_data
106
+ expect(data).to eq(@updated_data)
95
107
  end
96
108
  end
97
109
 
98
110
  context 'when encrypting with -s or --secret' do
99
111
  before do
100
112
  @knife.config[:secret] = 'secret_key'
101
- Chef::EncryptedDataBagItem.should_receive(:new).
102
- with(@bag_item_foo.raw_data, 'secret_key').
103
- and_return(@updated_data)
113
+ allow(Chef::EncryptedDataBagItem).
114
+ to receive(:new).
115
+ with(@bag_item_foo.raw_data, 'secret_key').
116
+ and_return(@updated_data)
104
117
  end
105
118
 
106
119
  it 'should edit the encrypted data bag item' do
107
120
  @knife.run
108
121
  content = JSON.parse(File.read(@item_path))
109
- content['who'].should_not == @orig_data['who']
110
- content['who'].should_not be_nil
122
+ expect(content['who']).not_to eq(@orig_data['who'])
123
+ expect(content['who']).not_to be_nil
111
124
  end
112
125
  end
113
126
 
@@ -115,19 +128,20 @@ describe Chef::Knife::SoloDataBagEdit do
115
128
  before do
116
129
  @secret_path = '/var/chef/secret.txt'
117
130
  @knife.config[:secret_file] = @secret_path
118
- Chef::EncryptedDataBagItem.stub(:load_secret).
119
- with(@secret_path).
120
- and_return('psst')
121
- Chef::EncryptedDataBagItem.should_receive(:new).
122
- with(@bag_item_foo.raw_data, 'psst').
123
- and_return(@updated_data)
131
+ allow(Chef::EncryptedDataBagItem).to receive(:load_secret).
132
+ with(@secret_path).
133
+ and_return('psst')
134
+ allow(Chef::EncryptedDataBagItem).
135
+ to receive(:new).
136
+ with(@bag_item_foo.raw_data, 'psst').
137
+ and_return(@updated_data)
124
138
  end
125
139
 
126
140
  it 'should edit the encrypted data bag item' do
127
141
  @knife.run
128
142
  content = JSON.parse(File.read(@item_path))
129
- content['who'].should_not == @orig_data['who']
130
- content['who'].should_not be_nil
143
+ expect(content['who']).not_to eq(@orig_data['who'])
144
+ expect(content['who']).not_to be_nil
131
145
  end
132
146
  end
133
147
 
@@ -135,12 +149,14 @@ describe Chef::Knife::SoloDataBagEdit do
135
149
  before do
136
150
  @secret_path = '/var/chef/secret.txt'
137
151
  Chef::Config[:encrypted_data_bag_secret] = @secret_path
138
- Chef::EncryptedDataBagItem.stub(:load_secret).
139
- with(@secret_path).
140
- and_return('psst')
141
- Chef::EncryptedDataBagItem.should_receive(:new).
142
- with(@bag_item_foo.raw_data, 'psst').
143
- and_return(@updated_data)
152
+ allow(Chef::EncryptedDataBagItem).
153
+ to receive(:load_secret).
154
+ with(@secret_path).
155
+ and_return('psst')
156
+ allow(Chef::EncryptedDataBagItem).
157
+ to receive(:new).
158
+ with(@bag_item_foo.raw_data, 'psst').
159
+ and_return(@updated_data)
144
160
  end
145
161
 
146
162
  after { Chef::Config[:encrypted_data_bag_secret] = nil }
@@ -148,19 +164,20 @@ describe Chef::Knife::SoloDataBagEdit do
148
164
  it 'should edit the encrypted data bag item' do
149
165
  @knife.run
150
166
  content = JSON.parse(File.read(@item_path))
151
- content['who'].should_not == @orig_data['who']
152
- content['who'].should_not be_nil
167
+ expect(content['who']).not_to eq(@orig_data['who'])
168
+ expect(content['who']).not_to be_nil
153
169
  end
154
170
  end
155
171
 
156
172
  context 'with malformed JSON' do
157
173
  let(:user_wants_to_reedit) { 'Y' }
174
+ let(:bad_json) { '{,badjson}' }
158
175
 
159
176
  before do
160
- @knife.config[:editor] = 'vimacs'
161
177
  @pass = 0
162
178
  @asked_to_continue = 0
163
- File.stub(:read).with(tempfile_name) do
179
+
180
+ allow(File).to receive(:read).with(tempfile_name) do
164
181
  @pass += 1
165
182
  case @pass
166
183
  when 1
@@ -169,25 +186,36 @@ describe Chef::Knife::SoloDataBagEdit do
169
186
  @updated_data.to_json
170
187
  end
171
188
  end
172
- @knife.ui.stub(:ask) do
189
+
190
+ allow(@knife.ui).to receive(:ask) do
173
191
  case @pass
174
192
  when 1
175
193
  @asked_to_continue += 1
176
194
  user_wants_to_reedit
195
+ else
196
+ nil
177
197
  end
178
198
  end
179
199
  end
180
200
 
181
201
  it 'asks whether to re-edit' do
182
202
  @knife.run
183
- @asked_to_continue.should == 1
203
+ expect(@asked_to_continue).to eq(1)
184
204
  end
185
205
 
186
206
  context 'when the user wants to re-edit' do
207
+ before do
208
+ allow(Kernel).to receive(:system).
209
+ with(edit_command).
210
+ and_return(true)
211
+ end
212
+
187
213
  it 'the editor is re-opened' do
188
- Kernel.should_receive(:system).with("vimacs #{tempfile_name}").
189
- exactly(2).times.and_return(true)
190
214
  @knife.run
215
+
216
+ expect(Kernel).to have_received(:system).
217
+ with(edit_command).
218
+ exactly(2).times
191
219
  end
192
220
  end
193
221
 
@@ -195,9 +223,9 @@ describe Chef::Knife::SoloDataBagEdit do
195
223
  let(:user_wants_to_reedit) { 'N' }
196
224
 
197
225
  it 'an error is thrown' do
198
- lambda {
226
+ expect do
199
227
  @knife.run
200
- }.should raise_error(Yajl::ParseError)
228
+ end.to raise_error(StandardError)
201
229
  end
202
230
  end
203
231
  end
@@ -30,8 +30,8 @@ describe Chef::Knife::SoloDataBagList do
30
30
 
31
31
  it 'should list all of the data bags' do
32
32
  @knife.run
33
- @stdout.string.should match /bag_1/
34
- @stdout.string.should match /bag_2/
33
+ expect(@stdout.string).to match(/bag_1/)
34
+ expect(@stdout.string).to match(/bag_2/)
35
35
  end
36
36
 
37
37
  context 'with --data-bag-path' do
@@ -44,8 +44,8 @@ describe Chef::Knife::SoloDataBagList do
44
44
 
45
45
  it 'should list all of the data bags' do
46
46
  @knife.run
47
- @stdout.string.should match /bag_1-opt/
48
- @stdout.string.should match /bag_2-opt/
47
+ expect(@stdout.string).to match(/bag_1-opt/)
48
+ expect(@stdout.string).to match(/bag_2-opt/)
49
49
  end
50
50
  end
51
51
 
@@ -8,54 +8,58 @@ describe Chef::Knife::SoloDataBagShow do
8
8
  include_context 'stubbed_out_stdout_and_stderr'
9
9
 
10
10
  describe 'run' do
11
+ let(:bags_path) { '/var/chef/data_bags' }
12
+ let(:bag_path) { "#{bags_path}/bag_1" }
13
+
14
+ before do
15
+ FakeFS.activate!
16
+ FileUtils.mkdir_p bag_path
17
+ Chef::Config[:data_bag_path] = bags_path
18
+ end
19
+
20
+ after do
21
+ FakeFS.deactivate!
22
+ FakeFS::FileSystem.clear
23
+ end
24
+
11
25
  include_context 'bag_name_not_provided'
12
26
  include_context 'bag_path_is_not_valid'
13
27
  include_context 'secret_string_and_secret_file_are_both_provided'
14
28
 
15
29
  context 'with valid arguments' do
16
30
  before do
17
- @bags_path = '/var/chef/data_bags'
18
- @bag_path = "#{@bags_path}/bag_1"
19
31
  @knife.name_args = ['bag_1']
20
32
 
21
- FakeFS.activate!
22
- FileUtils.mkdir_p @bag_path
23
-
24
33
  @bag_item_foo = Chef::DataBagItem.from_hash 'id' => 'foo', 'who' => 'bob'
25
34
  @bag_item_bar = Chef::DataBagItem.from_hash 'id' => 'bar', 'who' => 'sue'
26
- Chef::Config[:data_bag_path] = @bags_path
27
- end
28
-
29
- after do
30
- FakeFS.deactivate!
31
- FakeFS::FileSystem.clear
32
35
  end
33
36
 
34
37
  context 'if an item is not specified' do
35
38
  before do
36
39
  bag_items = {'foo' => @bag_item_foo, 'bar' => @bag_item_bar}
37
- Chef::DataBag.should_receive(:load).with('bag_1').
38
- and_return(bag_items)
40
+ allow(Chef::DataBag).to receive(:load).
41
+ with('bag_1').
42
+ and_return(bag_items)
39
43
  end
40
44
 
41
45
  it 'should show the list of items' do
42
46
  @knife.run
43
- @stdout.string.should match /foo/
44
- @stdout.string.should match /bar/
47
+ expect(@stdout.string).to match(/foo/)
48
+ expect(@stdout.string).to match(/bar/)
45
49
  end
46
50
 
47
51
  context 'with --data-bag-path' do
52
+ let(:bags_path) { '/opt/bags' }
53
+
48
54
  before do
49
- @bags_path = '/opt/bags'
50
- @bag_path = "#{@bags_path}/bag_1"
51
- FileUtils.mkdir_p @bag_path
52
- @knife.config[:data_bag_path] = @bags_path
55
+ FileUtils.mkdir_p bag_path
56
+ @knife.config[:data_bag_path] = bags_path
53
57
  end
54
58
 
55
59
  it 'uses the data bag path from the override' do
56
60
  @knife.run
57
- @stdout.string.should match /foo/
58
- @stdout.string.should match /bar/
61
+ expect(@stdout.string).to match(/foo/)
62
+ expect(@stdout.string).to match(/bar/)
59
63
  end
60
64
  end
61
65
 
@@ -67,37 +71,39 @@ describe Chef::Knife::SoloDataBagShow do
67
71
  end
68
72
 
69
73
  it 'should show the item' do
70
- Chef::DataBagItem.should_receive(:load).with('bag_1', 'foo').
71
- and_return(@bag_item_foo)
74
+ allow(Chef::DataBagItem).to receive(:load).
75
+ with('bag_1', 'foo').
76
+ and_return(@bag_item_foo)
72
77
  @knife.run
73
- @stdout.string.should match /id:\s+foo.+who:\s+bob/m
78
+ expect(@stdout.string).to match(/id:\s+foo.+who:\s+bob/m)
74
79
  end
75
80
 
76
81
  context 'and with -F of json' do
77
82
  before do
78
83
  @knife.config[:format] = 'json'
79
- Chef::DataBagItem.should_receive(:load).with('bag_1', 'foo').
80
- and_return(@bag_item_foo)
84
+ allow(Chef::DataBagItem).to receive(:load).with('bag_1', 'foo').
85
+ and_return(@bag_item_foo)
81
86
  end
82
87
 
83
88
  it 'should show the item as json' do
84
89
  @knife.run
85
- @stdout.string.should match /"id":\s+"foo".+"who":\s+"bob"/m
86
- @stdout.string.should_not match /json_class/
90
+ expect(@stdout.string).to match(/"id":\s+"foo".+"who":\s+"bob"/m)
91
+ expect(@stdout.string).not_to match(/json_class/)
87
92
  end
88
93
  end
89
94
 
90
95
  context 'when encrypting with -s or --secret' do
91
96
  before do
92
97
  @knife.config[:secret] = 'SECRET'
93
- Chef::EncryptedDataBagItem.should_receive(:load).
94
- with('bag_1', 'foo', 'SECRET').
95
- and_return(@bag_item_foo)
98
+ allow(Chef::EncryptedDataBagItem).
99
+ to receive(:load).
100
+ with('bag_1', 'foo', 'SECRET').
101
+ and_return(@bag_item_foo)
96
102
  end
97
103
 
98
104
  it 'should show the unencrypted item' do
99
105
  @knife.run
100
- @stdout.string.should match /id:\s+foo.+who:\s+bob/m
106
+ expect(@stdout.string).to match(/id:\s+foo.+who:\s+bob/m)
101
107
  end
102
108
 
103
109
  context 'and with -F of json' do
@@ -107,8 +113,8 @@ describe Chef::Knife::SoloDataBagShow do
107
113
 
108
114
  it 'should show the unencrypted item as json' do
109
115
  @knife.run
110
- @stdout.string.should match /"id":\s+"foo".+"who":\s+"bob"/m
111
- @stdout.string.should_not match /json_class/
116
+ expect(@stdout.string).to match(/"id":\s+"foo".+"who":\s+"bob"/m)
117
+ expect(@stdout.string).not_to match(/json_class/)
112
118
  end
113
119
  end
114
120
  end
@@ -116,17 +122,17 @@ describe Chef::Knife::SoloDataBagShow do
116
122
  context 'when encrypting with --secret-file' do
117
123
  before do
118
124
  @knife.config[:secret_file] = '/var/tmp/secret'
119
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
120
- with('/var/tmp/secret').
121
- and_return('abcd')
122
- Chef::EncryptedDataBagItem.should_receive(:load).
123
- with('bag_1', 'foo', 'abcd').
124
- and_return(@bag_item_foo)
125
+ allow(Chef::EncryptedDataBagItem).to receive(:load_secret).
126
+ with('/var/tmp/secret').
127
+ and_return('abcd')
128
+ allow(Chef::EncryptedDataBagItem).to receive(:load).
129
+ with('bag_1', 'foo', 'abcd').
130
+ and_return(@bag_item_foo)
125
131
  end
126
132
 
127
133
  it 'should show the unencrypted item' do
128
134
  @knife.run
129
- @stdout.string.should match /id:\s+foo.+who:\s+bob/m
135
+ expect(@stdout.string).to match(/id:\s+foo.+who:\s+bob/m)
130
136
  end
131
137
 
132
138
  context 'and with -F of json' do
@@ -136,8 +142,8 @@ describe Chef::Knife::SoloDataBagShow do
136
142
 
137
143
  it 'should show the unencrypted item as json' do
138
144
  @knife.run
139
- @stdout.string.should match /"id":\s+"foo".+"who":\s+"bob"/m
140
- @stdout.string.should_not match /json_class/
145
+ expect(@stdout.string).to match(/"id":\s+"foo".+"who":\s+"bob"/m)
146
+ expect(@stdout.string).not_to match(/json_class/)
141
147
  end
142
148
  end
143
149
  end
@@ -146,17 +152,17 @@ describe Chef::Knife::SoloDataBagShow do
146
152
  before do
147
153
  @secret_path = '/var/chef/secret.txt'
148
154
  Chef::Config[:encrypted_data_bag_secret] = @secret_path
149
- Chef::EncryptedDataBagItem.should_receive(:load_secret).
150
- with(@secret_path).
151
- and_return('abcd')
152
- Chef::EncryptedDataBagItem.should_receive(:load).
153
- with('bag_1', 'foo', 'abcd').
154
- and_return(@bag_item_foo)
155
+ allow(Chef::EncryptedDataBagItem).to receive(:load_secret).
156
+ with(@secret_path).
157
+ and_return('abcd')
158
+ allow(Chef::EncryptedDataBagItem).to receive(:load).
159
+ with('bag_1', 'foo', 'abcd').
160
+ and_return(@bag_item_foo)
155
161
  end
156
162
 
157
163
  it 'should show the unencrypted item' do
158
164
  @knife.run
159
- @stdout.string.should match /id:\s+foo.+who:\s+bob/m
165
+ expect(@stdout.string).to match(/id:\s+foo.+who:\s+bob/m)
160
166
  end
161
167
 
162
168
  context 'and with -F of json' do
@@ -166,8 +172,8 @@ describe Chef::Knife::SoloDataBagShow do
166
172
 
167
173
  it 'should show the unencrypted item as json' do
168
174
  @knife.run
169
- @stdout.string.should match /"id":\s+"foo".+"who":\s+"bob"/m
170
- @stdout.string.should_not match /json_class/
175
+ expect(@stdout.string).to match(/"id":\s+"foo".+"who":\s+"bob"/m)
176
+ expect(@stdout.string).not_to match(/json_class/)
171
177
  end
172
178
  end
173
179
  end
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-solo_data_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tommy Bishop
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2016-12-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 2.13.0
33
+ version: '3.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: 2.13.0
40
+ version: '3.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: fakefs
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 0.4.0
47
+ version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
- version: 0.4.0
54
+ version: '0'
62
55
  description: A knife plugin for working with data bags and chef solo
63
56
  email:
64
57
  - bishop.thomas@gmail.com
@@ -66,23 +59,18 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
70
- - .kitchen.yml
71
- - .rspec
72
- - .ruby-gemset
73
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".kitchen.yml"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".travis.yml"
74
67
  - CHANGELOG.md
75
68
  - Gemfile
76
69
  - LICENSE
77
70
  - README.md
78
71
  - Rakefile
79
- - gemfiles/Gemfile.chef.11.10.0
80
- - gemfiles/Gemfile.chef.11.10.2
81
- - gemfiles/Gemfile.chef.11.10.4
82
- - gemfiles/Gemfile.chef.11.4.4
83
- - gemfiles/Gemfile.chef.11.6.2
84
- - gemfiles/Gemfile.chef.11.8.0
85
- - gemfiles/Gemfile.chef.11.8.2
72
+ - gemfiles/Gemfile.chef.11.18.12
73
+ - gemfiles/Gemfile.chef.12.16.42
86
74
  - knife-solo_data_bag.gemspec
87
75
  - lib/chef/knife/solo_data_bag_create.rb
88
76
  - lib/chef/knife/solo_data_bag_edit.rb
@@ -105,39 +93,25 @@ files:
105
93
  - test/integration/data/solo.rb
106
94
  homepage: https://github.com/thbishop/knife-solo_data_bag
107
95
  licenses: []
96
+ metadata: {}
108
97
  post_install_message:
109
98
  rdoc_options: []
110
99
  require_paths:
111
100
  - lib
112
101
  required_ruby_version: !ruby/object:Gem::Requirement
113
- none: false
114
102
  requirements:
115
- - - ! '>='
103
+ - - ">="
116
104
  - !ruby/object:Gem::Version
117
105
  version: '0'
118
106
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
107
  requirements:
121
- - - ! '>='
108
+ - - ">="
122
109
  - !ruby/object:Gem::Version
123
110
  version: '0'
124
111
  requirements: []
125
112
  rubyforge_project:
126
- rubygems_version: 1.8.23
113
+ rubygems_version: 2.5.1
127
114
  signing_key:
128
- specification_version: 3
115
+ specification_version: 4
129
116
  summary: A knife plugin for working with data bags and chef solo
130
- test_files:
131
- - spec/contexts/bag_name_not_provided.rb
132
- - spec/contexts/bag_path_is_not_valid.rb
133
- - spec/contexts/secret_string_and_secret_file_are_both_provided.rb
134
- - spec/contexts/stubbed_out_stdout_and_stderr.rb
135
- - spec/spec_helper.rb
136
- - spec/unit/solo_data_bag_create_spec.rb
137
- - spec/unit/solo_data_bag_edit_spec.rb
138
- - spec/unit/solo_data_bag_list_spec.rb
139
- - spec/unit/solo_data_bag_show_spec.rb
140
- - test/integration/bootstrap.sh
141
- - test/integration/data/cookbooks/foo/metadata.rb
142
- - test/integration/data/cookbooks/foo/recipes/default.rb
143
- - test/integration/data/solo.rb
117
+ test_files: []
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'chef', '11.10.4'
4
-
5
- gemspec :path => "../"
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'chef', '11.4.4'
4
-
5
- gemspec :path => "../"
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'chef', '11.6.2'
4
-
5
- gemspec :path => "../"
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'chef', '11.8.0'
4
-
5
- gemspec :path => "../"
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'chef', '11.8.2'
4
-
5
- gemspec :path => "../"