diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-11-23 14:11:08 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-11-23 15:56:05 -0800 |
commit | 675634fa5c314ed00859ddf78bfc31428dde002d (patch) | |
tree | 0f85b648d1bebc303f116c15ebeac289aa82d3c5 /lib/chef | |
parent | 2fe875ce8d38631bf9b5975ff3f3cf5b532be2bd (diff) | |
download | chef-675634fa5c314ed00859ddf78bfc31428dde002d.tar.gz |
Prevent inspect on PsCredential from printing out plain text passwordjdm/dont-print-pscred
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/resource/dsc_resource.rb | 22 | ||||
-rw-r--r-- | lib/chef/util/powershell/ps_credential.rb | 5 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index b6167e76d0..1dcde8de96 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -20,16 +20,34 @@ require 'chef/dsl/powershell' class Chef
class Resource
class DscResource < Chef::Resource
-
provides :dsc_resource, os: "windows"
+ # This class will check if the object responds to
+ # to_text. If it does, it will call that as opposed
+ # to inspect. This is useful for properties that hold
+ # objects such as PsCredential, where we do not want
+ # to dump the actual ivars
+ class ToTextHash < Hash
+ def to_text
+ descriptions = self.map do |(property, obj)|
+ obj_text = if obj.respond_to?(:to_text)
+ obj.to_text
+ else
+ obj.inspect
+ end
+ "#{property}=>#{obj_text}"
+ end
+ "{#{descriptions.join(', ')}}"
+ end
+ end
+
include Chef::DSL::Powershell
default_action :run
def initialize(name, run_context)
super
- @properties = {}
+ @properties = ToTextHash.new
@resource = nil
@reboot_action = :nothing
end
diff --git a/lib/chef/util/powershell/ps_credential.rb b/lib/chef/util/powershell/ps_credential.rb index 3f4558a77c..2fc0650e5f 100644 --- a/lib/chef/util/powershell/ps_credential.rb +++ b/lib/chef/util/powershell/ps_credential.rb @@ -29,9 +29,8 @@ class Chef::Util::Powershell "New-Object System.Management.Automation.PSCredential('#{@username}',('#{encrypt(@password)}' | ConvertTo-SecureString))" end - def to_s - to_psobject - end + alias to_s to_psobject + alias to_text to_psobject private |