ucloud-setup/app/api.py

52 lines
1.8 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,\
2019-08-28 07:13:05 +00:00
clone_etcd_wrapper, GitOperation,\
PipenvOperation, FileOperation,\
PackageManagementOperation
2019-08-27 08:31:22 +00:00
@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-28 07:13:05 +00:00
# Install Package
op = PackageManagementOperation.install("asdnioasndisa")
# Git Operation Depends on success of previous operation i.e PackageManagementOperation
op.add(GitOperation.clone("https://code.ungleich.ch/ungleich-public/ucloud-api.git"))
2019-08-27 11:19:54 +00:00
2019-08-27 13:33:26 +00:00
content = f"AUTH_NAME={auth_name}\n" \
f"AUTH_SEED={auth_seed}\n" \
f"AUTH_REALM={auth_seed}\n" \
f"REALM_ALLOWED={list(realm_allowed)}\n" \
f"OTP_SERVER={otp_server}\n"
2019-08-27 11:19:54 +00:00
2019-08-28 07:13:05 +00:00
# FileOperation depends on success of previos operation i.e GitOperation.clone
op.add(FileOperation.write,
2019-08-27 11:19:54 +00:00
path=os.path.join("ucloud-api", ".env"),
content=content)
2019-08-28 07:13:05 +00:00
op.add(GitOperation.clone, path="ucloud-api",
2019-08-27 11:19:54 +00:00
url="https://code.ungleich.ch/ungleich-public/ucloud_common")
2019-08-28 07:13:05 +00:00
op.add(GitOperation.clone, path="ucloud-api",
2019-08-27 11:19:54 +00:00
url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
2019-08-27 08:31:22 +00:00
2019-08-28 07:13:05 +00:00
op.add(PipenvOperation.install, path="ucloud-api")