diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:27:31 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-03-23 14:27:31 +0200 |
commit | 2a51eb3197507f40f51e50745094bd2645149c30 (patch) | |
tree | f0ce4f648a8afcf48b5e758c86e8c2c381d3ed62 | |
parent | 1a8367b5cf4432a3dadbb49f01e4de45c5ff4667 (diff) | |
download | effitool-2a51eb3197507f40f51e50745094bd2645149c30.tar.gz |
Refactore: DRY: move repated operations into methods
-rwxr-xr-x | effitool | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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 = { |