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

Fixes #34206 - Fix bool params in global registration template #9010

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

stejskalleos
Copy link
Contributor

No description provided.

@theforeman-bot
Copy link
Member

Issues: #34206

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if @param should be normalized in code instead. For example, on line 151 @force is also used but not checked with == 'true'. So it will be inconsistent. Please at least make it consistent, but consider normalizing @force before passing it to the template.

@stejskalleos
Copy link
Contributor Author

Condition on 151th line updated.

I was thinking about normalizing parameters before passing them to the template, but with extensions from plugins (Katello & REX) it would require quite a lot of changes in foreman core and in the plugins. Updating the global reg. template looks like the easiest fix.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slowly starting to get back and I now remembered we also have host_param_true?() which uses Foreman::Cast.to_bool(value). However, I'm not sure if it works since it's really only valid for host params. Do you think this could be used?

I'm worried about the case where it's passed via the API and actually might be a real boolean. Both are specified as real booleans in https://github.com/Katello/katello/blob/8ca9d36efa44b8f2fa0982b066e7483989407fec/app/controllers/katello/concerns/api/v2/registration_commands_controller_extensions.rb#L33-L34 and this patch may cause a regression there.

@stejskalleos
Copy link
Contributor Author

I'm worried about the case where it's passed via the API and actually might be a real boolean. Both are specified as real booleans in app/controllers/katello/concerns/api/v2/registration_commands_controller_extensions.rb#L33-L34 and this patch may cause a regression there.

This is for generating registration command, not for the /register endpoint where we generate the template, so it should not introduce any regression issues

@ekohl
Copy link
Member

ekohl commented Jan 3, 2022

I was thinking about normalizing parameters before passing them to the template, but with extensions from plugins (Katello & REX) it would require quite a lot of changes in foreman core and in the plugins. Updating the global reg. template looks like the easiest fix.

Since the workflow wasn't clear, I had to figure this out myself. Noting it down here for others.

What happens is that a Foreman plugin can declare allowed_registration_vars via extend_allowed_registration_vars:

def extend_allowed_registration_vars(var)
@allowed_registration_vars << var
end

These allowed params are gathered in the controller:

permitted = Foreman::Plugin.all
.map(&:allowed_registration_vars)
.flatten.compact.uniq

The registration controller then filters the params by calling params.permit(permitted):

To properly cast to a bool it would need to modify params which then in turn would probably require the DSL to add casting. That's a non-trivial change.

An alternative would be to introduce a macro to do the comparison. Thinking more about it: perhaps host_param_true? should be generalized. That's a rather large change though.

Having said that, I think this could be OK to go in but I don't want to merge while our test suite is broken. Hopefully #9012 solves that.

@stejskalleos
Copy link
Contributor Author

An alternative would be to introduce a macro to do the comparison.

I thought the same, see #9013

@ezr-ondrej
Copy link
Member

@stejskalleos can you rebase pls, the failures should be fixed

@ezr-ondrej ezr-ondrej self-assigned this Jan 5, 2022
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stejskalleos ! 👍

@ezr-ondrej ezr-ondrej merged commit 7cd74ae into theforeman:develop Jan 5, 2022
@ezr-ondrej ezr-ondrej added the Needs cherrypick This should be cherrypicked to the stable branches or branches label Jan 12, 2022
@ezr-ondrej
Copy link
Member

CP 3.1: 5cb4f6c

@ezr-ondrej ezr-ondrej removed the Needs cherrypick This should be cherrypicked to the stable branches or branches label Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants