puppet-horizon/lib/puppet/functions/validate_available_themes.rb
Takashi Kajinami 5a3245f9d4 Require valid type for available_themses
Currently, if a users gives invalid input type for available_themses,
the logic ignores the input and reflect nothing in the config file,
which can cause unexpected results. This ensures the given input is
a hash value.

This also adds validations to ensure only required values are included
by the hash.

Change-Id: I61aefe65e6218a79dce7a0633cb0ceb13b0021b4
2024-01-10 15:42:02 +00:00

16 lines
479 B
Ruby

Puppet::Functions.create_function(:validate_available_themes) do
def validate_available_themes(themes)
req_keys = Set.new(['name', 'label', 'path'])
themes.each do |theme|
if theme.keys.to_set != req_keys
if theme.keys.to_set.subset?(req_keys)
raise Puppet::Error, "Some of the required keys (name, label and path) are missing"
else
raise Puppet::Error, "Unsupported keys are detected"
end
end
end
end
end