2019-07-17 14:58:39 +00:00
|
|
|
import click
|
|
|
|
import requests
|
|
|
|
from decouple import config
|
2019-09-13 18:10:23 +00:00
|
|
|
|
2019-08-12 12:56:19 +00:00
|
|
|
from .helper import OTPCredentials, load_dump_pretty
|
2019-07-17 14:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def user():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-08-12 12:56:19 +00:00
|
|
|
@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)
|
2019-07-17 14:58:39 +00:00
|
|
|
def list_files(name, realm, seed):
|
|
|
|
data = OTPCredentials(name, realm, seed).get_json()
|
2019-09-13 18:10:23 +00:00
|
|
|
r = requests.get("{}/user/files".format(config('UCLOUD_API_SERVER')),
|
|
|
|
json=data)
|
2019-08-12 12:56:19 +00:00
|
|
|
print(load_dump_pretty(r.content))
|
2019-07-17 14:58:39 +00:00
|
|
|
|
|
|
|
|
2019-08-12 12:56:19 +00:00
|
|
|
@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)
|
2019-07-17 14:58:39 +00:00
|
|
|
def list_vms(name, realm, seed):
|
|
|
|
data = OTPCredentials(name, realm, seed).get_json()
|
2019-09-13 18:10:23 +00:00
|
|
|
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)
|
2019-09-13 19:06:55 +00:00
|
|
|
@click.option("--cc", required=True, is_flag=True)
|
2019-09-13 18:10:23 +00:00
|
|
|
@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,
|
2019-09-13 19:06:55 +00:00
|
|
|
card_holder_name, email, cc):
|
2019-09-13 18:10:23 +00:00
|
|
|
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
|
|
|
|
}
|
2019-09-13 19:06:55 +00:00
|
|
|
r = requests.post(
|
2019-09-13 18:10:23 +00:00
|
|
|
"{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')),
|
|
|
|
json=data)
|
2019-08-12 12:56:19 +00:00
|
|
|
print(load_dump_pretty(r.content))
|