Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CAT-2061) Fix empty string nullification #346

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,16 @@ def mandatory_set_attributes(context)
context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
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
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
# This is used to ensure that any nil values are converted to empty strings to match puppets expeceted 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)
nil_attributes = data.select { |_name, value| value.nil? }.keys
nil_attributes.each do |nil_attr|
attribute_type = context.type.attributes[nil_attr][:type]
data[nil_attr] = '' if (attribute_type.start_with?('Optional[Enum[', 'Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
end
data
end
Expand Down