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
Add ability to have proxy rewrite API_ROOT w/ header #5013
base: main
Are you sure you want to change the base?
Conversation
@@ -1254,8 +1254,7 @@ class RepositoryVersionContentDetails(models.Model): | |||
) | |||
count = models.IntegerField() | |||
|
|||
@property | |||
def content_href(self): | |||
def get_content_href(self, request=None): |
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 always feels like request
would be the perfect candidate for a context var...
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.
Do you think I should do so in this PR?
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.
I am a little worried that we are changing a public interface here. But is this class actually public?
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.
The interface isn't changed though, further down I re-create the content_href
property and have it call this "new" method.
@@ -1254,8 +1254,7 @@ class RepositoryVersionContentDetails(models.Model): | |||
) | |||
count = models.IntegerField() | |||
|
|||
@property | |||
def content_href(self): | |||
def get_content_href(self, request=None): |
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.
I am a little worried that we are changing a public interface here. But is this class actually public?
pulpcore/app/path_api_urls.py
Outdated
PATH_API_ROOT = "<path:api_root>/" + API_ROOT.split(settings.API_ROOT[1:])[1] | ||
dup_urls = special_views + docs_and_status | ||
for router in all_routers: | ||
dup_urls.extend(router.urls) |
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.
Do we really need to dupe the url patterns? Can't we just also handle the default paths with the global match pattern?
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.
Also do plugins with individual urlpattern opt into this? Do we get the whole "domain enabled" story all over again?
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.
Now using a global pattern placed into V3_API_ROOT
. Plugins that use this for extending their urlpatterns will automatically get support for this feature.
pulpcore/app/serializers/base.py
Outdated
self.reverse = _reverse(self.reverse, request, obj) | ||
return super().get_url(obj, view_name, None, *args, **kwargs) | ||
# Use the Pulp reverse method to display relative hrefs. | ||
self.reverse = reverse |
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.
At least some consolidating codepaths. ;)
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.
Might have to change this back to a patched reverse (albeit using our new Pulp reverse). The tests are failing because super().get_url
doesn't accept kwargs to pass onto reverse
, so the domain can't be specified. For serializing fields we need to know if the object has a domain relationship to use the correct domain name, the requests domain is not good enough.
@@ -113,6 +114,7 @@ | |||
"django.contrib.messages.middleware.MessageMiddleware", | |||
"django.middleware.clickjacking.XFrameOptionsMiddleware", | |||
"pulpcore.middleware.DomainMiddleware", | |||
"pulpcore.middleware.APIRootRewriteMiddleware", |
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.
Didn't you only want to include this when configured?
I saw the raising of MiddlewareNotUsed.
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.
It's part of django's middelware api: https://docs.djangoproject.com/en/5.0/topics/http/middleware/#marking-middleware-as-unused. You list it here and then on launch the middleware's init will determine if it should be used or not.
c28b04d
to
a9c3bcb
Compare
bfe1c84
to
89bc79e
Compare
@@ -126,7 +126,7 @@ if [ "$TEST" = "azure" ]; then | |||
- ./azurite:/etc/pulp\ | |||
command: "azurite-blob --blobHost 0.0.0.0 --cert /etc/pulp/azcert.pem --key /etc/pulp/azkey.pem"' vars/main.yaml | |||
sed -i -e '$a azure_test: true\ | |||
pulp_scenario_settings: {"domain_enabled": true}\ | |||
pulp_scenario_settings: {"api_root_rewrite_header": "X-API-Root", "domain_enabled": true}\ |
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.
Just wondering, can we infer the original relative path the user sent this request to from the request object?
Or is there some apache/nginx rewrite we going on we cannot see anymore?
(I was wondering, because drf used to use the request object to create uris, where we dumbed it down to do hrefs.)
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.
Don't think so, unless the reverse proxy sends along that info inside some header we are completely clueless where the original path came from.
d2e8f2f
to
3fcde86
Compare
a2745ad
to
ba404f7
Compare
[noissue]
if [ "$TEST" = "azure" ]; then | ||
cmd_stdin_prefix bash -c "cat > /etc/nginx/pulp/api_root_rewrite.conf" < pulpcore/tests/functional/assets/api_root_rewrite.conf |
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 this related to your recent oci images change with a templated nginx config?
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.
No it is not.
@newswangerd If you have any free time would love to hear feedback on the design of this feature and if it accomplishes what you need. |
fixes: #4207