Skip to content

Commit faa2dce

Browse files
committed
test GITHUB_TOKEN non-emptyness before using it in auth headers
1 parent 5b572a2 commit faa2dce

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

misc/bazel/internal/git_lfs_probe.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ def get_endpoint():
6868
# see https://github.com/actions/checkout/blob/44c2b7a8a4ea60a981eaca3cf939b5f4305c123b/src/git-auth-helper.ts#L56-L63
6969
auth = git("config", f"http.{url.scheme}://{url.netloc}/.extraheader")
7070
endpoint.update_headers(get_env(auth, sep=": "))
71+
if "GITHUB_TOKEN" in os.environ and os.environ.get("GITHUB_TOKEN") != "":
72+
endpoint.headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
7173
if "Authorization" not in endpoint.headers:
72-
if "GITHUB_TOKEN" in os.environ:
73-
endpoint.headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
74-
else:
75-
# last chance: use git credentials (possibly backed by a credential helper like the one installed by gh)
76-
# see https://git-scm.com/docs/git-credential
77-
credentials = get_env(git("credential", "fill", check=True,
78-
# drop leading / from url.path
79-
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n"))
80-
auth = base64.b64encode(f'{credentials["username"]}:{credentials["password"]}'.encode()).decode('ascii')
81-
endpoint.headers["Authorization"] = f"Basic {auth}"
74+
# last chance: use git credentials (possibly backed by a credential helper like the one installed by gh)
75+
# see https://git-scm.com/docs/git-credential
76+
credentials = get_env(git("credential", "fill", check=True,
77+
# drop leading / from url.path
78+
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n"))
79+
auth = base64.b64encode(f'{credentials["username"]}:{credentials["password"]}'.encode()).decode('ascii')
80+
endpoint.headers["Authorization"] = f"Basic {auth}"
8281
return endpoint
8382

8483

0 commit comments

Comments
 (0)