-
Notifications
You must be signed in to change notification settings - Fork 65
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 #37849 - Support Rails 7.0 #582
Fixes #37849 - Support Rails 7.0 #582
Conversation
2a9aee9
to
b8ec085
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR doesn't seem to depends on Foreman's one, so it can be merged before that.
Although, still not sure if the changes in routes are OK.
config/routes.rb
Outdated
@@ -95,6 +95,12 @@ | |||
post 'arf_reports/:cname/:policy_id/:date', \ | |||
:constraints => { :cname => /[^\/]+/ }, :to => 'arf_reports#create' | |||
end | |||
|
|||
resources :hosts, :only => [] do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this adds something to API v1, right? To me Rails routes are always this magic thing that I don't understand so can you explain why this change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that the workaround to make the routes be picked up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this adds something to API v1, right?
I don't think so, it's still within the api
namespace, which is defined above: https://github.com/theforeman/foreman_openscap/blob/master/config/routes.rb#L63-L65
Is that the workaround to make the routes be picked up?
Yeap. Still no idea why it started to fail in Rails 7, but without this patch:
With this patch:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's no longer possible to add API routes via Foreman::Application.routes.draw
or does it overwrite all the previously defined API routes? Is that a regression somewhere in our code?
And why isn't that an issue in Foreman itself? https://github.com/theforeman/foreman/blob/develop/config/routes/api/puppet/api/v2.rb appears to use the same code and theforeman/foreman#10299 doesn't change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's no longer possible to add API routes via
Foreman::Application.routes.draw
It's possible, otherwise we'd not have any plugins' routes, I guess?
or does it overwrite all the previously defined API routes? Is that a regression somewhere in our code?
Hard to tell :/ I've spent a lot of time digging through Rails, but couldn't find why it suddenly changed behavior.
https://github.com/theforeman/foreman/blob/develop/config/routes/api/puppet/api/v2.rb appears to use the same code
Unfortunately, not the best example :/ I didn't test that before, so didn't know. I've tried to test that endpoint now, but it's not even usable anymore. I'd say we should nuke that one anyway because it's been 4 years since deprecation? theforeman/foreman#7719 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, not the best example :/ I didn't test that before, so didn't know. I've tried to test that endpoint now, but it's not even usable anymore. I'd say we should nuke that one anyway because it's been 4 years since deprecation? theforeman/foreman#7719 (comment)
I didn't even notice that. I think by now we can safely drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My biggest issue here is that the bit you're adding to still allows v1:
foreman_openscap/config/routes.rb
Lines 63 to 65 in b6c60d6
namespace :api, :defaults => { :format => 'json' } do | |
scope "(:apiv)", :module => :v2, :defaults => { :apiv => 'v2' }, | |
:apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do |
Foreman dropped its v1 API a long time ago so perhaps we can simply only allow v2 there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today we discussed it may not do anything, but https://guides.rubyonrails.org/routing.html#specifying-constraints actually documents exactly what we do here:
By default the :id parameter doesn't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within an :id add a constraint which overrides this - for example id: /[^\/]+/ allows anything except a slash.
So that code is there for FQDN support. I think you should be able to verify it by going to /hosts/host.example.com/policies_enc
. If we don't have a test for it, perhaps write that too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekohl is right, we still must write constraints
, otherwise we won't support host fqdn in the URL :/
I've updated the fix (along with removing v1 support), the issue might actually be in , :only => []
part for resources that we're already introduced. Now it works as expected: no conflicts with core routes (see previous screenshot) and supports host's fqdn.
b8ec085
to
512ccae
Compare
512ccae
to
17d2ba1
Compare
Looks good to me, could you drop the last commit so that we can get it in? |
17d2ba1
to
5f90fc7
Compare
@adamruzicka, sure, done. |
No description provided.