uotp-client added
This commit is contained in:
parent
106b7df5db
commit
78326a52df
3 changed files with 13 additions and 11 deletions
92
bin/uotp-client
Normal file
92
bin/uotp-client
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import pyotp
|
||||
import argparse
|
||||
|
||||
from uotp.config import env_vars, etcd_client
|
||||
from os.path import join as join_path
|
||||
from etcd3_wrapper import Etcd3Wrapper
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
arg_parser.add_argument("action",
|
||||
choices=["list", "create", "verify", "delete",
|
||||
"get-admin"])
|
||||
arg_parser.add_argument("--name")
|
||||
arg_parser.add_argument("--realm")
|
||||
arg_parser.add_argument("--seed")
|
||||
arg_parser.add_argument("--admin-name")
|
||||
arg_parser.add_argument("--admin-realm")
|
||||
arg_parser.add_argument("--admin-seed")
|
||||
arg_parser.add_argument("--auth-name")
|
||||
arg_parser.add_argument("--auth-realm")
|
||||
arg_parser.add_argument("--auth-seed")
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
action = args.action
|
||||
|
||||
if action == "list":
|
||||
assert args.admin_name and args.admin_realm and args.admin_seed, \
|
||||
"You must pass --admin-name, --admin-realm and --admin-seed"
|
||||
|
||||
data = \
|
||||
{
|
||||
"admin_name": args.admin_name,
|
||||
"admin_realm": args.admin_realm,
|
||||
"admin_token": pyotp.TOTP(args.admin_seed).now()
|
||||
}
|
||||
url = "http://localhost:{}/list/".format(env_vars.get('PORT'))
|
||||
r = requests.post(url, json=data)
|
||||
print(r.content.decode("utf-8"))
|
||||
|
||||
elif action == "create":
|
||||
assert args.name and args.realm and args.admin_name and args.admin_realm and args.admin_seed, \
|
||||
"You must pass --name, --realm, --admin-name, --admin-realm and --admin-seed"
|
||||
|
||||
data = \
|
||||
{
|
||||
"name": args.name,
|
||||
"realm": args.realm,
|
||||
"admin_name": args.admin_name,
|
||||
"admin_realm": args.admin_realm,
|
||||
"admin_token": pyotp.TOTP(args.admin_seed).now()
|
||||
}
|
||||
url = "http://localhost:{}/create/".format(env_vars.get('PORT'))
|
||||
r = requests.post(url, json=data)
|
||||
print(r.content.decode("utf-8"))
|
||||
|
||||
elif action == "verify":
|
||||
assert args.name and args.realm and args.seed and args.auth_name and args.auth_realm and args.auth_seed, \
|
||||
"You must pass --name, --realm, --seed, --auth-name, --auth-realm and --auth-seed"
|
||||
data = \
|
||||
{
|
||||
"name": args.name,
|
||||
"realm": args.realm,
|
||||
"token": pyotp.TOTP(args.seed).now(),
|
||||
"auth_name": args.auth_name,
|
||||
"auth_realm": args.auth_realm,
|
||||
"auth_token": pyotp.TOTP(args.auth_seed).now()
|
||||
}
|
||||
url = "http://localhost:{}/verify/".format(env_vars.get('PORT'))
|
||||
r = requests.post(url, json=data)
|
||||
print(r.content.decode("utf-8"))
|
||||
|
||||
elif action == "delete":
|
||||
assert args.name and args.admin_name and args.admin_realm and args.admin_seed, \
|
||||
"You must pass --name, --admin-name, --admin-realm and --admin-seed"
|
||||
|
||||
data = \
|
||||
{
|
||||
"name": args.name,
|
||||
"admin_name": args.admin_name,
|
||||
"admin_realm": args.admin_realm,
|
||||
"admin_token": pyotp.TOTP(args.admin_seed).now()
|
||||
}
|
||||
url = "http://localhost:{}/delete/".format(env_vars.get('PORT'))
|
||||
r = requests.post(url, json=data)
|
||||
print(r.content.decode("utf-8"))
|
||||
|
||||
elif action == "get-admin":
|
||||
admin_uotp = etcd_client.get(join_path(env_vars.get('BASE_PREFIX'), 'admin'))
|
||||
print(admin_uotp.value)
|
||||
Loading…
Add table
Add a link
Reference in a new issue