61 lines
2.1 KiB
Python
Executable file
61 lines
2.1 KiB
Python
Executable file
from commands.helper import OTPCredentials, load_dump_pretty
|
|
from decouple import config
|
|
|
|
import click
|
|
import requests
|
|
|
|
|
|
@click.group()
|
|
def user():
|
|
pass
|
|
|
|
|
|
@user.command("files")
|
|
@click.option("--name", envvar="OTP_NAME", required=True)
|
|
@click.option("--realm", envvar="OTP_REALM", required=True)
|
|
@click.option("--seed", envvar="OTP_SEED", required=True)
|
|
def list_files(name, realm, seed):
|
|
data = OTPCredentials(name, realm, seed).get_json()
|
|
r = requests.get("{}/user/files".format(config('UCLOUD_API_SERVER')), json=data)
|
|
print(load_dump_pretty(r.content))
|
|
|
|
|
|
@user.command("vms")
|
|
@click.option("--name", envvar="OTP_NAME", required=True)
|
|
@click.option("--realm", envvar="OTP_REALM", required=True)
|
|
@click.option("--seed", envvar="OTP_SEED", required=True)
|
|
def list_vms(name, realm, seed):
|
|
data = OTPCredentials(name, realm, seed).get_json()
|
|
r = requests.get("{}/user/vms".format(config('UCLOUD_API_SERVER')), json=data)
|
|
print(load_dump_pretty(r.content))
|
|
|
|
@user.command("add-ssh")
|
|
@click.option("--name", envvar="OTP_NAME", required=True)
|
|
@click.option("--realm", envvar="OTP_REALM", required=True)
|
|
@click.option("--seed", envvar="OTP_SEED", required=True)
|
|
@click.option("--key_name", required=True)
|
|
@click.option("--key", required=True)
|
|
def add_ssh(name, realm, seed, key_name, key):
|
|
otp = OTPCredentials(name, realm, seed)
|
|
data = {
|
|
**otp.get_json(),
|
|
"key_name": key_name,
|
|
"key": key
|
|
}
|
|
r = requests.get("{}/user/add-ssh".format(config('UCLOUD_API_SERVER')), json=data)
|
|
print(load_dump_pretty(r.content))
|
|
|
|
|
|
@user.command("remove-ssh")
|
|
@click.option("--name", envvar="OTP_NAME", required=True)
|
|
@click.option("--realm", envvar="OTP_REALM", required=True)
|
|
@click.option("--seed", envvar="OTP_SEED", required=True)
|
|
@click.option("--key_name", required=True)
|
|
def remove_ssh(name, realm, seed, key_name):
|
|
otp = OTPCredentials(name, realm, seed)
|
|
data = {
|
|
**otp.get_json(),
|
|
"key_name": key_name,
|
|
}
|
|
r = requests.get("{}/user/remove-ssh".format(config('UCLOUD_API_SERVER')), json=data)
|
|
print(load_dump_pretty(r.content))
|