knife-hitori 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/hitori/version.rb +1 -1
- data/lib/chef/knife/hitori_base.rb +11 -0
- data/lib/chef/knife/hitori_bootstrap.rb +1 -0
- data/lib/chef/knife/hitori_cook.rb +23 -51
- data/lib/chef/knife/hitori_data_bag_dec.rb +3 -0
- data/lib/chef/knife/hitori_data_bag_enc.rb +11 -1
- data/lib/chef/knife/hitori_file_dec.rb +65 -0
- data/lib/chef/knife/hitori_file_enc.rb +64 -0
- data/lib/chef/knife/hitori_key_create.rb +36 -0
- data/lib/chef/knife/hitori_prepare.rb +1 -0
- data/lib/knife-hitori/lib/crypt_util.rb +22 -0
- data/lib/knife-hitori/resources/do_cook.sh +2 -0
- data/lib/knife-hitori/resources/knife.erb +5 -0
- data/spec/knife/hitori_base_spec.rb +29 -0
- data/spec/knife/hitori_config_spec.rb +1 -0
- data/spec/knife/hitori_cook_spec.rb +21 -43
- data/spec/knife/hitori_data_bag_dec_spec.rb +31 -0
- data/spec/knife/hitori_data_bag_enc_spec.rb +50 -0
- data/spec/knife/hitori_prepare_spec.rb +1 -0
- metadata +12 -2
@@ -6,6 +6,17 @@ require 'knife-hitori'
|
|
6
6
|
class Chef
|
7
7
|
class Knife
|
8
8
|
module HitoriBase
|
9
|
+
def update_environment(env)
|
10
|
+
Chef::Config[:environment] = nil
|
11
|
+
Chef::Config[:solo_environment] = env
|
12
|
+
%w(data_bag_path settings_path encrypted_data_bag_secret).each do |name|
|
13
|
+
name = name.to_sym
|
14
|
+
tpl_name = "#{name}_tpl".to_sym
|
15
|
+
if Chef::Config[tpl_name]
|
16
|
+
Chef::Config[name] = sprintf(Chef::Config[tpl_name], env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -17,10 +17,6 @@ class Chef
|
|
17
17
|
require 'fog'
|
18
18
|
end
|
19
19
|
|
20
|
-
option :local,
|
21
|
-
:long => '--local',
|
22
|
-
:description => 'run chef-solo locally'
|
23
|
-
|
24
20
|
option :install_chef,
|
25
21
|
:long => '--install-chef',
|
26
22
|
:description => 'Install chef before run cookbook. This process usually have done by hitori-prepare.'
|
@@ -46,55 +42,32 @@ class Chef
|
|
46
42
|
:description => 'specify a server by Public IP Address'
|
47
43
|
|
48
44
|
def run
|
49
|
-
if config[:local]
|
50
|
-
run_local
|
51
|
-
else
|
52
|
-
run_remote
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def run_local
|
57
|
-
Chef::Config[:environment] = nil
|
58
45
|
update_environment(config[:environment]) if config[:environment]
|
59
|
-
|
60
|
-
@chef_solo = Chef::Client.new(json_attrs)
|
61
|
-
@chef_solo.run
|
62
|
-
end
|
63
|
-
|
64
|
-
def update_environment(env)
|
65
|
-
Chef::Config[:solo_environment] = env
|
66
|
-
%w(data_bag_path settings_path encrypted_data_bag_secret).each do |name|
|
67
|
-
name = name.to_sym
|
68
|
-
tpl_name = "#{name}_tpl".to_sym
|
69
|
-
if Chef::Config[tpl_name]
|
70
|
-
Chef::Config[name] = sprintf(Chef::Config[tpl_name], env)
|
71
|
-
end
|
72
|
-
end
|
46
|
+
run_remote
|
73
47
|
end
|
74
48
|
|
75
|
-
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
49
|
+
## @return [Hash]
|
50
|
+
#def json_attrs
|
51
|
+
# attrs = load_settings || {}
|
52
|
+
# # Chef::Mixin::DeepMerge.merge(normal_attrs,normal_attrs_to_merge)
|
53
|
+
#
|
54
|
+
# # Update run_list
|
55
|
+
# run_list = new_run_list
|
56
|
+
# unless run_list.empty?
|
57
|
+
# attrs['run_list'] = run_list
|
58
|
+
# end
|
59
|
+
# #
|
60
|
+
# attrs
|
61
|
+
#end
|
62
|
+
#
|
63
|
+
#def load_settings
|
64
|
+
# path = Chef::Config[:settings_path]
|
65
|
+
# if ::File.exists?(path)
|
66
|
+
# return JSON.parse(::File.read(path))
|
67
|
+
# end
|
68
|
+
# ui.warn "#{path} is not found!!" if path
|
69
|
+
# {}
|
70
|
+
#end
|
98
71
|
|
99
72
|
def new_run_list
|
100
73
|
run_list = []
|
@@ -103,7 +76,6 @@ class Chef
|
|
103
76
|
run_list
|
104
77
|
end
|
105
78
|
|
106
|
-
|
107
79
|
#########################################################
|
108
80
|
########################################################
|
109
81
|
def run_remote(server_list=nil)
|
@@ -13,6 +13,7 @@ class Chef
|
|
13
13
|
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
14
14
|
|
15
15
|
def run
|
16
|
+
update_environment(config[:environment]) if config[:environment]
|
16
17
|
config[:bag], config[:item] = @name_args
|
17
18
|
exit 1 unless validate
|
18
19
|
|
@@ -20,7 +21,9 @@ class Chef
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def decrypt_data_bag
|
24
|
+
ui.info ui.color("Use SECRET_FILE '#{secret_file_path}'", :green)
|
23
25
|
secret = Chef::EncryptedDataBagItem.load_secret(secret_file_path)
|
26
|
+
ui.info ui.color("Decrypt DataBag #{Chef::Config[:data_bag_path]}/#{config[:bag]}/#{config[:item]}.json", :green)
|
24
27
|
spr_creds = Chef::EncryptedDataBagItem.load(config[:bag], config[:item], secret)
|
25
28
|
puts JSON.pretty_generate(spr_creds.to_hash)
|
26
29
|
end
|
@@ -5,7 +5,7 @@ require 'chef/knife/hitori_base'
|
|
5
5
|
class Chef
|
6
6
|
class Knife
|
7
7
|
class HitoriDataBagEnc < Knife
|
8
|
-
banner 'knife hitori data bag enc BAG ITEM (options)'
|
8
|
+
banner 'knife hitori data bag enc BAG ITEM -j JSON_FILE (options)'
|
9
9
|
include HitoriBase
|
10
10
|
|
11
11
|
option :json_file,
|
@@ -17,6 +17,7 @@ class Chef
|
|
17
17
|
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
18
18
|
|
19
19
|
def run
|
20
|
+
update_environment(config[:environment]) if config[:environment]
|
20
21
|
config[:bag], config[:item] = @name_args
|
21
22
|
exit 1 unless validate
|
22
23
|
|
@@ -27,6 +28,7 @@ class Chef
|
|
27
28
|
data_bag_path = Chef::Config[:data_bag_path]
|
28
29
|
secret = Chef::EncryptedDataBagItem.load_secret(secret_file_path)
|
29
30
|
data = JSON.parse(File.read(config[:json_file]))
|
31
|
+
exit 1 unless check_data(data)
|
30
32
|
encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)
|
31
33
|
bag_dir = "#{data_bag_path}/#{config[:bag]}"
|
32
34
|
FileUtils.mkpath(bag_dir)
|
@@ -35,6 +37,14 @@ class Chef
|
|
35
37
|
ui.info ui.color("Created encrypted data bag item at #{write_path}", :green)
|
36
38
|
end
|
37
39
|
|
40
|
+
def check_data(data)
|
41
|
+
unless data['id'] == config[:item]
|
42
|
+
ui.error ui.color(%Q|ITEM=#{config[:item]} must have {"id": "#{config[:item]}"}, but #{config[:json_file]} does not.|)
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
|
38
48
|
def secret_file_path
|
39
49
|
config[:secret_file] || Chef::Config[:encrypted_data_bag_secret]
|
40
50
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'chef/knife/hitori_base'
|
4
|
+
require 'knife-hitori/lib/crypt_util'
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Knife
|
8
|
+
class HitoriFileDec < Knife
|
9
|
+
banner 'knife hitori file dec -i IN_FILE -o OUT_FILE (options)'
|
10
|
+
include HitoriBase
|
11
|
+
include KnifeHitori::CryptUtil
|
12
|
+
|
13
|
+
option :in_file,
|
14
|
+
:short => '-i IN_FILE',
|
15
|
+
:description => 'A file for decryption'
|
16
|
+
|
17
|
+
option :out_file,
|
18
|
+
:short => '-o OUT_FILE',
|
19
|
+
:description => 'A file for store decrypted file'
|
20
|
+
|
21
|
+
option :secret_file,
|
22
|
+
:long => '--secret-file SECRET_FILE',
|
23
|
+
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
24
|
+
|
25
|
+
def run
|
26
|
+
update_environment(config[:environment]) if config[:environment]
|
27
|
+
exit 1 unless validate
|
28
|
+
|
29
|
+
secret = Chef::EncryptedDataBagItem.load_secret(secret_file_path)
|
30
|
+
data = File.read(config[:in_file])
|
31
|
+
File.write(config[:out_file], decrypt(JSON.parse(data), secret))
|
32
|
+
ui.info ui.color("Saved in #{config[:out_file]}", :green)
|
33
|
+
end
|
34
|
+
|
35
|
+
def secret_file_path
|
36
|
+
config[:secret_file] || Chef::Config[:encrypted_data_bag_secret]
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate
|
40
|
+
unless config[:in_file]
|
41
|
+
ui.error '-i IN_FILE must be specified'
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
|
45
|
+
unless ::File.exists?(config[:in_file])
|
46
|
+
ui.error "IN_FILE: #{config[:in_file]} not found"
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
unless config[:out_file]
|
51
|
+
ui.error '-o OUT_FILE must be specified'
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
|
55
|
+
unless ::File.exists?(secret_file_path)
|
56
|
+
ui.error 'No secret key file is found.'
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'chef/knife/hitori_base'
|
4
|
+
require 'knife-hitori/lib/crypt_util'
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Knife
|
8
|
+
class HitoriFileEnc < Knife
|
9
|
+
banner 'knife hitori file enc -i IN_FILE -o OUT_FILE (options)'
|
10
|
+
include HitoriBase
|
11
|
+
include KnifeHitori::CryptUtil
|
12
|
+
|
13
|
+
option :in_file,
|
14
|
+
:short => '-i IN_FILE',
|
15
|
+
:description => 'A file for encryption'
|
16
|
+
|
17
|
+
option :out_file,
|
18
|
+
:short => '-o OUT_FILE',
|
19
|
+
:description => 'A file for store encrypted file'
|
20
|
+
|
21
|
+
option :secret_file,
|
22
|
+
:long => '--secret-file SECRET_FILE',
|
23
|
+
:description => 'A file containing the secret key to use to encrypt data bag item values'
|
24
|
+
|
25
|
+
def run
|
26
|
+
update_environment(config[:environment]) if config[:environment]
|
27
|
+
exit 1 unless validate
|
28
|
+
|
29
|
+
secret = Chef::EncryptedDataBagItem.load_secret(secret_file_path)
|
30
|
+
data = File.read(config[:in_file])
|
31
|
+
File.write(config[:out_file], JSON.dump(encrypt(data, secret)))
|
32
|
+
ui.info ui.color("Saved in #{config[:out_file]}", :green)
|
33
|
+
end
|
34
|
+
|
35
|
+
def secret_file_path
|
36
|
+
config[:secret_file] || Chef::Config[:encrypted_data_bag_secret]
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate
|
40
|
+
unless config[:in_file]
|
41
|
+
ui.error '-i IN_FILE must be specified'
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
|
45
|
+
unless ::File.exists?(config[:in_file])
|
46
|
+
ui.error "IN_FILE: #{config[:in_file]} not found"
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
unless config[:out_file]
|
51
|
+
ui.error '-o OUT_FILE must be specified'
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
|
55
|
+
unless ::File.exists?(secret_file_path)
|
56
|
+
ui.error 'No secret key file is found. Please "knife hitori key create" first.'
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
return true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'chef/knife/hitori_base'
|
4
|
+
|
5
|
+
class Chef
|
6
|
+
class Knife
|
7
|
+
class HitoriKeyCreate < Knife
|
8
|
+
banner 'knife hitori key create (options)'
|
9
|
+
include HitoriBase
|
10
|
+
|
11
|
+
def run
|
12
|
+
update_environment(config[:environment]) if config[:environment]
|
13
|
+
create_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_key
|
17
|
+
secret_file_path = Chef::Config[:encrypted_data_bag_secret]
|
18
|
+
if ::File.exists?(secret_file_path)
|
19
|
+
yes = ui.confirm("#{secret_file_path} already exists.\nOVERWRITE this?")
|
20
|
+
return unless yes
|
21
|
+
end
|
22
|
+
do_create_key(secret_file_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_create_key(secret_file_path)
|
26
|
+
FileUtils.mkpath(::File.dirname(secret_file_path))
|
27
|
+
key = [OpenSSL::Random.random_bytes(512)].pack('m0')
|
28
|
+
data = (1..key.size/64).inject(key) {|x,i| x.insert(i*64+i-1, "\n")} + "\n"
|
29
|
+
::File.write(secret_file_path, data)
|
30
|
+
ui.info ui.color("save secret key to #{secret_file_path}", :green)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module KnifeHitori
|
4
|
+
module CryptUtil
|
5
|
+
require 'chef/encrypted_data_bag_item'
|
6
|
+
|
7
|
+
# @param [Hash] data
|
8
|
+
# @param [String] secret
|
9
|
+
# @return [String]
|
10
|
+
def decrypt(data, secret)
|
11
|
+
Chef::EncryptedDataBagItem::Decryptor.for(data, secret.strip).for_decrypted_item
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [String] data
|
15
|
+
# @param [String] secret
|
16
|
+
# @return [Hash]
|
17
|
+
def encrypt(data, secret)
|
18
|
+
Chef::EncryptedDataBagItem::Encryptor.new(data, secret.strip).for_encrypted_item
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
require 'chef/knife/hitori_base'
|
8
|
+
|
9
|
+
|
10
|
+
describe 'hitori_base' do
|
11
|
+
before do
|
12
|
+
@obj = Object.new
|
13
|
+
@obj.extend Chef::Knife::HitoriBase
|
14
|
+
end
|
15
|
+
|
16
|
+
describe :update_environment do
|
17
|
+
before(:each) do
|
18
|
+
Chef::Config[:data_bag_path_tpl] = 'databag/%s'
|
19
|
+
Chef::Config[:settings_path_tpl] = 'settings/%s'
|
20
|
+
Chef::Config[:encrypted_data_bag_secret_tpl] = 'enc/%s'
|
21
|
+
@obj.update_environment('my_env')
|
22
|
+
end
|
23
|
+
|
24
|
+
subject {Chef::Config}
|
25
|
+
its(:data_bag_path) {should == 'databag/my_env'}
|
26
|
+
its(:settings_path) {should == 'settings/my_env'}
|
27
|
+
its(:encrypted_data_bag_secret) {should == 'enc/my_env'}
|
28
|
+
end
|
29
|
+
end
|
@@ -30,30 +30,12 @@ describe 'hitori_cook' do
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
-
it 'should call
|
34
|
-
@obj.should_receive(:run_local)
|
35
|
-
@obj.config[:local] = true
|
36
|
-
@obj.run
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should call run_remote if not config[:local]' do
|
33
|
+
it 'should call run_remote' do
|
40
34
|
@obj.should_receive(:run_remote)
|
41
|
-
@obj.config[:local] = nil
|
42
35
|
@obj.run
|
43
36
|
end
|
44
37
|
end
|
45
38
|
|
46
|
-
describe :run_local do
|
47
|
-
it 'should call ChefClient.run' do
|
48
|
-
@obj.config[:environment] = nil
|
49
|
-
chef_client = double('chef_client')
|
50
|
-
Chef::Client.should_receive(:new).with({json: 'attrs'}).and_return(chef_client)
|
51
|
-
@obj.stub(:json_attrs => {json: 'attrs'})
|
52
|
-
chef_client.should_receive(:run)
|
53
|
-
@obj.run_local
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
39
|
describe :update_environment do
|
58
40
|
before(:each) do
|
59
41
|
Chef::Config[:data_bag_path_tpl] = 'databag/%s'
|
@@ -68,26 +50,26 @@ describe 'hitori_cook' do
|
|
68
50
|
its(:encrypted_data_bag_secret) {should == 'enc/my_env'}
|
69
51
|
end
|
70
52
|
|
71
|
-
describe :json_attrs do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
53
|
+
#describe :json_attrs do
|
54
|
+
# before() do
|
55
|
+
# @data = {'my' => 'data', 'run_list' => 'role[magic]'}
|
56
|
+
# temp = Tempfile.open('hitori-')
|
57
|
+
# Chef::Config[:settings_path] = temp.path
|
58
|
+
# temp.write JSON.dump(@data)
|
59
|
+
# temp.close
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# it 'should return json data of Config[:settings_path]' do
|
63
|
+
# @obj.json_attrs.should == @data
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# it 'should update run_list if options is specified' do
|
67
|
+
# @obj.config[:recipes] = 'cat'
|
68
|
+
# @obj.config[:roles] = 'dog'
|
69
|
+
# ret = @obj.json_attrs
|
70
|
+
# ret['run_list'].sort.should == %w(recipe[cat] role[dog]).sort
|
71
|
+
# end
|
72
|
+
#end
|
91
73
|
|
92
74
|
describe :new_run_list do
|
93
75
|
before(:each) do
|
@@ -167,8 +149,4 @@ describe 'hitori_cook' do
|
|
167
149
|
ret.should == nil
|
168
150
|
end
|
169
151
|
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
152
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'chef/knife/hitori_data_bag_dec'
|
4
|
+
|
5
|
+
describe 'HitoriDataBagDec' do
|
6
|
+
before do
|
7
|
+
Chef::Knife::HitoriDataBagDec.load_deps
|
8
|
+
@obj = Chef::Knife::HitoriDataBagDec.new
|
9
|
+
@obj.name_args = %w(MY_BAG MY_ITEM)
|
10
|
+
Chef::Config[:encrypted_data_bag_secret] = '/tmp/enc.key'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe :run do
|
14
|
+
it 'should call update_environment' do
|
15
|
+
@obj.config[:environment] = 'apple'
|
16
|
+
@obj.should_receive(:update_environment).with('apple')
|
17
|
+
common_run
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not call update_environment' do
|
21
|
+
@obj.config[:environment] = nil
|
22
|
+
@obj.should_not_receive(:update_environment)
|
23
|
+
common_run
|
24
|
+
end
|
25
|
+
|
26
|
+
def common_run
|
27
|
+
@obj.should_receive(:decrypt_data_bag)
|
28
|
+
@obj.run
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'chef/knife/hitori_data_bag_enc'
|
4
|
+
|
5
|
+
describe 'HitoriDataBagEnc' do
|
6
|
+
before do
|
7
|
+
Chef::Knife::HitoriDataBagEnc.load_deps
|
8
|
+
@obj = Chef::Knife::HitoriDataBagEnc.new
|
9
|
+
@obj.name_args = %w(MY_BAG MY_ITEM)
|
10
|
+
@obj.config[:json_file] = 'my.json'
|
11
|
+
Chef::Config[:encrypted_data_bag_secret] = '/tmp/enc.key'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :run do
|
15
|
+
it 'should call update_environment if config[:environment]' do
|
16
|
+
@obj.config[:environment] = 'apple'
|
17
|
+
@obj.should_receive(:update_environment).with('apple')
|
18
|
+
common_run
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should not call update_environment if not config[:environment]' do
|
22
|
+
@obj.config[:environment] = nil
|
23
|
+
@obj.should_not_receive(:update_environment)
|
24
|
+
common_run
|
25
|
+
end
|
26
|
+
|
27
|
+
def common_run
|
28
|
+
@obj.should_receive(:create_data_bag)
|
29
|
+
@obj.run
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe :create_data_bag do
|
34
|
+
it 'should write encrypted data to specific path' do
|
35
|
+
@obj.config[:bag], @obj.config[:item] = @obj.name_args
|
36
|
+
Chef::Config[:data_bag_path] = '/tmp/data_bag'
|
37
|
+
Chef::EncryptedDataBagItem.should_receive(:load_secret) {'sec'}
|
38
|
+
File.should_receive(:read).with(@obj.config[:json_file]) {'{"a": 9}'}
|
39
|
+
@obj.should_receive(:check_data).and_return(true)
|
40
|
+
Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item) {
|
41
|
+
enc_data = double('enc_data')
|
42
|
+
enc_data.should_receive(:to_json) {'enc_to_json'}
|
43
|
+
enc_data
|
44
|
+
}
|
45
|
+
File.should_receive(:write).with('/tmp/data_bag/MY_BAG/MY_ITEM.json', 'enc_to_json')
|
46
|
+
@obj.create_data_bag
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-hitori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -128,9 +128,13 @@ files:
|
|
128
128
|
- lib/chef/knife/hitori_cook.rb
|
129
129
|
- lib/chef/knife/hitori_data_bag_dec.rb
|
130
130
|
- lib/chef/knife/hitori_data_bag_enc.rb
|
131
|
+
- lib/chef/knife/hitori_file_dec.rb
|
132
|
+
- lib/chef/knife/hitori_file_enc.rb
|
131
133
|
- lib/chef/knife/hitori_hello.rb
|
134
|
+
- lib/chef/knife/hitori_key_create.rb
|
132
135
|
- lib/chef/knife/hitori_prepare.rb
|
133
136
|
- lib/knife-hitori.rb
|
137
|
+
- lib/knife-hitori/lib/crypt_util.rb
|
134
138
|
- lib/knife-hitori/lib/interactive_configure.rb
|
135
139
|
- lib/knife-hitori/lib/run_remote_cook.rb
|
136
140
|
- lib/knife-hitori/resources/centos_bootstrap.erb
|
@@ -142,9 +146,12 @@ files:
|
|
142
146
|
- refs/run_chef_solo.sh
|
143
147
|
- refs/util/create_encrypt_databag.rb
|
144
148
|
- refs/util/crypt_file.rb
|
149
|
+
- spec/knife/hitori_base_spec.rb
|
145
150
|
- spec/knife/hitori_bootstrap_spec.rb
|
146
151
|
- spec/knife/hitori_config_spec.rb
|
147
152
|
- spec/knife/hitori_cook_spec.rb
|
153
|
+
- spec/knife/hitori_data_bag_dec_spec.rb
|
154
|
+
- spec/knife/hitori_data_bag_enc_spec.rb
|
148
155
|
- spec/knife/hitori_hello_spec.rb
|
149
156
|
- spec/knife/hitori_prepare_spec.rb
|
150
157
|
- spec/spec_helper.rb
|
@@ -174,9 +181,12 @@ signing_key:
|
|
174
181
|
specification_version: 3
|
175
182
|
summary: knife subcommand
|
176
183
|
test_files:
|
184
|
+
- spec/knife/hitori_base_spec.rb
|
177
185
|
- spec/knife/hitori_bootstrap_spec.rb
|
178
186
|
- spec/knife/hitori_config_spec.rb
|
179
187
|
- spec/knife/hitori_cook_spec.rb
|
188
|
+
- spec/knife/hitori_data_bag_dec_spec.rb
|
189
|
+
- spec/knife/hitori_data_bag_enc_spec.rb
|
180
190
|
- spec/knife/hitori_hello_spec.rb
|
181
191
|
- spec/knife/hitori_prepare_spec.rb
|
182
192
|
- spec/spec_helper.rb
|