Skip to content

Commit daea674

Browse files
committed
Bazel: cover standard https git credentials in git_lfs_probe.py
1 parent 9157dee commit daea674

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

misc/bazel/internal/git_lfs_probe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def get_endpoint():
2727
endpoint = ssh_server = ssh_path = None
2828
endpoint_re = re.compile(r'Endpoint(?: \(\S+\))?=(\S+)')
2929
ssh_re = re.compile(r'\s*SSH=(\S*):(.*)')
30+
credentials_re = re.compile(r'^password=(.*)$', re.M)
3031
for line in lfs_env.splitlines():
3132
m = endpoint_re.match(line)
3233
if m:
@@ -63,6 +64,15 @@ def get_endpoint():
6364
headers[k.capitalize()] = v
6465
if "GITHUB_TOKEN" in os.environ:
6566
headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
67+
if "Authorization" not in headers:
68+
credentials = subprocess.run(["git", "credential", "fill"], cwd=source_dir, stdout=subprocess.PIPE, text=True,
69+
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n",
70+
check=True).stdout
71+
m = credentials_re.search(credentials)
72+
if m:
73+
headers["Authorization"] = f"token {m[1]}"
74+
else:
75+
print(f"WARNING: no auth credentials found for {endpoint}")
6676
return endpoint, headers
6777

6878

0 commit comments

Comments
 (0)