summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-08-03 10:18:41 +0300
committerLars Wirzenius <liw@liw.fi>2018-08-03 10:18:41 +0300
commitea6b87df9d5b8a39ad6fc43ba2d595c7fd1b17ee (patch)
treeb9b014321cd7413602d2bc831ad296f7c236f14f
parent87b542db319257ef0bdb418bd847e81fae6e3d2c (diff)
downloadqvisqve-ea6b87df9d5b8a39ad6fc43ba2d595c7fd1b17ee.tar.gz
Add: get-user, create-user, set-secret
-rwxr-xr-xqvisqvetool55
1 files changed, 55 insertions, 0 deletions
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']