Bug 1356524 - Only add Authorization header when sending requests to the tooltool url. r?gps
We're going to potentially use the same download manager for tooltool
and taskcluster artifacts, and we don't want to send the tooltool
authentication header to the taskcluster requests.
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -1560,16 +1560,17 @@ class PackageFrontend(MachCommandBase):
'''Download, cache and install pre-built toolchains.
'''
from mozbuild.artifacts import ArtifactCache
from mozbuild.action.tooltool import (
FileRecord,
open_manifest,
unpack_file,
)
+ from requests.adapters import HTTPAdapter
import redo
import requests
import shutil
self._set_log_level(verbose)
# Normally, we'd use self.log_manager.enable_unstructured(),
# but that enables all logging, while we only really want tooltool's
# and it also makes structured log output twice.
@@ -1589,18 +1590,26 @@ class PackageFrontend(MachCommandBase):
'https://api.pub.build.mozilla.org/tooltool').rstrip('/')
cache = ArtifactCache(cache_dir=cache_dir, log=self.log,
skip_cache=skip_cache)
if authentication_file:
with open(authentication_file, 'rb') as f:
token = f.read().strip()
- cache._download_manager.session.headers['Authorization'] = \
- 'Bearer {}'.format(token)
+
+ class TooltoolAuthenticator(HTTPAdapter):
+ def send(self, request, *args, **kwargs):
+ request.headers['Authorization'] = \
+ 'Bearer {}'.format(token)
+ return super(TooltoolAuthenticator, self).send(
+ request, *args, **kwargs)
+
+ cache._download_manager.session.mount(
+ tooltool_url, TooltoolAuthenticator())
manifest = open_manifest(tooltool_manifest)
downloaded_files = {}
for record in manifest.file_records:
if files and not any(record.filename == f or
record.filename.startswith('%s.' % f)
for f in files):