a
This commit is contained in:
parent
843949e7ca
commit
e57772f19e
8 changed files with 301 additions and 119 deletions
106
app/api.py
106
app/api.py
|
|
@ -2,52 +2,84 @@ import click
|
|||
import subprocess
|
||||
import os
|
||||
|
||||
from app.helper import clone, clone_common,\
|
||||
clone_etcd_wrapper, GitOperation,\
|
||||
PipenvOperation, FileOperation,\
|
||||
PackageManagementOperation
|
||||
from app.helper import (
|
||||
clone,
|
||||
clone_common,
|
||||
clone_etcd_wrapper,
|
||||
GitOperation,
|
||||
PipenvOperation,
|
||||
FileOperation,
|
||||
PackageManagementOperation,
|
||||
)
|
||||
|
||||
|
||||
@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")
|
||||
@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)
|
||||
|
||||
def setup(path, auth_name, auth_seed, auth_realm,
|
||||
realm_allowed, otp_server):
|
||||
os.chdir(path)
|
||||
|
||||
|
||||
# Install Package
|
||||
op = PackageManagementOperation.install("etcd")
|
||||
|
||||
# Git Operation Depends on success of previous operation i.e PackageManagementOperation
|
||||
op.add(GitOperation.clone,
|
||||
url="https://code.ungleich.ch/ungleich-public/ucloud-api.git",
|
||||
path=path)
|
||||
|
||||
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"
|
||||
|
||||
# FileOperation depends on success of previos operation i.e GitOperation.clone
|
||||
op.add(FileOperation.write,
|
||||
path=os.path.join("ucloud-api", ".env"),
|
||||
content=content)
|
||||
|
||||
op.add(GitOperation.clone, path="ucloud-api",
|
||||
url="https://code.ungleich.ch/ungleich-public/ucloud_common")
|
||||
|
||||
op.add(GitOperation.clone, path="ucloud-api",
|
||||
url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
|
||||
|
||||
op.add(PipenvOperation.install, path="ucloud-api")
|
||||
# Install etcd
|
||||
op = PackageManagementOperation.install("etcd")
|
||||
|
||||
# Add --pidfile argument to supervise daemon
|
||||
op.add(
|
||||
subprocess.check_output,
|
||||
args=r"""sed -i -e 's/supervise_daemon_args="--chdir $ETCD_DATA_DIR"/supervise_daemon_args="--chdir $ETCD_DATA_DIR --pidfile /run/etcd.pid"/g' /etc/init.d/etcd""".split(),
|
||||
)
|
||||
|
||||
# Change address of etcd
|
||||
op.add(
|
||||
subprocess.check_output,
|
||||
args=r'sed -i -e "s/localhost/[2a0a:e5c0:0:2:0:b3ff:fe39:7994]/g" /etc/etcd/conf.yml'.split(),
|
||||
)
|
||||
|
||||
# Start and Enable etcd service
|
||||
op.add(subprocess.check_output,
|
||||
args="service etcd start; rc-update add etcd".split())
|
||||
|
||||
# Git Operation Depends on success of previous operation i.e PackageManagementOperation
|
||||
op.add(
|
||||
GitOperation.clone,
|
||||
url="https://code.ungleich.ch/ungleich-public/ucloud-api.git",
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
# FileOperation depends on success of previos operation i.e GitOperation.clone
|
||||
op.add(
|
||||
FileOperation.write, path=os.path.join("ucloud-api", ".env"), content=content
|
||||
)
|
||||
|
||||
op.add(
|
||||
GitOperation.clone,
|
||||
path="ucloud-api",
|
||||
url="https://code.ungleich.ch/ungleich-public/ucloud_common",
|
||||
)
|
||||
|
||||
op.add(
|
||||
GitOperation.clone,
|
||||
path="ucloud-api",
|
||||
url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
|
||||
)
|
||||
|
||||
op.add(PipenvOperation.install, path="ucloud-api")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue