diff options
author | Salim Afiune <afiune@chef.io> | 2016-12-22 10:10:15 -0500 |
---|---|---|
committer | Salim Afiune <afiune@chef.io> | 2016-12-22 12:43:10 -0500 |
commit | 134d02990eeb61ee1f8df124ed726e370cbb0187 (patch) | |
tree | 2d674459e934d00bf7ac8a174b7f48c4ccfdf7ef | |
parent | 1b60195f4cb7ec5414ceb8543fc9a41c1ba4b73b (diff) | |
download | chef-134d02990eeb61ee1f8df124ed726e370cbb0187.tar.gz |
Create a new blank Resource instead of transforming it
Signed-off-by: Salim Afiune <afiune@chef.io>
-rw-r--r-- | lib/chef/resource_reporter.rb | 24 | ||||
-rw-r--r-- | spec/unit/resource_reporter_spec.rb | 12 |
2 files changed, 13 insertions, 23 deletions
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 83787818b8..368e66245f 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -200,30 +200,20 @@ class Chef @pending_update.finish # Verify if the resource has sensitive data + # and create a new blank resource with only + # the name so we can report it back without + # sensitive data if @pending_update.new_resource.sensitive - sensitive_resource = transform_sensitive_resource(@pending_update.new_resource) - @pending_update.new_resource = sensitive_resource + klass = @pending_update.new_resource.class + resource_name = @pending_update.new_resource.name + @pending_update.new_resource = klass.new(resource_name) end + @updated_resources << @pending_update @pending_update = nil end end - def transform_sensitive_resource(resource) - mock_display = '*sensitive*' - - # Every resource has a name - resource.name(mock_display) - # For Execute Resources - resource.command(mock_display) if defined? resource.command - # For File Resources - resource.content(mock_display) if defined? resource.content - # For Template Resources - resource.variables({'data' => mock_display}) if defined? resource.variables - - resource - end - def run_completed(node) @status = "success" post_reporting_data diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index e896aac4d7..ccd7087c0b 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -267,8 +267,8 @@ describe Chef::ResourceReporter do context "when the new_resource is sensitive" do before do - @execute_resource = Chef::Resource::Execute.new("my sensitive execute block") - @execute_resource.name('sensitive-resource') + @execute_resource = Chef::Resource::Execute.new("sensitive-resource") + @execute_resource.name("sensitive-resource") @execute_resource.command('echo "password: SECRET"') @execute_resource.sensitive(true) @resource_reporter.resource_action_start(@execute_resource, :run) @@ -280,12 +280,12 @@ describe Chef::ResourceReporter do @first_update_report = @report["resources"].first end - it "resource_name in prepared_run_data should be transformed" do - expect(@first_update_report["name"]).to eq('*sensitive*') + it "resource_name in prepared_run_data should be the same" do + expect(@first_update_report["name"]).to eq("sensitive-resource") end - it "resource_command in prepared_run_data should be transformed" do - expect(@first_update_report["after"]).to eq({:command=>"*sensitive*"}) + it "resource_command in prepared_run_data should be blank" do + expect(@first_update_report["after"]).to eq({ :command => "sensitive-resource" }) end end |