Skip to content

Commit

Permalink
Bazel: cover standard https git credentials in git_lfs_probe.py
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed May 2, 2024
1 parent 9157dee commit daea674
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions misc/bazel/internal/git_lfs_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_endpoint():
endpoint = ssh_server = ssh_path = None
endpoint_re = re.compile(r'Endpoint(?: \(\S+\))?=(\S+)')
ssh_re = re.compile(r'\s*SSH=(\S*):(.*)')
credentials_re = re.compile(r'^password=(.*)$', re.M)
for line in lfs_env.splitlines():
m = endpoint_re.match(line)
if m:
Expand Down Expand Up @@ -63,6 +64,15 @@ def get_endpoint():
headers[k.capitalize()] = v
if "GITHUB_TOKEN" in os.environ:
headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
if "Authorization" not in headers:
credentials = subprocess.run(["git", "credential", "fill"], cwd=source_dir, stdout=subprocess.PIPE, text=True,
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n",
check=True).stdout
m = credentials_re.search(credentials)
if m:
headers["Authorization"] = f"token {m[1]}"
else:
print(f"WARNING: no auth credentials found for {endpoint}")
return endpoint, headers


Expand Down

0 comments on commit daea674

Please sign in to comment.