diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:19:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:19:49 +0200 |
commit | ce861a21c9021e0f467e862a1bae7525a7fd5012 (patch) | |
tree | 9ac8f2152f72de233fc6e74d5ff6ceacf068b87b | |
parent | ac6ff2d9b045da45a2296274ecaa7d353698daae (diff) | |
download | effitool-ce861a21c9021e0f467e862a1bae7525a7fd5012.tar.gz |
Refacor: add Session.list_clients and get_client
-rwxr-xr-x | effitool | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -215,6 +215,13 @@ class Session: } self._api.put_json(self._token, '{}/secret'.format(client_path), new_secret) + def list_clients(self): + obj = self._api.get_list(self._token, '/clients') + return sorted(obj.get('resources', [])) + + def get_client(self, client_id): + return self._api.get_json(self._token, '/clients/{}'.format(client_id)) + def fetch_member(self, rid): headers = { 'Muck-Id': rid, @@ -304,19 +311,13 @@ class Tool: print('Created new admin client', args['client_id']) def list_clients(self, args): - server = self.get_chosen_server(args) - token = self.get_admin_token(server) - api = HTTPAPI(server['url']) - obj = api.get_list(token, '/clients') - for name in sorted(obj.get('resources', [])): + session = self.get_session(args) + for name in session.list_clients(): print(name) - - def show_clients(self, args): - server = self.get_chosen_server(args) - token = self.get_admin_token(server) - api = HTTPAPI(server['url']) - obj = api.get_list(token, '/clients') - client = api.get_json(token, '/clients/{}'.format(args['client-name'])) + + def show_client(self, args): + session = self.get_session(args) + client = session.get_client(args['client-name']) del client['hashed_secret'] for scope in client.get('allowed_scopes', []): print(scope) @@ -414,7 +415,7 @@ def process_args(config): ('--client-secret', {'required':True}), ]), ('list-clients', tool.list_clients, []), - ('show-client', tool.show_clients, [ + ('show-client', tool.show_client, [ ('client-name', {}), ]), ('allow-scope', tool.allow_scope, [ |