ucloud-setup/app/api.py

45 lines
1.4 KiB
Python
Raw Normal View History

2019-08-27 08:31:22 +00:00
import click
import subprocess
2019-08-27 08:57:22 +00:00
import os
2019-08-27 08:31:22 +00:00
from app.helper import clone, clone_common,\
clone_etcd_wrapper, pipenv_install
@click.group()
def api():
pass
@api.command("setup")
2019-08-27 08:57:22 +00:00
@click.option("--path", required=True)
2019-08-27 08:31:22 +00:00
@click.option("--auth_name", required=True)
@click.option("--auth_seed", required=True)
@click.option("--auth_realm", required=True)
@click.option("--realm_allowed", multiple=True, required=True)
@click.option("--otp_server", default="https://otp.ungleich.ch/ungleichotp/",
help="URL of ungleich OTP server")
2019-08-27 08:57:22 +00:00
def setup(path, auth_name, auth_seed, auth_realm,
realm_allowed, otp_server):
os.chdir(path)
2019-08-27 08:31:22 +00:00
if clone("https://code.ungleich.ch/ungleich-public/ucloud-api.git"):
with open(".env", "w") as env_file:
lines = [f"AUTH_NAME={auth_name}",
f"AUTH_SEED={auth_seed}",
f"AUTH_REALM={auth_seed}",
f"REALM_ALLOWED={realm_allowed}",
f"OTP_SERVER={otp_server}"]
env_file.writelines(lines)
result = []
result.append(clone_common())
result.append(clone_etcd_wrapper())
if all(result):
result.append(pipenv_install("ucloud-api"))
if all(result):
print("Successfull installation :)")
else:
2019-08-27 08:36:10 +00:00
print("Unsuccessful installation. Please fix errors then run the installation again")