import click import requests from decouple import config from .helper import OTPCredentials, load_dump_pretty @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("register-payment") @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("--cc", required=True, is_flag=True) @click.option("--number", required=True) @click.option("--cvc", required=True) @click.option("--expiry-month", required=True, help="MM", type=str) @click.option("--expiry-year", required=True, help="YY", type=str) @click.option("--card-holder-name", required=True, help="The name as printed on the card", type=str) @click.option("--email", required=True, help="Email address", type=str) def register_payment(name, realm, seed, number, cvc, expiry_year, expiry_month, card_holder_name, email, cc): data = { **OTPCredentials(name, realm, seed).get_json(), "card_number": number, "cvc": cvc, "expiry_year": expiry_year, "expiry_month": expiry_month, "card_holder_name": card_holder_name, "email": email } r = requests.post( "{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')), json=data) print(load_dump_pretty(r.content))