From 122eb56aa11c0878471f96aab63aaa3621a6e2e9 Mon Sep 17 00:00:00 2001 From: dale-primer-e <70494025+dale-primer-e@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:55:20 +1300 Subject: [PATCH 1/3] 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. --- github_backup/github_backup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 562313a..49e54a6 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -777,14 +777,19 @@ def redirect_request(self, req, fp, code, msg, headers, newurl): 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 ) From 1eccebcb83e7715ba3d994137098174e070a05f3 Mon Sep 17 00:00:00 2001 From: dale-primer-e <70494025+dale-primer-e@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:27:22 +1300 Subject: [PATCH 2/3] Fix error with as_app flag --- github_backup/github_backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 49e54a6..f564458 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -1260,7 +1260,7 @@ 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, + as_app=args.as_app, fine=True if args.token_fine is not None else False ) From 9812988a4acf369a7ad2ea3171ba3dc713d85aaa Mon Sep 17 00:00:00 2001 From: dale-primer-e <70494025+dale-primer-e@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:26:14 +1300 Subject: [PATCH 3/3] Remove trailing whitespaces That are triggering flake. --- github_backup/github_backup.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index f564458..ca9e88e 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -782,12 +782,12 @@ def download_file(url, path, auth, as_app=False, fine=False): if os.path.exists(path): return - request = _construct_request(per_page=100, - page=1, - query_args={}, - template=url, - auth=auth, - as_app=as_app, + 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") opener = build_opener(S3HTTPRedirectHandler)