Fix error downloading assets

When downloading assets using a fine grained token you will get a "can't
concat str to bytes" error. This is due to the fine grained token being
concatenated onto bytes in the line:

`request.add_header("Authorization", "Basic ".encode("ascii") + auth)`

This is better handled in the function `_construct_request` so I changed
the lines that construct the request in `download_file` to use the
function `_construct_request` and updated the function signature to
reflect that.
This commit is contained in:
dale-primer-e
2024-03-14 14:55:20 +13:00
parent a0fdae3314
commit 122eb56aa1

View File

@@ -777,14 +777,19 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
return request
def download_file(url, path, auth):
def download_file(url, path, auth, as_app=False, fine=False):
# Skip downloading release assets if they already exist on disk so we don't redownload on every sync
if os.path.exists(path):
return
request = Request(url)
request = _construct_request(per_page=100,
page=1,
query_args={},
template=url,
auth=auth,
as_app=as_app,
fine=fine)
request.add_header("Accept", "application/octet-stream")
request.add_header("Authorization", "Basic ".encode("ascii") + auth)
opener = build_opener(S3HTTPRedirectHandler)
try:
@@ -1255,6 +1260,8 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
asset["url"],
os.path.join(release_assets_cwd, asset["name"]),
get_auth(args),
as_app=True if args.as_app is not None else False,
fine=True if args.token_fine is not None else False
)