knife-solo_data_bag 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -3
- data/README.md +10 -3
- data/lib/chef/knife/helpers.rb +4 -0
- data/lib/chef/knife/solo_data_bag_create.rb +15 -3
- data/lib/chef/knife/solo_data_bag_edit.rb +4 -0
- data/lib/chef/knife/solo_data_bag_list.rb +4 -0
- data/lib/chef/knife/solo_data_bag_show.rb +4 -0
- data/lib/knife-solo_data_bag/version.rb +1 -1
- data/spec/unit/solo_data_bag_create_spec.rb +30 -0
- data/spec/unit/solo_data_bag_edit_spec.rb +16 -0
- data/spec/unit/solo_data_bag_list_spec.rb +16 -0
- data/spec/unit/solo_data_bag_show_spec.rb +16 -0
- metadata +37 -11
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
## head
|
2
2
|
|
3
|
-
|
3
|
+
# 0.4.0 (05/30/2013)
|
4
|
+
* Add support for creating a data bag item from a json file (--json-file) ([@joeyates](https://github.com/joeyates))
|
5
|
+
* Add support for specifying the data bag path on the command line (--data-bag-path) ([@ToQoz](https://github.com/ToQoz))
|
6
|
+
|
7
|
+
## 0.3.2 (04/06/2013)
|
4
8
|
* Send warning about overriding secret in knife.rb to STDERR instead of STDOUT (props to BK Box @gondoi)
|
5
9
|
|
6
|
-
## 0.3.1 (01/11/
|
10
|
+
## 0.3.1 (01/11/2013)
|
7
11
|
* Write pretty json to disk (addresses #1)
|
8
12
|
|
9
13
|
## 0.3.0 (11/08/2012)
|
@@ -20,4 +24,3 @@
|
|
20
24
|
|
21
25
|
## 0.1.0 (05/17/2012)
|
22
26
|
* Initial release
|
23
|
-
|
data/README.md
CHANGED
@@ -30,6 +30,10 @@ Create a data bag item with JSON from the command line (works with encryption)
|
|
30
30
|
|
31
31
|
$ knife solo data bag create apps app_1 --json '{"id": "app_1", "username": "bob"}'
|
32
32
|
|
33
|
+
Create a data bag item from a json file
|
34
|
+
|
35
|
+
$ knife solo data bag create apps app_1 --json-file foo.json
|
36
|
+
|
33
37
|
### Edit
|
34
38
|
Edit a plain text data bag
|
35
39
|
|
@@ -66,10 +70,13 @@ You can also display any of the above variations in JSON format with `-F json`
|
|
66
70
|
$ knife solo data bag show apps app_1 -s secret_key -F json
|
67
71
|
|
68
72
|
## Notes
|
69
|
-
|
70
|
-
|
71
|
-
|
73
|
+
### Data Bag Path
|
74
|
+
By default, this plugin will use the configured data_bag_path. This is
|
75
|
+
defaulted to `/var/chef/data_bags` by Chef. It is possible to override this
|
76
|
+
path in your Chef client config if desired. When using this plugin, it is also
|
77
|
+
possible to override the path using the `--data-bag-path` argument.
|
72
78
|
|
79
|
+
### Encrypted Data Bag Secret
|
73
80
|
This plugin respects the "encrypted_data_bag_secret" configuration option in
|
74
81
|
knife.rb. Command line secret arguments (-s or --secret-file) will override the
|
75
82
|
setting in knife.rb.
|
data/lib/chef/knife/helpers.rb
CHANGED
@@ -26,6 +26,14 @@ module KnifeSoloDataBag
|
|
26
26
|
:long => '--json JSON_STRING',
|
27
27
|
:description => 'The data bag json string that can be passed at the CLI'
|
28
28
|
|
29
|
+
option :json_file,
|
30
|
+
:long => '--json-file JSON_FILE',
|
31
|
+
:description => 'A file contining the data bag json string'
|
32
|
+
|
33
|
+
option :data_bag_path,
|
34
|
+
:long => '--data-bag-path DATA_BAG_PATH',
|
35
|
+
:description => 'The path to data bag'
|
36
|
+
|
29
37
|
def run
|
30
38
|
@bag_name, @item_name = @name_args
|
31
39
|
ensure_valid_arguments
|
@@ -45,12 +53,16 @@ module KnifeSoloDataBag
|
|
45
53
|
|
46
54
|
def create_item_object
|
47
55
|
item = nil
|
48
|
-
|
56
|
+
case
|
57
|
+
when config[:json_string]
|
58
|
+
item = Chef::DataBagItem.from_hash bag_item_content(convert_json_string)
|
59
|
+
when config[:json_file]
|
60
|
+
json_string = JSON.parse(File.read(config[:json_file]))
|
61
|
+
item = Chef::DataBagItem.from_hash bag_item_content(json_string)
|
62
|
+
else
|
49
63
|
create_object({'id' => item_name}, "data_bag_item[#{item_name}]") do |output|
|
50
64
|
item = Chef::DataBagItem.from_hash bag_item_content(output)
|
51
65
|
end
|
52
|
-
else
|
53
|
-
item = Chef::DataBagItem.from_hash bag_item_content(convert_json_string)
|
54
66
|
end
|
55
67
|
item
|
56
68
|
end
|
@@ -20,6 +20,10 @@ module KnifeSoloDataBag
|
|
20
20
|
:long => '--secret-file SECRET_FILE',
|
21
21
|
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
22
22
|
|
23
|
+
option :data_bag_path,
|
24
|
+
:long => '--data-bag-path DATA_BAG_PATH',
|
25
|
+
:description => 'The path to data bag'
|
26
|
+
|
23
27
|
def run
|
24
28
|
Chef::Config[:solo] = true
|
25
29
|
@bag_name, @item_name = @name_args
|
@@ -20,6 +20,10 @@ module KnifeSoloDataBag
|
|
20
20
|
:long => '--secret-file SECRET_FILE',
|
21
21
|
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
22
22
|
|
23
|
+
option :data_bag_path,
|
24
|
+
:long => '--data-bag-path DATA_BAG_PATH',
|
25
|
+
:description => 'The path to data bag'
|
26
|
+
|
23
27
|
def run
|
24
28
|
Chef::Config[:solo] = true
|
25
29
|
@bag_name, @item_name = @name_args
|
@@ -49,6 +49,20 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
|
|
49
49
|
JSON.parse(File.read(@item_path)).raw_data.should == @input_data
|
50
50
|
end
|
51
51
|
|
52
|
+
context 'with --data-bag-path' do
|
53
|
+
before do
|
54
|
+
@override_bags_path = '/opt/bags'
|
55
|
+
@override_bag_path = "#{@override_bags_path}/bag_1"
|
56
|
+
@knife.config[:data_bag_path] = @override_bags_path
|
57
|
+
FileUtils.mkdir_p @override_bags_path
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'uses the data bag path from the override' do
|
61
|
+
@knife.run
|
62
|
+
File.directory?(@override_bag_path).should be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
52
66
|
context 'when encrypting with -s or --secret' do
|
53
67
|
before do
|
54
68
|
@knife.name_args << 'bar'
|
@@ -181,6 +195,22 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
|
|
181
195
|
end
|
182
196
|
end
|
183
197
|
|
198
|
+
context 'when also specifying a json file' do
|
199
|
+
before do
|
200
|
+
@knife.name_args << 'bar'
|
201
|
+
@json_path = '/var/chef/my_bag.json'
|
202
|
+
@knife.config[:json_file] = @json_path
|
203
|
+
@input_data = {'id' => 'foo', 'sub' => {'key_1' => 'value_1', 'key_2' => 'value_2'}}
|
204
|
+
@item_path = "#{@bag_path}/bar.json"
|
205
|
+
File.open(@json_path, 'w') { |f| f.write @input_data.to_json }
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'creates the data bag item' do
|
209
|
+
@knife.run
|
210
|
+
JSON.parse(File.read(@item_path)).raw_data.should == @input_data
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
184
214
|
end
|
185
215
|
|
186
216
|
end
|
@@ -72,6 +72,22 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
|
|
72
72
|
})
|
73
73
|
end
|
74
74
|
|
75
|
+
context 'with --data-bag-path' do
|
76
|
+
before do
|
77
|
+
@override_bags_path = '/opt/bags'
|
78
|
+
@override_bag_path = "#{@override_bags_path}/bag_1"
|
79
|
+
@override_item_path = "#{@override_bag_path}/foo.json"
|
80
|
+
@knife.config[:data_bag_path] = @override_bags_path
|
81
|
+
FileUtils.mkdir_p @override_bag_path
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'uses the data bag path from the override' do
|
85
|
+
@knife.run
|
86
|
+
data = JSON.parse(File.read(@override_item_path)).raw_data
|
87
|
+
data.should == @updated_data
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
75
91
|
context 'when encrypting with -s or --secret' do
|
76
92
|
before do
|
77
93
|
@knife.config[:secret] = 'secret_key'
|
@@ -33,6 +33,22 @@ describe KnifeSoloDataBag::SoloDataBagList do
|
|
33
33
|
@stdout.string.should match /bag_1/
|
34
34
|
@stdout.string.should match /bag_2/
|
35
35
|
end
|
36
|
+
|
37
|
+
context 'with --data-bag-path' do
|
38
|
+
before do
|
39
|
+
@bags_path = '/opt/bags'
|
40
|
+
FileUtils.mkdir_p @bags_path
|
41
|
+
@bags.each { |b| FileUtils.mkdir_p "#{@bags_path}/#{b}-opt" }
|
42
|
+
@knife.config[:data_bag_path] = @bags_path
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should list all of the data bags' do
|
46
|
+
@knife.run
|
47
|
+
@stdout.string.should match /bag_1-opt/
|
48
|
+
@stdout.string.should match /bag_2-opt/
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
end
|
37
53
|
|
38
54
|
end
|
@@ -43,6 +43,22 @@ describe KnifeSoloDataBag::SoloDataBagShow do
|
|
43
43
|
@stdout.string.should match /foo/
|
44
44
|
@stdout.string.should match /bar/
|
45
45
|
end
|
46
|
+
|
47
|
+
context 'with --data-bag-path' do
|
48
|
+
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
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'uses the data bag path from the override' do
|
56
|
+
@knife.run
|
57
|
+
@stdout.string.should match /foo/
|
58
|
+
@stdout.string.should match /bar/
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
46
62
|
end
|
47
63
|
|
48
64
|
context 'when also specifying an item' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-solo_data_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.10.10
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.10
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rake
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 2.10.0
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.10.0
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: fakefs
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: 0.4.0
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.4.0
|
58
78
|
description: A knife plugin for working with data bags and chef solo
|
59
79
|
email:
|
60
80
|
- bishop.thomas@gmail.com
|
@@ -103,15 +123,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
123
|
- - ! '>='
|
104
124
|
- !ruby/object:Gem::Version
|
105
125
|
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: -422012811052713416
|
106
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
130
|
none: false
|
108
131
|
requirements:
|
109
132
|
- - ! '>='
|
110
133
|
- !ruby/object:Gem::Version
|
111
134
|
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -422012811052713416
|
112
138
|
requirements: []
|
113
139
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.24
|
115
141
|
signing_key:
|
116
142
|
specification_version: 3
|
117
143
|
summary: A knife plugin for working with data bags and chef solo
|