@@ -351,7 +351,7 @@ def insync?(context, name, _property_name, _is_hash, should_hash)
351
351
# @param context [Object] the Puppet runtime context to operate in and send feedback to
352
352
# @param name_hash [Hash] the hash of namevars to be passed as properties to `Invoke-DscResource`
353
353
# @return [Hash] returns a hash representing the DSC resource munged to the representation the Puppet Type expects
354
- def invoke_get_method ( context , name_hash )
354
+ def invoke_get_method ( context , name_hash ) # rubocop:disable Metrics/AbcSize
355
355
context . debug ( "retrieving #{ name_hash . inspect } " )
356
356
357
357
query_props = name_hash . select { |k , v | mandatory_get_attributes ( context ) . include? ( k ) || ( k == :dsc_psdscrunascredential && !v . nil? ) }
@@ -394,6 +394,8 @@ def invoke_get_method(context, name_hash)
394
394
# If a resource is found, it's present, so refill this Puppet-only key
395
395
data [ :name ] = name_hash [ :name ]
396
396
397
+ data = stringify_nil_attributes ( context , data )
398
+
397
399
# Have to check for this to avoid a weird canonicalization warning
398
400
# The Resource API calls canonicalize against the current state which
399
401
# will lead to dsc_ensure being set to absent in the name_hash even if
@@ -663,6 +665,20 @@ def mandatory_set_attributes(context)
663
665
context . type . attributes . select { |_attribute , properties | properties [ :mandatory_for_set ] } . keys
664
666
end
665
667
668
+ # Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
669
+ # This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
670
+ # @param context [Object] the Puppet runtime context to operate in and send feedback to
671
+ # @param data [Hash] the hash of properties returned from the DSC resource
672
+ # @return [Hash] returns a data hash with any nil values converted to empty strings
673
+ def stringify_nil_attributes ( context , data )
674
+ nil_strings = data . select { |_name , value | value . nil? } . keys
675
+ string_attrs = context . type . attributes . select { |_name , properties | properties [ :type ] == 'String' } . keys
676
+ string_attrs . each do |attribute |
677
+ data [ attribute ] = '' if nil_strings . include? ( attribute )
678
+ end
679
+ data
680
+ end
681
+
666
682
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as namevars
667
683
#
668
684
# @param context [Object] the Puppet runtime context to operate in and send feedback to
0 commit comments