Mercurial > kallithea
changeset 8167:8114623895cc
auth: make crowd logging simpler
There is no point in creating dicts and then logging them as json. Also, json
can't handle py3 bytes and it would fail on py3. (ext_json could perhaps handle
bytes, but it seems better to keep it simple and explicit.)
If the default repr isn't good enough, it would be better to use pprint. But
repr is good enough.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 05 Feb 2020 13:22:53 +0100 |
parents | a280c27b3c21 |
children | 7d5dfe117d0f |
files | kallithea/lib/auth_modules/auth_crowd.py |
diffstat | 1 files changed, 6 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/auth_modules/auth_crowd.py Tue Feb 04 03:27:17 2020 +0100 +++ b/kallithea/lib/auth_modules/auth_crowd.py Wed Feb 05 13:22:53 2020 +0100 @@ -31,7 +31,7 @@ import urllib2 from kallithea.lib import auth_modules, ext_json -from kallithea.lib.compat import formatted_json, hybrid_property +from kallithea.lib.compat import hybrid_property from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_bytes @@ -87,9 +87,7 @@ _headers["Authorization"] = "Basic %s" % authstring if headers: _headers.update(headers) - log.debug("Sent crowd: \n%s", - formatted_json({"url": url, "body": body, - "headers": _headers})) + log.debug("Sent to crowd at %s:\nHeaders: %s\nBody:\n%s", url, _headers, body) req = urllib2.Request(url, body, _headers) if method: req.get_method = lambda: method @@ -210,11 +208,11 @@ log.debug('Empty username or password skipping...') return None - log.debug("Crowd settings: \n%s", formatted_json(settings)) + log.debug("Crowd settings: %s", settings) server = CrowdServer(**settings) server.set_credentials(settings["app_name"], settings["app_password"]) crowd_user = server.user_auth(username, password) - log.debug("Crowd returned: \n%s", formatted_json(crowd_user)) + log.debug("Crowd returned: %s", crowd_user) if not crowd_user["status"]: log.error('Crowd authentication as %s returned no status', username) return None @@ -224,7 +222,7 @@ return None res = server.user_groups(crowd_user["name"]) - log.debug("Crowd groups: \n%s", formatted_json(res)) + log.debug("Crowd groups: %s", res) crowd_user["groups"] = [x["name"] for x in res["groups"]] # old attrs fetched from Kallithea database @@ -247,7 +245,7 @@ for group in settings["admin_groups"].split(","): if group in user_data["groups"]: user_data["admin"] = True - log.debug("Final crowd user object: \n%s", formatted_json(user_data)) + log.debug("Final crowd user object: %s", user_data) log.info('user %s authenticated correctly', user_data['username']) return user_data