Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/+pypi-path-prefix.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added new setting PYPI_PATH_PREFIX to allow for customizing the path prefix for the PyPI API.
6 changes: 6 additions & 0 deletions docs/admin/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
> This specifies the hostname where the PyPI API is served. It defaults to the fully qualified
> hostname of the system where the process is running. This needs to be adjusted if running behind
> a non local reverse proxy.
## PYPI_PATH_PREFIX

> This specifies where the PyPI endpoints can be found at. It defaults to `/pypi/`. The value is
> used along with `PYPI_API_HOSTNAME` to generate the links to the PyPI endpoints and should start
> and end in a slash.
2 changes: 1 addition & 1 deletion pulp_python/app/pypi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

ORIGIN_HOST = settings.CONTENT_ORIGIN if settings.CONTENT_ORIGIN else settings.PYPI_API_HOSTNAME
BASE_CONTENT_URL = urljoin(ORIGIN_HOST, settings.CONTENT_PATH_PREFIX)
BASE_API_URL = urljoin(settings.PYPI_API_HOSTNAME, "pypi/")
BASE_API_URL = urljoin(settings.PYPI_API_HOSTNAME, settings.PYPI_PATH_PREFIX)

PYPI_SIMPLE_V1_HTML = "application/vnd.pypi.simple.v1+html"
PYPI_SIMPLE_V1_JSON = "application/vnd.pypi.simple.v1+json"
Expand Down
6 changes: 4 additions & 2 deletions pulp_python/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework import serializers
from pypi_attestations import AttestationError
from pydantic import TypeAdapter, ValidationError
from urllib.parse import urljoin

from pulpcore.plugin import models as core_models
from pulpcore.plugin import serializers as core_serializers
Expand All @@ -31,6 +32,7 @@
)

log = logging.getLogger(__name__)
PYPI_BASE_URL = urljoin(settings.PYPI_API_HOSTNAME, settings.PYPI_PATH_PREFIX)


@extend_schema_serializer(
Expand Down Expand Up @@ -92,8 +94,8 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
def get_base_url(self, obj):
"""Gets the base url."""
if settings.DOMAIN_ENABLED:
return f"{settings.PYPI_API_HOSTNAME}/pypi/{get_domain().name}/{obj.base_path}/"
return f"{settings.PYPI_API_HOSTNAME}/pypi/{obj.base_path}/"
return urljoin(PYPI_BASE_URL, f"{get_domain().name}/{obj.base_path}/")
return urljoin(PYPI_BASE_URL, f"{obj.base_path}/")

class Meta:
fields = core_serializers.DistributionSerializer.Meta.fields + (
Expand Down
1 change: 1 addition & 0 deletions pulp_python/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

DRF_ACCESS_POLICY = {
"dynaconf_merge_unique": True,
Expand Down
5 changes: 3 additions & 2 deletions pulp_python/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
)

if settings.DOMAIN_ENABLED:
PYPI_API_URL = "pypi/<slug:pulp_domain>/<path:path>/"
PYPI_API_URL = "/<slug:pulp_domain>/<path:path>/"
else:
PYPI_API_URL = "pypi/<path:path>/"
PYPI_API_URL = "/<path:path>/"
PYPI_API_URL = settings.PYPI_PATH_PREFIX.strip("/") + PYPI_API_URL
# TODO: Implement remaining PyPI endpoints
# path("project/", PackageProject.as_view()), # Endpoints to nicely see contents of index
# path("search/", PackageSearch.as_view()),
Expand Down
Loading