Skip to content

Commit 3abd300

Browse files
committed
Add new setting PYPI_PATH_PREFIX
https://redhat.atlassian.net/browse/PULP-1318
1 parent f457c52 commit 3abd300

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

CHANGES/+pypi-path-prefix.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added new setting PYPI_PATH_PREFIX to allow for customizing the path prefix for the PyPI API.

docs/admin/reference/settings.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
> This specifies the hostname where the PyPI API is served. It defaults to the fully qualified
1414
> hostname of the system where the process is running. This needs to be adjusted if running behind
1515
> a non local reverse proxy.
16+
17+
## PYPI_PATH_PREFIX
18+
19+
> This specifies where the PyPI endpoints can be found at. It defaults to `/pypi/`. The value is
20+
> used along with `PYPI_API_HOSTNAME` to generate the links to the PyPI endpoints and should start
21+
> and end in a slash.

pulp_python/app/pypi/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
ORIGIN_HOST = settings.CONTENT_ORIGIN if settings.CONTENT_ORIGIN else settings.PYPI_API_HOSTNAME
6161
BASE_CONTENT_URL = urljoin(ORIGIN_HOST, settings.CONTENT_PATH_PREFIX)
62-
BASE_API_URL = urljoin(settings.PYPI_API_HOSTNAME, "pypi/")
62+
BASE_API_URL = urljoin(settings.PYPI_API_HOSTNAME, settings.PYPI_PATH_PREFIX)
6363

6464
PYPI_SIMPLE_V1_HTML = "application/vnd.pypi.simple.v1+html"
6565
PYPI_SIMPLE_V1_JSON = "application/vnd.pypi.simple.v1+json"

pulp_python/app/serializers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rest_framework import serializers
1010
from pypi_attestations import AttestationError
1111
from pydantic import TypeAdapter, ValidationError
12+
from urllib.parse import urljoin
1213

1314
from pulpcore.plugin import models as core_models
1415
from pulpcore.plugin import serializers as core_serializers
@@ -31,6 +32,7 @@
3132
)
3233

3334
log = logging.getLogger(__name__)
35+
PYPI_BASE_URL = urljoin(settings.PYPI_API_HOSTNAME, settings.PYPI_PATH_PREFIX)
3436

3537

3638
@extend_schema_serializer(
@@ -92,8 +94,8 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
9294
def get_base_url(self, obj):
9395
"""Gets the base url."""
9496
if settings.DOMAIN_ENABLED:
95-
return f"{settings.PYPI_API_HOSTNAME}/pypi/{get_domain().name}/{obj.base_path}/"
96-
return f"{settings.PYPI_API_HOSTNAME}/pypi/{obj.base_path}/"
97+
return urljoin(PYPI_BASE_URL, f"{get_domain().name}/{obj.base_path}/")
98+
return urljoin(PYPI_BASE_URL, f"{obj.base_path}/")
9799

98100
class Meta:
99101
fields = core_serializers.DistributionSerializer.Meta.fields + (

pulp_python/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
PYTHON_GROUP_UPLOADS = False
44
PYPI_API_HOSTNAME = "https://" + socket.getfqdn()
5+
PYPI_PATH_PREFIX = "/pypi/"
56

67
DRF_ACCESS_POLICY = {
78
"dynaconf_merge_unique": True,

pulp_python/app/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
)
1111

1212
if settings.DOMAIN_ENABLED:
13-
PYPI_API_URL = "pypi/<slug:pulp_domain>/<path:path>/"
13+
PYPI_API_URL = "/<slug:pulp_domain>/<path:path>/"
1414
else:
15-
PYPI_API_URL = "pypi/<path:path>/"
15+
PYPI_API_URL = "/<path:path>/"
16+
PYPI_API_URL = settings.PYPI_PATH_PREFIX.strip("/") + PYPI_API_URL
1617
# TODO: Implement remaining PyPI endpoints
1718
# path("project/", PackageProject.as_view()), # Endpoints to nicely see contents of index
1819
# path("search/", PackageSearch.as_view()),

0 commit comments

Comments
 (0)