ucloud-setup/app/api.py
2019-08-27 13:57:22 +05:00

45 lines
No EOL
1.4 KiB
Python

import click
import subprocess
import os
from app.helper import clone, clone_common,\
clone_etcd_wrapper, pipenv_install
@click.group()
def api():
pass
@api.command("setup")
@click.option("--path", required=True)
@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")
def setup(path, auth_name, auth_seed, auth_realm,
realm_allowed, otp_server):
os.chdir(path)
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:
print("Unsuccessful installation. Please fix errors then run the installation again")