provisioners/chef: set `encrypted_data_bag_secret` to `nil` if it's not uploaded

/cc @shanegibbs

Fixes #2984
This commit is contained in:
Teemu Matilainen 2014-02-16 18:14:56 -03:00
parent ad34d474bc
commit eea9c07029
4 changed files with 18 additions and 8 deletions

View File

@ -107,12 +107,12 @@ module VagrantPlugins
end end
def upload_encrypted_data_bag_secret def upload_encrypted_data_bag_secret
return if !@config.encrypted_data_bag_secret_key_path remote_file = guest_encrypted_data_bag_secret_key_path
return if !remote_file
@machine.env.ui.info I18n.t( @machine.env.ui.info I18n.t(
"vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key") "vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
remote_file = guest_encrypted_data_bag_secret_key_path
@machine.communicate.tap do |comm| @machine.communicate.tap do |comm|
comm.sudo("rm -f #{remote_file}", error_check: false) comm.sudo("rm -f #{remote_file}", error_check: false)
comm.upload(encrypted_data_bag_secret_key_path, remote_file) comm.upload(encrypted_data_bag_secret_key_path, remote_file)
@ -120,9 +120,10 @@ module VagrantPlugins
end end
def delete_encrypted_data_bag_secret def delete_encrypted_data_bag_secret
@machine.communicate.sudo( remote_file = guest_encrypted_data_bag_secret_key_path
"rm -f #{guest_encrypted_data_bag_secret_key_path}", if remote_file
error_check: false) @machine.communicate.sudo("rm -f #{remote_file}", error_check: false)
end
end end
def encrypted_data_bag_secret_key_path def encrypted_data_bag_secret_key_path
@ -131,7 +132,9 @@ module VagrantPlugins
end end
def guest_encrypted_data_bag_secret_key_path def guest_encrypted_data_bag_secret_key_path
File.join(@config.provisioning_path, "encrypted_data_bag_secret_key") if @config.encrypted_data_bag_secret_key_path
File.join(@config.provisioning_path, "encrypted_data_bag_secret_key")
end
end end
end end
end end

View File

@ -11,7 +11,7 @@ validation_client_name "<%= validation_client_name %>"
validation_key "<%= validation_key %>" validation_key "<%= validation_key %>"
client_key "<%= client_key %>" client_key "<%= client_key %>"
encrypted_data_bag_secret "<%= encrypted_data_bag_secret %>" encrypted_data_bag_secret <%= encrypted_data_bag_secret.inspect %>
<% if environment %> <% if environment %>
environment "<%= environment %>" environment "<%= environment %>"

View File

@ -10,7 +10,7 @@ role_path <%= roles_path.inspect %>
log_level <%= log_level.inspect %> log_level <%= log_level.inspect %>
verbose_logging <%= verbose_logging.inspect %> verbose_logging <%= verbose_logging.inspect %>
encrypted_data_bag_secret "<%= encrypted_data_bag_secret %>" encrypted_data_bag_secret <%= encrypted_data_bag_secret.inspect %>
<% if data_bags_path -%> <% if data_bags_path -%>
data_bag_path <%= data_bags_path.inspect %> data_bag_path <%= data_bags_path.inspect %>

View File

@ -33,7 +33,14 @@ describe VagrantPlugins::Chef::Provisioner::Base do
end end
describe "#guest_encrypted_data_bag_secret_key_path" do describe "#guest_encrypted_data_bag_secret_key_path" do
it "returns nil if host path is not configured" do
config.stub(:encrypted_data_bag_secret_key_path).and_return(nil)
config.stub(:provisioning_path).and_return("/tmp/foo")
expect(subject.guest_encrypted_data_bag_secret_key_path).to be_nil
end
it "returns path under config.provisioning_path" do it "returns path under config.provisioning_path" do
config.stub(:encrypted_data_bag_secret_key_path).and_return("secret")
config.stub(:provisioning_path).and_return("/tmp/foo") config.stub(:provisioning_path).and_return("/tmp/foo")
expect(File.dirname(subject.guest_encrypted_data_bag_secret_key_path)). expect(File.dirname(subject.guest_encrypted_data_bag_secret_key_path)).
to eq "/tmp/foo" to eq "/tmp/foo"