summaryrefslogtreecommitdiff
path: root/qvisqvetool
diff options
context:
space:
mode:
Diffstat (limited to 'qvisqvetool')
-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()