From ea6b87df9d5b8a39ad6fc43ba2d595c7fd1b17ee Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 3 Aug 2018 10:18:41 +0300 Subject: Add: get-user, create-user, set-secret --- qvisqvetool | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/qvisqvetool b/qvisqvetool index d8d61d7..1fffab2 100755 --- a/qvisqvetool +++ b/qvisqvetool @@ -85,6 +85,61 @@ class QvisqveTool(cliapp.Application): token = api.get_token(scopes) self.output.write('{}\n'.format(token)) + def cmd_get_user(self, args): + api = self.get_api() + scopes = self.settings['scopes'] + token = api.get_token(scopes) + + for username in args: + path = '/users/{}'.format(username) + r = api.GET(token, path) + json.dump(r.json(), self.output, indent=4) + self.output.write('\n') + + def cmd_create_user(self, args): + username, password = args + api = self.get_api() + scopes = self.settings['scopes'] + token = api.get_token(scopes) + content_type = 'application/json' + + user = { + 'id': username, + } + path = '/users' + api.POST(token, path, json.dumps(user), content_type) + + secret = { + 'secret': password, + } + path = '/users/{}/secret'.format(username) + api.PUT(token, path, json.dumps(secret), content_type) + + self.output.write('Created {}\n'.format(username)) + + def cmd_set_secret(self, args): + kind, name, secret = args + + kinds = { + 'user': 'users', + 'client': 'clients', + 'application': 'applications', + } + kind = kinds.get(kind, kind) + + api = self.get_api() + scopes = self.settings['scopes'] + token = api.get_token(scopes) + content_type = 'application/json' + + secret = { + 'secret': secret, + } + path = '/{}/{}/secret'.format(kind, name) + api.PUT(token, path, json.dumps(secret), content_type) + + self.output.write('Set secret for {}\n'.format(name)) + def cmd_GET(self, args): api = self.get_api() scopes = self.settings['scopes'] -- cgit v1.2.1