summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-10 15:10:15 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-10 15:10:15 -0700
commit4184ebc19a60053a59efea1db21664d1aa3bc73a (patch)
tree4964ba42a99dd399a81d8b93ec8903d3c1eae2b6
parent07b7c3aafd0a29b121e5bcc9717b609acd8ae50f (diff)
parent6906af2501eef88ca9f31beb67287a5a840ce43b (diff)
downloadchef-4184ebc19a60053a59efea1db21664d1aa3bc73a.tar.gz
Merge pull request #2013 from nvwls/sensitive-execute
Support sensitive in execute resources.
-rw-r--r--lib/chef/provider/execute.rb5
-rw-r--r--spec/unit/provider/execute_spec.rb28
2 files changed, 25 insertions, 8 deletions
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index d469bea769..54632c0684 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -50,10 +50,11 @@ class Chef
opts[:umask] = @new_resource.umask if @new_resource.umask
opts[:log_level] = :info
opts[:log_tag] = @new_resource.to_s
- if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
+ if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info? && !@new_resource.sensitive
opts[:live_stream] = STDOUT
end
- converge_by("execute #{@new_resource.command}") do
+ description = @new_resource.sensitive ? "sensitive resource" : @new_resource.command
+ converge_by("execute #{description}") do
result = shell_out!(@new_resource.command, opts)
Chef::Log.info("#{@new_resource} ran successfully")
end
diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb
index 78216a89fa..6aa48f1e2a 100644
--- a/spec/unit/provider/execute_spec.rb
+++ b/spec/unit/provider/execute_spec.rb
@@ -36,22 +36,38 @@ describe Chef::Provider::Execute do
STDOUT.stub(:tty?).and_return(true)
end
+ let(:opts) do
+ {
+ timeout: @new_resource.timeout,
+ returns: @new_resource.returns,
+ log_level: :info,
+ log_tag: @new_resource.to_s,
+ live_stream: STDOUT
+ }
+ end
it "should execute foo_resource" do
@provider.stub(:load_current_resource)
- opts = {}
- opts[:timeout] = @new_resource.timeout
- opts[:returns] = @new_resource.returns
- opts[:log_level] = :info
- opts[:log_tag] = @new_resource.to_s
- opts[:live_stream] = STDOUT
@provider.should_receive(:shell_out!).with(@new_resource.command, opts)
+ @provider.should_receive(:converge_by).with("execute foo_resource").and_call_original
Chef::Log.should_not_receive(:warn)
@provider.run_action(:run)
@new_resource.should be_updated
end
+ it "should honor sensitive attribute" do
+ @new_resource.sensitive true
+ @provider = Chef::Provider::Execute.new(@new_resource, @run_context)
+ @provider.stub(:load_current_resource)
+ # Since the resource is sensitive, it should not have :live_stream set
+ @provider.should_receive(:shell_out!).with(@new_resource.command, opts.reject { |k| k == :live_stream })
+ Chef::Log.should_not_receive(:warn)
+ @provider.should_receive(:converge_by).with("execute sensitive resource").and_call_original
+ @provider.run_action(:run)
+ @new_resource.should be_updated
+ end
+
it "should do nothing if the sentinel file exists" do
@provider.stub(:load_current_resource)
File.should_receive(:exists?).with(@new_resource.creates).and_return(true)