From 39c71254ff8d89196d08432b2e6b208ac97f4239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Fri, 15 Oct 2021 13:36:54 +0200 Subject: [PATCH] ref(api): Use relative endpoint for ChunkUploadEndpoint if upload-url-prefix is absent --- src/sentry/api/endpoints/chunk.py | 15 +++++++++------ tests/sentry/api/endpoints/test_chunk_upload.py | 7 +------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/sentry/api/endpoints/chunk.py b/src/sentry/api/endpoints/chunk.py index 065759744c71e4..d0ccb85d0f7e9f 100644 --- a/src/sentry/api/endpoints/chunk.py +++ b/src/sentry/api/endpoints/chunk.py @@ -46,16 +46,19 @@ def get(self, request, organization): :auth: required """ endpoint = options.get("system.upload-url-prefix") - # We fallback to default system url if config is not set - if len(endpoint) == 0: - endpoint = options.get("system.url-prefix") + relative_url = reverse("sentry-api-0-chunk-upload", args=[organization.slug]) - url = reverse("sentry-api-0-chunk-upload", args=[organization.slug]) - endpoint = urljoin(endpoint.rstrip("/") + "/", url.lstrip("/")) + if len(endpoint) == 0: + # If config is not set, we return relative, versionless endpoint (with `/api/0` stripped) + prefix = "/api/0" + url = relative_url.replace(prefix, "/") + else: + # Otherwise, we want a relative, versioned endpoint, with user-configured prefix + url = urljoin(endpoint.rstrip("/") + "/", relative_url.lstrip("/")) return Response( { - "url": endpoint, + "url": url, "chunkSize": settings.SENTRY_CHUNK_UPLOAD_BLOB_SIZE, "chunksPerRequest": MAX_CHUNKS_PER_REQUEST, "maxFileSize": get_max_file_size(organization), diff --git a/tests/sentry/api/endpoints/test_chunk_upload.py b/tests/sentry/api/endpoints/test_chunk_upload.py index 3321631b1c5320..a2f3436506d0ce 100644 --- a/tests/sentry/api/endpoints/test_chunk_upload.py +++ b/tests/sentry/api/endpoints/test_chunk_upload.py @@ -26,11 +26,6 @@ def test_chunk_parameters(self): self.url, HTTP_AUTHORIZATION=f"Bearer {self.token.token}", format="json" ) - endpoint = options.get("system.upload-url-prefix") - # We fallback to default system url if config is not set - if len(endpoint) == 0: - endpoint = options.get("system.url-prefix") - assert response.status_code == 200, response.content assert response.data["chunkSize"] == settings.SENTRY_CHUNK_UPLOAD_BLOB_SIZE assert response.data["chunksPerRequest"] == MAX_CHUNKS_PER_REQUEST @@ -38,7 +33,7 @@ def test_chunk_parameters(self): assert response.data["maxFileSize"] == options.get("system.maximum-file-size") assert response.data["concurrency"] == MAX_CONCURRENCY assert response.data["hashAlgorithm"] == HASH_ALGORITHM - assert response.data["url"] == options.get("system.url-prefix") + self.url + assert response.data["url"] == self.url.replace("/api/0", "/") options.set("system.upload-url-prefix", "test") response = self.client.get(