-
Notifications
You must be signed in to change notification settings - Fork 25
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
(GH-127) Canonicalize enums correctly #131
(GH-127) Canonicalize enums correctly #131
Conversation
Prior to this commit, some enums would be incorrectly canonicalized to the value returned from invoke_get_method; while this is fine for most strings, enums are case sensitive and validated in Puppet. For example, when the result of invoke_get_method returns a value of DWord for an enum of Dword, an error was raised when attempting to canonicalize to the incorrect casing of DWord. This commit: 1. Adds a new enum_attributes method which, like the namevar_attributes and parameter attributes methods, filters the type attributes to return the list of attribute names (as keys); in this case, for any attribute whose data type includes an Enum. 2. Ensures that enums are not erroneously cased to match system state. 3. Includes new unit tests for the canonicalize behavior as well as the new enum_attributes method.
Hi @michaeltlombardi , I'm facing an issue and it seems to be related to this PR. I already add a discussion about this on slack (here : https://puppetcommunity.slack.com/archives/CFD8Z9A4T/p1696342031154069 ) I've had some time to dig into it further and here what I can see. Here is the manifest
Let's focus on
It is an Enum that accepts both PascalCased and downcased values. In my manifest the value
and also
And here is the output concerning the parameter
We can see that the value that is going to be compared is downcased instead using the PascalCased that is actually set. It ends up trying to apply the resource on each run.
If I comment out the call to (I should also mention that the comparison with the empty_string
) I tried a quick fix:
It definitely should be improved but it solves the problem I described and also solves I think the former issue that this PR fixed. Hopefully you'll give me some feedback :) Thanks |
Prior to this PR, some enums would be incorrectly canonicalized to the value returned from
invoke_get_method
; while this is fine for most strings, enums are case sensitive and validated in Puppet. For example, when the result ofinvoke_get_method
returns a value ofDWord
for an enum ofDword
, an error was raised when attempting to canonicalize to the incorrect casing ofDWord
.This PR:
enum_attributes
method which, like thenamevar_attributes
andparameter_attributes
methods, filters the type attributes to return the list of attribute names (as keys); in this case, for any attribute whose data type includes an Enum.canonicalize
behavior as well as the newenum_attributes
method.