Skip to content

Commit

Permalink
Set CONTENT_ORIGIN default value to ""(empty str)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Jan 21, 2025
1 parent d7dc98b commit a1e1b61
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGES/5931.feature
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/admin/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
2 changes: 1 addition & 1 deletion pulp_file/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _generate_server_and_remote(*, manifest_path, policy):
yield _generate_server_and_remote


# if content_origin == null, base_url will return the relative path and
# if content_origin == "", base_url will return the relative path and
# we need to add the hostname to run the tests
@pytest.fixture
def file_distribution_base_url(bindings_cfg):
Expand Down
7 changes: 6 additions & 1 deletion pulpcore/app/models/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,12 @@ def ensure_singleton(self):
raise RuntimeError(f"This system already has a {cls.__name__}")

def artifact_url(self, artifact):
origin = settings.CONTENT_ORIGIN.strip("/")

# When CONTENT_ORIGIN == "" we need to set origin as "/" so that the base_url will
# have the relative path like "/some/file/path", instead of "some/file/path"
origin = "/"
if settings.CONTENT_ORIGIN:
origin = settings.CONTENT_ORIGIN.strip("/")
prefix = settings.CONTENT_PATH_PREFIX.strip("/")
base_path = self.base_path.strip("/")
if settings.DOMAIN_ENABLED:
Expand Down
3 changes: 3 additions & 0 deletions pulpcore/app/serializers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ class BaseURLField(serializers.CharField):
"""

def to_representation(self, value):

# When CONTENT_ORIGIN == "" we need to set origin as "/" so that the base_url will
# have the relative path like "/some/file/path", instead of "some/file/path"
origin = "/"
if settings.CONTENT_ORIGIN:
origin = settings.CONTENT_ORIGIN.strip("/")
Expand Down
2 changes: 0 additions & 2 deletions pulpcore/app/serializers/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 2 additions & 1 deletion pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@

DRF_ACCESS_POLICY = {"reusable_conditions": ["pulpcore.app.global_access_conditions"]}

CONTENT_ORIGIN = None
# Empty string is allowed, but None is not
CONTENT_ORIGIN = ""
CONTENT_PATH_PREFIX = "/pulp/content/"

API_APP_TTL = 120 # The heartbeat is called from gunicorn notify (defaulting to 45 sec).
Expand Down
3 changes: 2 additions & 1 deletion pulpcore/tests/functional/api/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion template_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a1e1b61

Please sign in to comment.