Skip to content

Commit

Permalink
(CAT-1724) - Adjust stringify_nil_attrs to include Enum
Browse files Browse the repository at this point in the history
When comparing a resource from manifest that is an empty string
to the value set in the system, we have a mismatch between
empty_string and nil.

Similarly what we done for nil strings, we can extend to nil Enums
returned by DSC,
  • Loading branch information
jordanbreen28 committed Feb 20, 2024
1 parent 8c4a5bb commit c170000
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,16 @@ def mandatory_set_attributes(context)
end

# Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
#
# This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
# @param context [Object] the Puppet runtime context to operate in and send feedback to
# @param data [Hash] the hash of properties returned from the DSC resource
# @return [Hash] returns a data hash with any nil values converted to empty strings
def stringify_nil_attributes(context, data)
nil_strings = data.select { |_name, value| value.nil? }.keys
string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys
string_attrs.each do |attribute|
data[attribute] = '' if nil_strings.include?(attribute)
attributes = context.type.attributes.select { |_name, properties| properties[:type].match?(/^Optional\[(String|Enum)|^(String|Enum)/) }
attributes.each do |name, _properties|
data[name] = '' if nil_strings.include?(name)
end
data
end
Expand Down

0 comments on commit c170000

Please sign in to comment.