-
Notifications
You must be signed in to change notification settings - Fork 106
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
set -euv | ||
|
||
|
||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. No it is not. |
||
cmd_prefix bash -c "s6-rc -d change nginx" | ||
cmd_prefix bash -c "s6-rc -u change nginx" | ||
cmd_stdin_prefix bash -c "cat > /var/lib/pulp/scripts/otel_server.py" < pulpcore/tests/functional/assets/otel_server.py | ||
cmd_user_prefix nohup python3 /var/lib/pulp/scripts/otel_server.py & | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added new setting ``API_ROOT_REWRITE_HEADER`` that when specified allows the API_ROOT to be rewritten | ||
per request based on the header's value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added new ``reverse`` method that handles Pulp specific url formatting. Plugins should update | ||
instances of ``django.urls.reverse`` and ``rest_framework.reverse`` to this new Pulp one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,16 @@ | |
from django.core.validators import MinValueValidator | ||
from django.db import models, transaction | ||
from django.db.models import F, Func, Q, Value | ||
from django.urls import reverse | ||
from django_lifecycle import AFTER_UPDATE, BEFORE_DELETE, hook | ||
from rest_framework.exceptions import APIException | ||
|
||
from pulpcore.app.util import ( | ||
batch_qs, | ||
get_url, | ||
get_view_name_for_model, | ||
get_domain, | ||
get_domain_pk, | ||
cache_key, | ||
reverse, | ||
) | ||
from pulpcore.constants import ALL_KNOWN_CONTENT_CHECKSUMS, PROTECTED_REPO_VERSION_MESSAGE | ||
from pulpcore.download.factory import DownloaderFactory | ||
|
@@ -1254,8 +1253,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 commentThe reason will be displayed to describe this comment to others. Learn more. This always feels like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. The interface isn't changed though, further down I re-create the |
||
""" | ||
Generate URLs for the content types added, removed, or present in the RepositoryVersion. | ||
|
||
|
@@ -1274,19 +1272,16 @@ def content_href(self): | |
ctypes = {c.get_pulp_type(): c for c in repository_model.CONTENT_TYPES} | ||
ctype_model = ctypes[self.content_type] | ||
ctype_view = get_view_name_for_model(ctype_model, "list") | ||
kwargs = {} | ||
if settings.DOMAIN_ENABLED: | ||
kwargs["pulp_domain"] = get_domain().name | ||
try: | ||
ctype_url = reverse(ctype_view, kwargs=kwargs) | ||
ctype_url = reverse(ctype_view, request=request) | ||
except django.urls.exceptions.NoReverseMatch: | ||
# We've hit a content type for which there is no viewset. | ||
# There's nothing we can do here, except to skip it. | ||
return | ||
|
||
repository_view = get_view_name_for_model(repository_model, "list") | ||
|
||
repository_url = reverse(repository_view, kwargs=kwargs) | ||
repository_url = reverse(repository_view, request=request) | ||
rv_href = ( | ||
repository_url | ||
+ str(self.repository_version.repository_id) | ||
|
@@ -1300,3 +1295,5 @@ def content_href(self): | |
partial_url_str = "{base}?repository_version_removed={rv_href}" | ||
full_url = partial_url_str.format(base=ctype_url, rv_href=rv_href) | ||
return full_url | ||
|
||
content_href = property(get_content_href) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
|
||
# API Root | ||
API_ROOT = "/pulp/" | ||
API_ROOT_REWRITE_HEADER = None | ||
|
||
# Application definition | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Didn't you only want to include this when configured? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
] | ||
|
||
AUTHENTICATION_BACKENDS = [ | ||
|
@@ -509,7 +511,11 @@ | |
finally: | ||
connection.close() | ||
|
||
settings.set("V3_API_ROOT", settings.API_ROOT + "api/v3/") # Not user configurable | ||
settings.set("V3_DOMAIN_API_ROOT", settings.API_ROOT + "<slug:pulp_domain>/api/v3/") | ||
if settings.API_ROOT_REWRITE_HEADER: | ||
api_root = "/<path:api_root>/" | ||
else: | ||
api_root = settings.API_ROOT | ||
settings.set("V3_API_ROOT", api_root + "api/v3/") # Not user configurable | ||
settings.set("V3_DOMAIN_API_ROOT", api_root + "<slug:pulp_domain>/api/v3/") | ||
settings.set("V3_API_ROOT_NO_FRONT_SLASH", settings.V3_API_ROOT.lstrip("/")) | ||
settings.set("V3_DOMAIN_API_ROOT_NO_FRONT_SLASH", settings.V3_DOMAIN_API_ROOT.lstrip("/")) |
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.