-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecrets.py
34 lines (28 loc) · 1.06 KB
/
secrets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Search environment variables for secrets and create `.pypirc` for pipeline.
"""
import os
from pathlib import Path
def main():
repo = os.getenv("PIP_REPOSITORY")
user = os.getenv("PIP_USERNAME")
passw = os.getenv("PIP_PASSWORD")
configpath = os.path.expanduser("~/.config/pip")
print(os.getcwd())
if repo is user is passw is None:
print("No secrets provided, doing nothing.")
elif None in [repo, user, passw]:
raise Exception("PIP environment variables incomplete.")
else:
if os.path.exists(f"{configpath}/pip.conf"):
raise Exception(f"{configpath}/pip.conf exists, refusing to overwrite.")
Path(configpath).mkdir(parents=True, exist_ok=True)
with open(f"{configpath}/pip.conf", "w") as outfile:
outfile.write(
f"[global]\n"
f"index = https://{user}:{passw}@{repo}/pypi\n"
f"index-url = https://{user}:{passw}@{repo}/simple\n"
)
print("Created config ~/.config/pip/pip.conf")
if __name__ == "__main__":
main()