diff --git a/commands/user.py b/commands/user.py index cd23d31..e73e1db 100755 --- a/commands/user.py +++ b/commands/user.py @@ -1,8 +1,7 @@ import click -import json import requests - from decouple import config + from .helper import OTPCredentials, load_dump_pretty @@ -17,7 +16,8 @@ def user(): @click.option("--seed", envvar="OTP_SEED", required=True) def list_files(name, realm, seed): data = OTPCredentials(name, realm, seed).get_json() - r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/files", json=data) + r = requests.get("{}/user/files".format(config('UCLOUD_API_SERVER')), + json=data) print(load_dump_pretty(r.content)) @@ -27,5 +27,35 @@ def list_files(name, realm, seed): @click.option("--seed", envvar="OTP_SEED", required=True) def list_vms(name, realm, seed): data = OTPCredentials(name, realm, seed).get_json() - r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/vms", json=data) + 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) +@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): + 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.get( + "{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')), + json=data) print(load_dump_pretty(r.content))