# HG changeset patch # User Mads Kiilerich # Date 2020-02-05 13:22:53 # Node ID 8114623895ccc54ba428472900077395d1f0200b # Parent a280c27b3c21113ed847f762c16e727c556d5438 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. diff --git a/kallithea/lib/auth_modules/auth_crowd.py b/kallithea/lib/auth_modules/auth_crowd.py --- a/kallithea/lib/auth_modules/auth_crowd.py +++ b/kallithea/lib/auth_modules/auth_crowd.py @@ -31,7 +31,7 @@ import logging 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 @@ class CrowdServer(object): _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 @@ class KallitheaAuthPlugin(auth_modules.K 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 @@ class KallitheaAuthPlugin(auth_modules.K 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 @@ class KallitheaAuthPlugin(auth_modules.K 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