|
14 | 14 | ############################################### |
15 | 15 | import sys, json, httplib, base64 |
16 | 16 |
|
17 | | -base_path = "/api/users" |
18 | | - |
19 | 17 | #/(um.1) Assign arguments |
20 | 18 | if len(sys.argv) < 5: |
21 | | - print "USAGE: user_vhost_manager.py server_name:port auth_user auth_pass", |
22 | | - print "ACTION RESOURCE [PARAMS...]" |
| 19 | + print "USAGE: user_manager.py server_name:port auth_user auth_pass", |
| 20 | + print "ACTION [PARAMS...]" |
23 | 21 | sys.exit(1) |
24 | 22 |
|
25 | 23 | server, port = sys.argv[1].split(":") |
|
32 | 30 | else: |
33 | 31 | res_params = [] |
34 | 32 |
|
35 | | -#/(um.2) Connect to server |
36 | | -conn = httplib.HTTPConnection(server, port) |
| 33 | +#/(um.2) Build API path |
| 34 | +base_path = "/api/users" |
37 | 35 |
|
38 | | -#/(um.3) Build API path |
39 | 36 | if action == "list": |
40 | 37 | path = base_path |
41 | 38 | method = "GET" |
|
50 | 47 | method = "GET" |
51 | 48 |
|
52 | 49 |
|
53 | | -#/(um.4) Build JSON arguments |
| 50 | +#/(um.3) Build JSON arguments |
54 | 51 | json_args = "" |
55 | 52 | if action == "create": |
56 | 53 | json_args = {"password" : res_params[1], |
57 | 54 | "administrator" : json.loads(res_params[2])} |
58 | 55 | json_args = json.dumps(json_args) |
59 | 56 |
|
60 | | -#/(um.5) Issue API request |
| 57 | +#/(um.4) Issue API request |
| 58 | +conn = httplib.HTTPConnection(server, port) |
61 | 59 | credentials = base64.b64encode("%s:%s" % (username, password)) |
62 | 60 | conn.request(method, path, json_args, |
63 | 61 | {"Content-Type" : "application/json", |
|
68 | 66 | response.read()) |
69 | 67 | sys.exit(2) |
70 | 68 |
|
71 | | -#/(um.6) Parse and display response |
| 69 | +#/(um.5) Parse and display response |
72 | 70 | resp_payload = response.read() |
73 | 71 | if action in ["list", "show"]: |
74 | 72 | resp_payload = json.loads(resp_payload) |
75 | 73 |
|
76 | | - #/(um.7) Process 'list' results |
| 74 | + #/(um.6) Process 'list' results |
77 | 75 | if action == "list": |
78 | 76 | print "Count: %d" % len(resp_payload) |
79 | 77 | for user in resp_payload: |
80 | 78 | print "User: %(name)s" % user |
81 | 79 | print "\tPassword: %(password_hash)s" % user |
82 | 80 | print "\tAdministrator: %(administrator)s\n" % user |
83 | 81 |
|
84 | | - #/(um.8) Process 'show' results |
| 82 | + #/(um.7) Process 'show' results |
85 | 83 | if action == "show": |
86 | 84 | print "User: %(name)s" % resp_payload |
87 | 85 | print "\tPassword: %(password_hash)s" % resp_payload |
88 | 86 | print "\tAdministrator: %(administrator)s\n" % resp_payload |
| 87 | +#/(um.8) Create and delete requests have no result. |
89 | 88 | else: |
90 | 89 | print "Completed request!" |
91 | 90 |
|
|
0 commit comments