From 2a51eb3197507f40f51e50745094bd2645149c30 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 23 Mar 2019 14:27:31 +0200 Subject: Refactore: DRY: move repated operations into methods --- effitool | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/effitool b/effitool index 1954581..3634bd4 100755 --- a/effitool +++ b/effitool @@ -220,13 +220,25 @@ class Session: return sorted(obj.get('resources', [])) def get_client(self, client_id): - return self._api.get_json(self._token, '/clients/{}'.format(client_id)) + return self._api.get_json(self._token, self._get_client_path(client_id)) + + def update_client(self, client_id, client): + self._api.put_json(self._token, self._get_client_path(client_id), client) + + def _get_client_path(self, client_id): + return '/clients/{}'.format(client_id) def allow_scopes(self, client_id, scopes): - path = '/clients/{}'.format(client_id) - client = self._api.get_json(self._token, path) + client = self.get_client(client_id) client['allowed_scopes'] = uniq(client.get('allowed_scopes', []) + scopes) - self._api.put_json(self._token, path, client) + self.update_client(client_id, client) + + def deny_scopes(self, client_id, scopes): + client = self.get_client(client_id) + old_scopes = client.get('allowed_scopes', []) + client['allowed_scopes'] = uniq( + s for s in old_scopes if s not in denied_scopes) + self.update_client(client_id, client) def fetch_member(self, rid): headers = { -- cgit v1.2.1