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 #38241 - Extend userdata API by MAC address endpoint #912

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bastian-src
Copy link

Extend the proxy API to match the userdata API of foreman: theforeman/foreman#9213

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.

Refs #34887

That issue has been closed and already a Fixed in release version that went out so you can't use Refs for that. Please open a new issue.

@bastian-src
Copy link
Author

Thanks a lot for the fast responses! @ekohl

@bastian-src bastian-src changed the title Refs #34887 - userdata proxy should forward MAC address based API Fixes #38241 - Extend userdata API by MAC address endpoint Feb 25, 2025
@bastian-src bastian-src force-pushed the fix/userdata/34887 branch 2 times, most recently from f38d5a1 to 9ec90d9 Compare February 25, 2025 13:01
@bastian-src
Copy link
Author

@ekohl do you have an idea why I gotta define the additional parameter here while it is not needed in the unattended API here?


get "/:mac/:kind" do |mac, kind|
log_halt(500, "Failed to retrieve #{kind} userdata template for #{params.inspect}: ") do
Proxy::Templates::UserdataProxyRequest.new.get([mac, kind], request.env, params)
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the method this feels like an abuse of the API:

Technically it may work since it calls flatten, but I really don't like flatten because it ends up being really unpredictable what gets called.

But that's probably not the real issue. If you look at ProxyRequest you can see it copies the parameters while removing a blacklist:

opts = params.clone.merge(:url => template_url)
BLACKLIST_PARAMETERS.each do |blacklisted_parameter|
opts.delete(blacklisted_parameter)
end

Looking at that blacklist, we can see kind is in there:

BLACKLIST_PARAMETERS = ['path', 'template', 'kind', 'hostgroup', 'splat', 'captures']

I suspect both mac and kind are in params. Not entirely sure what the correct thing to do here, but this whole API feels awkward.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, I see why hostgroup and template don't need to be added in the test - thanks!

However, to make this API feel less awkward I see two improvements currently:

a.) Add another function in UserdataProxyRequest to mitigate the flatten here?
Like a def get_mac and then put the mac as mandatory function parameter? But, this makes it less generic..

b.) Overwrite BLACKLIST_PARAMETERS when inheriting ProxyRequest and add mac there?

What do you think?

Make the Smart Proxy Userdata API endpoint consistent with
the Foreman API which was extended in #34887 (46ca3e70).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants