From a2bd5bca4c60499b3f9a2b99ec0dd0645bc718fe Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 3 Aug 2018 10:44:36 +0300 Subject: Add: PUT /applications/id --- qvisqve/management_router.py | 19 +++++++++++++++++++ qvisqvetool | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/qvisqve/management_router.py b/qvisqve/management_router.py index 6095d41..5592677 100644 --- a/qvisqve/management_router.py +++ b/qvisqve/management_router.py @@ -67,6 +67,11 @@ class ManagementEndpoint: 'path': '{}/'.format(self._path), 'callback': self._show, }, + { + 'method': 'PUT', + 'path': '{}/'.format(self._path), + 'callback': self._update, + }, { 'method': 'PUT', 'path': '{}//secret'.format(self._path), @@ -93,6 +98,20 @@ class ManagementEndpoint: location = '{}{}/{}'.format(self._baseurl, self._path, entity_id) return qvisqve.created_response(entity, location) + def _update(self, content_type, body, **kwargs): + qvisqve.log.log('info', msg_text='Updating', path=self._path) + + entity_id = kwargs['id'] + try: + entity = self._entities.get(entity_id) + except qvisqve.ResourceDoesNotExist as e: + return qvisqve.not_found_response() + + self._entities.create(entity_id, body) + + entity = self._entities.get(entity_id) + return qvisqve.ok_response(entity) + def _list(self, content_type, body, **kwargs): qvisqve.log.log('info', msg_text='Listing', path=self._path) entity_ids = list(self._entities.list()) diff --git a/qvisqvetool b/qvisqvetool index 731606e..bfd92fe 100755 --- a/qvisqvetool +++ b/qvisqvetool @@ -150,6 +150,17 @@ class QvisqveTool(cliapp.Application): self.output.write('Set secret for {}\n'.format(name)) + def cmd_add_callback(self, args): + name, callback = args + + api, token = self.get_api() + + path = '/applications/{}'.format(name) + r = api.GET(token, path) + app = r.json() + app['callbacks'] = app.get('callbacks', []) + [callback] + api.PUT(token, path, json.dumps(app), json_content_type) + def cmd_GET(self, args): api, token = self.get_api() r = api.GET(token, args[0]) @@ -313,6 +324,7 @@ def default_scopes(): scopes.append('uapi_{}_post'.format(resource_type)) scopes.append('uapi_{}_get'.format(resource_type)) scopes.append('uapi_{}_id_get'.format(resource_type)) + scopes.append('uapi_{}_id_put'.format(resource_type)) scopes.append('uapi_{}_id_secret_put'.format(resource_type)) scopes.append('uapi_{}_id_delete'.format(resource_type)) return ' '.join(scopes) -- cgit v1.2.1