From 171b0a5ef783630ca7e8072d77f21703c260e86d Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:15:09 -0300 Subject: [PATCH] draft --- .github/workflows/scripts/install.sh | 2 +- CHANGES/5931.feature | 2 +- docs/admin/reference/settings.md | 4 ++-- pulpcore/app/serializers/fields.py | 4 +--- pulpcore/app/serializers/status.py | 2 -- pulpcore/app/settings.py | 2 +- pulpcore/tests/functional/api/test_status.py | 3 ++- template_config.yml | 2 +- 8 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index 775fe328fa..695a0d6bed 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -119,7 +119,7 @@ if [ "$TEST" = "azure" ]; then - ./azurite:/etc/pulp\ command: "azurite-blob --blobHost 0.0.0.0"' vars/main.yaml sed -i -e '$a azure_test: true\ -pulp_scenario_settings: {"api_root_rewrite_header": "X-API-Root", "content_origin": null, "domain_enabled": true, "rest_framework__default_permission_classes": ["pulpcore.plugin.access_policy.DefaultAccessPolicy"]}\ +pulp_scenario_settings: {"api_root_rewrite_header": "X-API-Root", "content_origin": "", "domain_enabled": true, "rest_framework__default_permission_classes": ["pulpcore.plugin.access_policy.DefaultAccessPolicy"]}\ pulp_scenario_env: {}\ ' vars/main.yaml fi diff --git a/CHANGES/5931.feature b/CHANGES/5931.feature index 755129d8d0..910e64f6ab 100644 --- a/CHANGES/5931.feature +++ b/CHANGES/5931.feature @@ -1 +1 @@ -Allow CONTENT_ORIGIN to be None. When None, the base_url for Distributions is a relative path. +Allow CONTENT_ORIGIN to be "" (an empty string). When empty, the base_url for Distributions is a relative path. diff --git a/docs/admin/reference/settings.md b/docs/admin/reference/settings.md index 93d7564861..fe72d80cf0 100644 --- a/docs/admin/reference/settings.md +++ b/docs/admin/reference/settings.md @@ -199,8 +199,8 @@ this setting only applies to uploads created after the change. A string containing the protocol, fqdn, and port where the content app is reachable by users. This is used by `pulpcore` and various plugins when referring users to the content app. For example if the API should refer users to content at using http to pulp.example.com on port -24816, (the content default port), you would set: `https://pulp.example.com:24816`. The default is `None`. -When set to `None`, the `base_url` for Distributions is a relative path. +24816, (the content default port), you would set: `https://pulp.example.com:24816`. The default is "". +When set to "" (empty string), the `base_url` for Distributions is a relative path. This means the API returns relative URLs without the protocol, fqdn, and port. diff --git a/pulpcore/app/serializers/fields.py b/pulpcore/app/serializers/fields.py index 0c9bd3afa9..6988c2646f 100644 --- a/pulpcore/app/serializers/fields.py +++ b/pulpcore/app/serializers/fields.py @@ -311,9 +311,7 @@ class BaseURLField(serializers.CharField): """ def to_representation(self, value): - origin = "/" - if settings.CONTENT_ORIGIN: - origin = settings.CONTENT_ORIGIN.strip("/") + origin = settings.CONTENT_ORIGIN.strip("/") prefix = settings.CONTENT_PATH_PREFIX.strip("/") base_path = value.base_path.strip("/") url = urljoin(origin, prefix + "/") diff --git a/pulpcore/app/serializers/status.py b/pulpcore/app/serializers/status.py index 76e8d1a151..3387ff0170 100644 --- a/pulpcore/app/serializers/status.py +++ b/pulpcore/app/serializers/status.py @@ -73,8 +73,6 @@ class ContentSettingsSerializer(serializers.Serializer): content_origin = serializers.CharField( help_text=_("The CONTENT_ORIGIN setting for this Pulp instance"), allow_blank=True, - allow_null=True, - required=False, ) content_path_prefix = serializers.CharField( help_text=_("The CONTENT_PATH_PREFIX setting for this Pulp instance"), diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index c50225c037..4fa8d5ca71 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -262,7 +262,7 @@ DRF_ACCESS_POLICY = {"reusable_conditions": ["pulpcore.app.global_access_conditions"]} -CONTENT_ORIGIN = None +CONTENT_ORIGIN = "" CONTENT_PATH_PREFIX = "/pulp/content/" API_APP_TTL = 120 # The heartbeat is called from gunicorn notify (defaulting to 45 sec). diff --git a/pulpcore/tests/functional/api/test_status.py b/pulpcore/tests/functional/api/test_status.py index 1e39f47c88..1900fd33dd 100644 --- a/pulpcore/tests/functional/api/test_status.py +++ b/pulpcore/tests/functional/api/test_status.py @@ -42,7 +42,7 @@ "content_settings": { "type": "object", "properties": { - "content_origin": {"type": ["string", "null"]}, + "content_origin": {"type": ["string"]}, "content_path_prefix": {"type": "string"}, }, "required": ["content_origin", "content_path_prefix"], @@ -138,6 +138,7 @@ def verify_get_response(status, expected_schema): assert status["versions"] != [] assert status["content_settings"] is not None + assert status["content_settings"]["content_origin"] is not None assert status["content_settings"]["content_path_prefix"] is not None assert status["storage"]["used"] is not None diff --git a/template_config.yml b/template_config.yml index 4747679d0d..3fffb8aadc 100644 --- a/template_config.yml +++ b/template_config.yml @@ -58,7 +58,7 @@ pulp_settings: tmpfile_protection_time: 10 upload_protection_time: 10 pulp_settings_azure: - content_origin: null + content_origin: "" api_root_rewrite_header: X-API-Root domain_enabled: true rest_framework__default_permission_classes: