diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:15:35 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:15:35 +0200 |
commit | ac6ff2d9b045da45a2296274ecaa7d353698daae (patch) | |
tree | 183139a5eec6c62ed474bb790a4a5e44d9d4227a /effitool | |
parent | 4740e00d4bba3fa18a4c4fe45ab3d6dece04bf53 (diff) | |
download | effitool-ac6ff2d9b045da45a2296274ecaa7d353698daae.tar.gz |
Refactor: add Session.register_admin_client
Diffstat (limited to 'effitool')
-rwxr-xr-x | effitool | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -202,6 +202,19 @@ class Session: self._api = api self._token = token + def register_admin_client(self, client_id, client_secret): + new_client = { + 'id': client_id, + 'allowed_scopes': ADMIN_SCOPES, + } + self._api.post_json(self._token, '/clients', new_client) + + client_path = '/clients/{}'.format(client_id) + new_secret = { + 'secret': client_secret, + } + self._api.put_json(self._token, '{}/secret'.format(client_path), new_secret) + def fetch_member(self, rid): headers = { 'Muck-Id': rid, @@ -286,23 +299,9 @@ class Tool: print(token) def register_admin_client(self, args): - server = self.get_chosen_server(args) - token = self.get_admin_token(server) - api = HTTPAPI(server['url']) - - new_client = { - 'id': args['client_id'], - 'allowed_scopes': ADMIN_SCOPES, - } - client_path = '/clients/{}'.format(new_client['id']) - api.post_json(token, '/clients', new_client) - - new_secret = { - 'secret': args['client_secret'], - } - api.put_json(token, '{}/secret'.format(client_path), new_secret) - - print('Created new admin client', new_client['id']) + session = self.get_session(args) + session.register_admin_client(args['client_id'], args['client_secret']) + print('Created new admin client', args['client_id']) def list_clients(self, args): server = self.get_chosen_server(args) |