From 5cff84723324b1fc01ea0962c0412bf7dc6027b4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 18 Jun 2018 20:22:09 +0300 Subject: Change: look up credentials using controller URL (fallback auth url) --- NEWS | 3 +++ ick2/client.py | 3 +++ ick2/client_tests.py | 1 + icktool | 19 +++++++++++++------ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 2d33e3d..0ecabc5 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,9 @@ Version 0.52.1+git, not yet released * Icktool shows a more humane error message if getting a token fails, instead of a Python stack trace. +* Icktool now looks for credentials using both the controller URL, and + the authentication URL. + Version 0.52.1, released 2018-06-12 ---------------------------------- diff --git a/ick2/client.py b/ick2/client.py index 2b1318c..2d54bc8 100644 --- a/ick2/client.py +++ b/ick2/client.py @@ -150,6 +150,9 @@ class ControllerClient: def set_controller_url(self, url): self._url = url + def get_controller_url(self): # pragma: no cover + return self._url + def set_token(self, token): self._api.set_token(token) diff --git a/ick2/client_tests.py b/ick2/client_tests.py index f164e6a..adba2dc 100644 --- a/ick2/client_tests.py +++ b/ick2/client_tests.py @@ -359,6 +359,7 @@ class FakeResponse: 'Content-Type': content_type, } self.content = body + self.text = body @property def ok(self): diff --git a/icktool b/icktool index 0866661..39def14 100755 --- a/icktool +++ b/icktool @@ -165,12 +165,13 @@ class Icktool(cliapp.Application): return api def _new_auth(self, api): - url = api.get_auth_url() - client_id, client_secret = self._get_client_creds(url) + c_url = api.get_controller_url() + auth_url = api.get_auth_url() + client_id, client_secret = self._get_client_creds(c_url, auth_url) ac = ick2.AuthClient() ac.set_http_api(api.get_http_api()) - ac.set_auth_url(url) + ac.set_auth_url(auth_url) ac.set_client_creds(client_id, client_secret) return ac @@ -185,11 +186,17 @@ class Icktool(cliapp.Application): sys.stderr.write('Error getting token: %s\n' % str(e)) sys.exit(1) - def _get_client_creds(self, url): + def _get_client_creds(self, controller_url, auth_url): cp = configparser.ConfigParser() cp.read(self.settings['secrets']) - client_id = cp.get(url, 'client_id') - client_secret = cp.get(url, 'client_secret') + + if cp.has_section(controller_url): + section = controller_url + else: + section = auth_url + + client_id = cp.get(section, 'client_id') + client_secret = cp.get(section, 'client_secret') return client_id, client_secret def _prettyson(self, obj): -- cgit v1.2.1