Browse Source

ref: Reuse internal_artifact_lookup_source_url as base for artifact files (#46379)

With this change, we can be certain, that the artifact lookup endpoint
will return a list of files, which URLs always point to the same source
as the list originated from.
Kamil Ogórek 1 year ago
parent
commit
ff47eebb1c
2 changed files with 13 additions and 8 deletions
  1. 4 4
      src/sentry/api/endpoints/artifact_lookup.py
  2. 9 4
      src/sentry/lang/native/sources.py

+ 4 - 4
src/sentry/api/endpoints/artifact_lookup.py

@@ -12,6 +12,7 @@ from sentry.api.base import region_silo_endpoint
 from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission
 from sentry.api.endpoints.debug_files import has_download_permission
 from sentry.api.serializers import serialize
+from sentry.lang.native.sources import get_internal_artifact_lookup_source_url
 from sentry.models import DebugIdArtifactBundle, Distribution, File, Release, ReleaseFile
 from sentry.models.artifactbundle import ArtifactBundleArchive, ReleaseArtifactBundle
 from sentry.models.project import Project
@@ -116,7 +117,7 @@ class ProjectArtifactLookupEndpoint(ProjectEndpoint):
         individual_files = try_resolve_urls(urls, project, release_name, dist_name, bundle_file_ids)
 
         # Then: Construct our response
-        url_constructor = UrlConstructor(request)
+        url_constructor = UrlConstructor(project)
 
         found_artifacts = []
         for file_id in bundle_file_ids:
@@ -325,9 +326,8 @@ def find_file_in_archive_index(archive_index: dict, url: str) -> Optional[File]:
 
 
 class UrlConstructor:
-    def __init__(self, request: Request):
-        # TODO: is there a better way to construct a url to this same route?
-        self.base_url = request.build_absolute_uri(request.path)
+    def __init__(self, project: Project):
+        self.base_url = get_internal_artifact_lookup_source_url(project)
 
     def url_for_file_id(self, file_id: int) -> str:
         # NOTE: Returning a self-route that requires authentication (via Bearer token)

+ 9 - 4
src/sentry/lang/native/sources.py

@@ -149,9 +149,9 @@ def get_internal_source(project):
     }
 
 
-def get_internal_artifact_lookup_source(project):
+def get_internal_artifact_lookup_source_url(project):
     """
-    Returns the source configuration for the Sentry artifact-lookup API.
+    Returns the url used as a part of source configuration for the Sentry artifact-lookup API.
     """
     internal_url_prefix = options.get("system.internal-url-prefix")
     if not internal_url_prefix:
@@ -162,7 +162,7 @@ def get_internal_artifact_lookup_source(project):
             ).replace("127.0.0.1", "host.docker.internal")
 
     assert internal_url_prefix
-    sentry_source_url = "{}{}".format(
+    return "{}{}".format(
         internal_url_prefix.rstrip("/"),
         reverse(
             "sentry-api-0-project-artifact-lookup",
@@ -173,10 +173,15 @@ def get_internal_artifact_lookup_source(project):
         ),
     )
 
+
+def get_internal_artifact_lookup_source(project):
+    """
+    Returns the source configuration for the Sentry artifact-lookup API.
+    """
     return {
         "type": "sentry",
         "id": INTERNAL_SOURCE_NAME,
-        "url": sentry_source_url,
+        "url": get_internal_artifact_lookup_source_url(project),
         "token": get_system_token(),
     }