summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-08-03 10:35:12 +0300
committerLars Wirzenius <liw@liw.fi>2018-08-03 10:35:12 +0300
commit9353d90a656acc45451956b4048f7a5befcf22cd (patch)
tree9e86217bc6848f43db0cd48c176c509a301806d1
parent77e2be064ee4601045ca623f6006dbb8a35f058e (diff)
downloadqvisqve-9353d90a656acc45451956b4048f7a5befcf22cd.tar.gz
Change: have generic get, list, create, set-secret commands
For all kinds of entities.
-rwxr-xr-xqvisqvetool54
1 files changed, 36 insertions, 18 deletions
diff --git a/qvisqvetool b/qvisqvetool
index 90bfd70..731606e 100755
--- a/qvisqvetool
+++ b/qvisqvetool
@@ -40,6 +40,13 @@ import qvisqve
json_content_type = 'application/json'
+paths = {
+ 'user': '/users',
+ 'client': '/clients',
+ 'application': '/applications',
+}
+
+
class QvisqveTool(cliapp.Application):
def add_settings(self):
@@ -86,40 +93,51 @@ class QvisqveTool(cliapp.Application):
api, token = self.get_api()
self.output.write('{}\n'.format(token))
- def cmd_get_user(self, args):
+ def cmd_get(self, args):
api, token = self.get_api()
- for username in args:
- path = '/users/{}'.format(username)
+ kind = args[0]
+ names = args[1:]
+ path = paths[kind]
+ for name in names:
+ path = '{}/{}'.format(path, name)
r = api.GET(token, path)
+ self.output.write('{} {}:\n'.format(kind, name))
json.dump(r.json(), self.output, indent=4)
self.output.write('\n')
- def cmd_create_user(self, args):
- username, password = args
- api, token = self.get_api()
+ def cmd_list(self, args):
+ for kind in args:
+ path = paths[kind]
+
+ api, token = self.get_api()
+ r = api.GET(token, path)
+ names = r.json()['resources']
+ for name in sorted(names):
+ self.output.write('{} {}\n'.format(kind, name))
- user = {
- 'id': username,
+ def cmd_create(self, args):
+ kind, name, password = args
+
+ entity = {
+ 'id': name,
}
- path = '/users'
- api.POST(token, path, json.dumps(user), json_content_type)
+ path = paths[kind]
+
+ api, token = self.get_api()
+ api.POST(token, path, json.dumps(entity), json_content_type)
secret = {
'secret': password,
}
- path = '/users/{}/secret'.format(username)
- api.PUT(token, path, json.dumps(secret), json_content_type)
+ secret_path = '{}/{}/secret'.format(path, name)
+ api.PUT(token, secret_path, json.dumps(secret), json_content_type)
- self.output.write('Created {}\n'.format(username))
+ entity_path = '{}/{}'.format(path, name)
+ self.output.write('Created {} {}\n'.format(kind, name))
def cmd_set_secret(self, args):
kind, name, secret = args
- kinds = {
- 'user': 'users',
- 'client': 'clients',
- 'application': 'applications',
- }
kind = kinds.get(kind, kind)
api, token = self.get_api()