Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Use lstrip instead of replace in ChunkUploadEndpoint #29481

Merged
merged 1 commit into from
Oct 21, 2021
Merged
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
5 changes: 2 additions & 3 deletions src/sentry/api/endpoints/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
MAX_CONCURRENCY = settings.DEBUG and 1 or 8
HASH_ALGORITHM = "sha1"
SENTRYCLI_SEMVER_RE = re.compile(r"^sentry-cli\/(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*$")

API_PREFIX = "/api/0"
CHUNK_UPLOAD_ACCEPT = (
"debug_files", # DIF assemble
"release_files", # Release files assemble
Expand Down Expand Up @@ -65,8 +65,7 @@ def get(self, request, organization):
if len(endpoint) == 0:
# And we support relative url uploads, return a relative, versionless endpoint (with `/api/0` stripped)
if supports_relative_url:
prefix = "/api/0"
url = relative_url.replace(prefix, "/")
url = relative_url.lstrip(API_PREFIX)
# Otherwise, if we do not support them, return an absolute, versioned endpoint with a default, system-wide prefix
else:
endpoint = options.get("system.url-prefix")
Expand Down
5 changes: 3 additions & 2 deletions tests/sentry/api/endpoints/test_chunk_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from sentry import options
from sentry.api.endpoints.chunk import (
API_PREFIX,
HASH_ALGORITHM,
MAX_CHUNKS_PER_REQUEST,
MAX_CONCURRENCY,
Expand Down Expand Up @@ -57,15 +58,15 @@ def test_relative_url_support(self):
HTTP_USER_AGENT="sentry-cli/1.70.1",
format="json",
)
assert response.data["url"] == self.url.replace("/api/0", "/")
assert response.data["url"] == self.url.lstrip(API_PREFIX)

response = self.client.get(
self.url,
HTTP_AUTHORIZATION=f"Bearer {self.token.token}",
HTTP_USER_AGENT="sentry-cli/2.77.4",
format="json",
)
assert response.data["url"] == self.url.replace("/api/0", "/")
assert response.data["url"] == self.url.lstrip(API_PREFIX)

# < 1.70.1
response = self.client.get(
Expand Down