Check response from version for auth required

If the version call requires auth, we need to catch that to understand
if we should use auth for making requests.  Previously the version api
call may have been open which allowed the CLI to make the call to
determine if auth should be used. If the version call itself requires
auth, then we need to check the response code to enable authentication
for the api requests.

Change-Id: Ie70d601eb4db4909e52e6afaa15cba6195f24045
Related-Bug: #1585137
This commit is contained in:
Alex Schultz
2016-05-24 10:52:31 -06:00
parent 298187d131
commit 72a7cd19e6

View File

@@ -121,9 +121,12 @@ class APIClient(object):
if self._auth_required is None:
url = self.api_root + 'version'
resp = requests.get(url)
self._raise_for_status_with_info(resp)
if resp.status_code == 401:
self._auth_required = True
else:
self._raise_for_status_with_info(resp)
self._auth_required = resp.json().get('auth_required', False)
self._auth_required = resp.json().get('auth_required', False)
return self._auth_required
@property