@@ -794,7 +794,7 @@ def prepare_credentials(resource)
794
794
variable_name = random_variable_name
795
795
credential_hash = {
796
796
'user' => property_hash [ :value ] [ 'user' ] ,
797
- 'password' => escape_quotes ( property_hash [ :value ] [ 'password' ] . unwrap )
797
+ 'password' => escape_quotes ( unwrap_string ( property_hash [ :value ] [ 'password' ] ) )
798
798
}
799
799
credentials_block << format_pscredential ( variable_name , credential_hash )
800
800
instantiated_variables . merge! ( variable_name => credential_hash )
@@ -899,7 +899,7 @@ def format_ciminstance(variable_name, class_name, property_hash)
899
899
#
900
900
# @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
901
901
# @return [String] A string representing the PowerShell definition of the InvokeParams hash
902
- def invoke_params ( resource )
902
+ def invoke_params ( resource ) # rubocop:disable Metrics/MethodLength
903
903
params = {
904
904
Name : resource [ :dscmeta_resource_friendly_name ] ,
905
905
Method : resource [ :dsc_invoke_method ] ,
@@ -917,6 +917,10 @@ def invoke_params(resource)
917
917
params [ :ModuleName ] = resource [ :dscmeta_module_name ]
918
918
end
919
919
resource [ :parameters ] . each do |property_name , property_hash |
920
+ # ignore dsc_timeout, since it is only used to specify the powershell command timeout
921
+ # and timeout itself is not a parameter to the DSC resource
922
+ next if property_name == :dsc_timeout
923
+
920
924
# strip dsc_ from the beginning of the property name declaration
921
925
name = property_name . to_s . gsub ( /^dsc_/ , '' ) . to_sym
922
926
params [ :Property ] [ name ] = case property_hash [ :mof_type ]
@@ -925,7 +929,7 @@ def invoke_params(resource)
925
929
# the Credential hash interpolable as it will be replaced by a variable reference.
926
930
{
927
931
'user' => property_hash [ :value ] [ 'user' ] ,
928
- 'password' => escape_quotes ( property_hash [ :value ] [ 'password' ] . unwrap )
932
+ 'password' => escape_quotes ( unwrap_string ( property_hash [ :value ] [ 'password' ] ) )
929
933
}
930
934
when 'DateTime'
931
935
# These have to be handled specifically because they rely on the *Puppet* DateTime,
@@ -1018,6 +1022,31 @@ def unwrap(value)
1018
1022
end
1019
1023
end
1020
1024
1025
+ # Unwrap sensitive strings and handle string
1026
+ #
1027
+ # @param value [Object] The object to unwrap sensitive data inside of
1028
+ # @return [Object] The object with any sensitive strings unwrapped
1029
+ def unwrap_string ( value )
1030
+ case value
1031
+ when Puppet ::Pops ::Types ::PSensitiveType ::Sensitive
1032
+ value . unwrap
1033
+ when Hash
1034
+ unwrapped = { }
1035
+ value . each do |k , v |
1036
+ unwrapped [ k ] = unwrap_string ( v )
1037
+ end
1038
+ unwrapped
1039
+ when Array
1040
+ unwrapped = [ ]
1041
+ value . each do |v |
1042
+ unwrapped << unwrap_string ( v )
1043
+ end
1044
+ unwrapped
1045
+ else
1046
+ value
1047
+ end
1048
+ end
1049
+
1021
1050
# Escape any nested single quotes in a Sensitive string
1022
1051
#
1023
1052
# @param text [String] the text to escape
0 commit comments