summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-06-18 20:22:09 +0300
committerLars Wirzenius <liw@liw.fi>2018-06-18 20:22:09 +0300
commit5cff84723324b1fc01ea0962c0412bf7dc6027b4 (patch)
tree017d059127233d26f3984198ff6d0cb0471b7a4d
parente9839fa9e91155f20ffdb48bc6b8d3d672cb8061 (diff)
downloadick2-5cff84723324b1fc01ea0962c0412bf7dc6027b4.tar.gz
Change: look up credentials using controller URL (fallback auth url)
-rw-r--r--NEWS3
-rw-r--r--ick2/client.py3
-rw-r--r--ick2/client_tests.py1
-rwxr-xr-xicktool19
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):