Skip to content

Commit 0f368fd

Browse files
author
jwiltse
committed
Add configuration support for custom HTTP Headers with env var interpolation for authentication to custom URLs
1 parent 629ab08 commit 0f368fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

portable-python.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ cpython-additional-packages:
2929
# Uncomment to override cpython or a dependency source URL
3030
# Note: string "$version" will be replaced with version string (e.g. 1.2.3)
3131
# cpython-url: https://my-cpython-mirror/cpython-$version.tar.gz
32+
# cpython-http-headers:
33+
# - Authorization: Bearer ${GITHUB_TOKEN}
3234
# zlib-url: https://my-zlib-mirror/zlib-$version.tar.gz
35+
# zlib-http-headers:
36+
# - Authorization: Bearer ${GITHUB_TOKEN}
3337

3438
# Uncomment to override the ./configure arguments for a dependency
3539
# Note: this will replace the default arguments, not extend them

src/portable_python/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ def is_usable_module(self, name):
492492
def cfg_version(self, default):
493493
return PPG.config.get_value("%s-version" % self.m_name) or default
494494

495+
def cfg_http_headers(self):
496+
if config_http_headers := PPG.config.get_value("%s-http-headers" % self.m_name):
497+
return config_http_headers
498+
495499
def cfg_url(self, version):
496500
if config_url := PPG.config.get_value("%s-url" % self.m_name):
497501
url_template = Template(config_url)
@@ -643,7 +647,14 @@ def compile(self):
643647
https_proxy = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy")
644648
if https_proxy:
645649
proxies["https"] = https_proxy
646-
RestClient().download(self.url, path, proxies=proxies)
650+
651+
expanded_url = os.path.expandvars(self.url)
652+
expanded_http_headers = {}
653+
if headers := self.cfg_http_headers():
654+
for header_dict in headers:
655+
for key, value in header_dict.items():
656+
expanded_http_headers[os.path.expandvars(key)] = os.path.expandvars(value)
657+
RestClient().download(expanded_url, path, proxies=proxies, headers=expanded_http_headers)
647658

648659
runez.decompress(path, self.m_src_build, simplify=True)
649660

0 commit comments

Comments
 (0)