Skip to content

Commit 6d6e710

Browse files
Merge pull request #41 from FireTail-io/fix/response/payload
changed response body to use stringified json
2 parents 41a68b1 + df3ef96 commit 6d6e710

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

firetail/auditor.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ def __init__(
2626
number_of_retries=4,
2727
retry_timeout=2,
2828
logs_drain_timeout=5,
29-
scrub_headers=["set-cookie", "cookie", "authorization", "x-api-key", "token", "api-token", "api-key"],
29+
scrub_headers=[
30+
"set-cookie",
31+
"cookie",
32+
"authorization",
33+
"x-api-key",
34+
"token",
35+
"api-token",
36+
"api-key",
37+
],
3038
enrich_oauth=True,
3139
):
3240
self.startThread = True
@@ -49,7 +57,12 @@ def __init__(
4957
self.LOGGING = {
5058
"version": 1,
5159
"disable_existing_loggers": False,
52-
"formatters": {"firetailFormat": {"format": '{"additional_field": "value"}', "validate": False}},
60+
"formatters": {
61+
"firetailFormat": {
62+
"format": '{"additional_field": "value"}',
63+
"validate": False,
64+
}
65+
},
5366
"handlers": {
5467
"firetail": {
5568
"class": "firetail.handlers.FiretailHandler",
@@ -98,7 +111,10 @@ def clean_pii(self, payload):
98111

99112
if self.oauth and self.enrich_oauth:
100113
try:
101-
jwt_decoded = jwt.decode(self.auth_token, options={"verify_signature": False, "verify_exp": False})
114+
jwt_decoded = jwt.decode(
115+
self.auth_token,
116+
options={"verify_signature": False, "verify_exp": False},
117+
)
102118
except jwt.exceptions.DecodeError:
103119
self.oauth = False
104120
if self.oauth:
@@ -124,7 +140,7 @@ def create(self, response, token, diff=-1, scrub_headers=None, debug=False):
124140
logging.config.dictConfig(self.LOGGING)
125141
self.logger = logging.getLogger("firetailLogger")
126142
try:
127-
response_data = response.get_json() if response.is_json else str(response.response[0].decode("utf-8"))
143+
response_data = response.get_data(as_text=True)
128144
except Exception:
129145
response_data = ""
130146
payload = {
@@ -137,12 +153,13 @@ def create(self, response, token, diff=-1, scrub_headers=None, debug=False):
137153
"headers": self.format_headers(dict(request.headers)),
138154
"resource": request.url_rule.rule if request.url_rule is not None else request.path,
139155
"method": request.method,
140-
"body": str(request.data),
156+
"body": request.get_data(as_text=True),
157+
141158
"ip": request.remote_addr,
142159
},
143160
"response": {
144161
"statusCode": response.status_code,
145-
"body": str(response_data),
162+
"body": response_data,
146163
"headers": self.format_headers(dict(response.headers)),
147164
},
148165
}

0 commit comments

Comments
 (0)