abderrahim commented on code in PR #1895:
URL: https://github.com/apache/buildstream/pull/1895#discussion_r1509993518


##########
src/buildstream/downloadablefilesource.py:
##########
@@ -25,6 +25,66 @@
 implementation.
 
 
+SourceMirror extra data "auth-header-format"
+--------------------------------------------
+The DownloadableFileSource, and consequently any :class:`Source 
<buildstream.source.Source>`
+implementations which derive from DownloadableFileSource, support the 
"auth-header-format"
+extra data returned by :class:`SourceMirror 
<buildstream.sourcemirror.SourceMirror>` plugins
+through :func:`Source.translate_url() 
<buildstream.source.Source.translate_url>`.
+
+This functionality is available **Since: 2.2**.
+
+This allows one to use :class:`SourceMirror 
<buildstream.sourcemirror.SourceMirror>` plugins
+to add an authorization header to the ``GET`` requests.
+
+
+**Example:**
+
+.. code:: python
+
+   class MySourceMirror(SourceMirror):
+
+        def translate_url(
+            self,
+            *,
+            project_name: str,
+            alias: str,
+            alias_url: str,
+            alias_substitute_url: Optional[str],
+            source_url: str,
+            extra_data: Optional[Dict[str, Any]],
+        ) -> str:
+
+            #
+            # Set the "auth-header-format" extra data
+            #
+            if extra_data is not None:
+                extra_data["auth-header-format"] = "Bearer {password}"
+
+            return alias_substitute_url + source_url
+
+The "auth-header-format" value **must** contain the ``{password}`` expression, 
which

Review Comment:
   We could support `{login}` here as well.



##########
src/buildstream/downloadablefilesource.py:
##########
@@ -25,6 +25,66 @@
 implementation.
 
 
+SourceMirror extra data "auth-header-format"
+--------------------------------------------
+The DownloadableFileSource, and consequently any :class:`Source 
<buildstream.source.Source>`
+implementations which derive from DownloadableFileSource, support the 
"auth-header-format"
+extra data returned by :class:`SourceMirror 
<buildstream.sourcemirror.SourceMirror>` plugins
+through :func:`Source.translate_url() 
<buildstream.source.Source.translate_url>`.
+
+This functionality is available **Since: 2.2**.
+
+This allows one to use :class:`SourceMirror 
<buildstream.sourcemirror.SourceMirror>` plugins
+to add an authorization header to the ``GET`` requests.
+
+
+**Example:**
+
+.. code:: python
+
+   class MySourceMirror(SourceMirror):

Review Comment:
   I don't like that this feature is only available when implementing a custom 
SourceMirror. I would like this to be available with regular aliases and 
default mirrors.
   
   I think we could have alias definitions be "string or dict", where the dict 
would contain "url" and "extra-data". (Of course custom source mirrors would 
still support this)



##########
src/buildstream/downloadablefilesource.py:
##########
@@ -145,7 +221,22 @@ class DownloadableFileSource(Source):
     def configure(self, node):
         self.original_url = node.get_str("url")
         self.ref = node.get_str("ref", None)
-        self.url = self.translate_url(self.original_url)
+
+        extra_data = {}
+        self.url = self.translate_url(self.original_url, extra_data=extra_data)
+        self.auth_header_format = extra_data.get("auth-header-format")

Review Comment:
   I'm afraid that doing so will require mirrors to know what source plugin 
they are translating for to only provide relevant keys.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to