Skip to content

Commit

Permalink
Merge pull request #41 from FireTail-io/fix/response/payload
Browse files Browse the repository at this point in the history
changed response body to use stringified json
  • Loading branch information
rileyfiretail authored Feb 19, 2024
2 parents 41a68b1 + df3ef96 commit 6d6e710
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions firetail/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ def __init__(
number_of_retries=4,
retry_timeout=2,
logs_drain_timeout=5,
scrub_headers=["set-cookie", "cookie", "authorization", "x-api-key", "token", "api-token", "api-key"],
scrub_headers=[
"set-cookie",
"cookie",
"authorization",
"x-api-key",
"token",
"api-token",
"api-key",
],
enrich_oauth=True,
):
self.startThread = True
Expand All @@ -49,7 +57,12 @@ def __init__(
self.LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {"firetailFormat": {"format": '{"additional_field": "value"}', "validate": False}},
"formatters": {
"firetailFormat": {
"format": '{"additional_field": "value"}',
"validate": False,
}
},
"handlers": {
"firetail": {
"class": "firetail.handlers.FiretailHandler",
Expand Down Expand Up @@ -98,7 +111,10 @@ def clean_pii(self, payload):

if self.oauth and self.enrich_oauth:
try:
jwt_decoded = jwt.decode(self.auth_token, options={"verify_signature": False, "verify_exp": False})
jwt_decoded = jwt.decode(
self.auth_token,
options={"verify_signature": False, "verify_exp": False},
)
except jwt.exceptions.DecodeError:
self.oauth = False
if self.oauth:
Expand All @@ -124,7 +140,7 @@ def create(self, response, token, diff=-1, scrub_headers=None, debug=False):
logging.config.dictConfig(self.LOGGING)
self.logger = logging.getLogger("firetailLogger")
try:
response_data = response.get_json() if response.is_json else str(response.response[0].decode("utf-8"))
response_data = response.get_data(as_text=True)
except Exception:
response_data = ""
payload = {
Expand All @@ -137,12 +153,13 @@ def create(self, response, token, diff=-1, scrub_headers=None, debug=False):
"headers": self.format_headers(dict(request.headers)),
"resource": request.url_rule.rule if request.url_rule is not None else request.path,
"method": request.method,
"body": str(request.data),
"body": request.get_data(as_text=True),

"ip": request.remote_addr,
},
"response": {
"statusCode": response.status_code,
"body": str(response_data),
"body": response_data,
"headers": self.format_headers(dict(response.headers)),
},
}
Expand Down

0 comments on commit 6d6e710

Please sign in to comment.