]> git.ipfire.org Git - ipfire.org.git/commitdiff
zeiterfassung: Log request/response bodies and allow empty responses
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Dec 2021 10:37:20 +0000 (10:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Dec 2021 10:37:20 +0000 (10:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/zeiterfassung.py

index c999a0ca093ee36f9b7d9c6e23c5b29e72d75322..c156a0a333abd1060f173a0876a63b154bce388e 100644 (file)
@@ -60,6 +60,8 @@ class ZeiterfassungClient(Object):
                logging.debug("Sending request to %s:" % request.url)
                for header in sorted(request.headers):
                        logging.debug(" %s: %s" % (header, request.headers[header]))
+               if request.body:
+                       logging.debug("%s" % json.dumps(kwargs, indent=4, sort_keys=True))
 
                # Send the request
                response = await self.backend.http_client.fetch(request)
@@ -72,15 +74,21 @@ class ZeiterfassungClient(Object):
 
                # Fetch the whole body
                body = response.body
+               if body:
+                       # Decode the JSON response
+                       body = json.loads(body)
+
+                       # Log what we have received in a human-readable way
+                       logging.debug("%s" % json.dumps(body, indent=4, sort_keys=True))
 
                # Fetch the signature
                signature = response.headers.get("Hash")
                if not signature:
                        raise RuntimeError("Could not find signature on response")
 
-               expected_signature = self._sign_response(body)
+               expected_signature = self._sign_response(response.body)
                if not hmac.compare_digest(expected_signature, signature):
                        raise RuntimeError("Invalid signature: %s" % signature)
 
-               # Decode the JSON response
-               return json.loads(body)
+               # Return the body
+               return body