-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
85 lines (70 loc) · 2.75 KB
/
main.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
"""Pritunl API Client
Usage:
main.py (-h | --help)
main.py --get-oid <org_name> [--debug]
main.py --get-user <org_name> <user_name> [--debug]
main.py --create-user <org_name> <user_name> <user_email> [--debug]
main.py --delete-user <org_name> <user_name> [--debug]
main.py --disable-user <org_name> <user_name> [--debug]
main.py --create-users-from-csv <csv_path> [--debug]
Options:
-h --help Show this screen
--get-oid Get Organization ID
--get-user Get User properties
--create-user Create new user
--delete-user Delete user from server
--disable-user Disable user from server
--create-users-from-csv Create a bulk users from csv file
--debug Set loglevel to DEBUG
"""
import sys
import time
import logging
from docopt import docopt
from pritunl_scripts.auth import request
from pritunl_scripts.get_user import get_user
from pritunl_scripts.create_user import create_user
from pritunl_scripts.get_organization import get_organization
from pritunl_scripts.create_from_csv import create_from_csv
from pritunl_scripts.delete_user import delete_user
from pritunl_scripts.disable_user import disable_user
if __name__ == '__main__':
arguments = docopt(__doc__)
if arguments['--debug']:
LOGLEVEL = 'DEBUG'
else:
LOGLEVEL = 'INFO'
logging.basicConfig(
level=LOGLEVEL,
format='%(asctime)s [%(levelname)s] %(message)s',
handlers=[logging.StreamHandler()]
)
if arguments['--get-oid']:
organization = arguments["<org_name>"]
response = get_organization(organization)
logging.debug(response)
if arguments['--get-user']:
organization = arguments["<org_name>"]
user = arguments["<user_name>"]
response = get_user(organization, user)
logging.debug(response)
if arguments['--create-user']:
organization = arguments["<org_name>"]
user = arguments["<user_name>"]
user_email = arguments["<user_email>"]
response = create_user(organization, user, user_email)
logging.debug(response)
if arguments['--delete-user']:
organization = arguments["<org_name>"]
user = arguments["<user_name>"]
response = delete_user(organization, user)
logging.debug(response)
if arguments['--disable-user']:
organization = arguments["<org_name>"]
user = arguments["<user_name>"]
response = disable_user(organization, user)
logging.debug(response)
if arguments['--create-users-from-csv']:
csvpath = arguments["<csv_path>"]
response = create_from_csv(csvpath)
logging.debug(response)