-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
executable file
·85 lines (72 loc) · 2.66 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python3
import argparse
import sys
import tabulate
from auth_api_client import config
from auth_api_client.common import api_get, format_ts, heading, load_config, validate_user
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--user", type=validate_user)
parser.add_argument("-m", "--mfa", action="store_true")
args = parser.parse_args()
if args.user and args.mfa:
sys.stderr.write("Cannot combine --user and --mfa options\n")
sys.exit(1)
if not (args.user or args.mfa):
sys.stderr.write("Please specify either --mfa or --user USER\n")
sys.exit(1)
load_config()
if args.user:
heading(f"SSH keys for {args.user}")
ssh_keys = api_get(f"ssh_keys/{args.user}")
for key in ssh_keys["keys"]:
print()
print(f"Name: {key['name']}")
print(f"Created: {format_ts(key['created_at'])}")
print(f"Key: {key['type']} {key['pub_key']}")
print()
heading(f"VPN certificates for {args.user}")
vpn_keys = api_get(f"vpn_keys/{args.user}")
for key in vpn_keys["keys"]:
print()
print(f"Name: {key['name']}")
print(f"UUID: {key['uuid']}")
print(f"Status: {key['status']}")
print(f"Created: {format_ts(key['created_at'])}")
print(f"Expires: {format_ts(key['expires_at'])}")
print("Public certificate:")
print(key["public_cert"])
print()
heading(f"MFA requests for {args.user}")
mfa_requests = api_get(f"mfa_requests/{args.user}")
to_print = []
for mfa in mfa_requests["mfa_requests"]:
row = {}
row["Created"] = format_ts(key['created_at'])
row["Updated"] = format_ts(key['updated_at'])
if mfa["expires_at"]:
row["Expires"] = format_ts(key['expires_at'])
else:
row["Expires"] = "n/a"
row["Service"] = mfa["service"]
row["IP address"] = mfa["remote_ip"]
row["Status"] = mfa["status"]
to_print.append(row)
print(tabulate.tabulate(to_print, headers="keys"))
if args.mfa:
heading("MFA requests for all users")
mfa_requests = api_get("mfa_requests")
to_print = []
for mfa in mfa_requests["mfa_requests"]:
row = {}
row["Username"] = mfa["username"]
row["Created"] = format_ts(key['created_at'])
row["Updated"] = format_ts(key['updated_at'])
if mfa["expires_at"]:
row["Expires"] = format_ts(key['expires_at'])
else:
row["Expires"] = "n/a"
row["Service"] = mfa["service"]
row["IP address"] = mfa["remote_ip"]
row["Status"] = mfa["status"]
to_print.append(row)
print(tabulate.tabulate(to_print, headers="keys"))