Skip to content

Commit 2e19091

Browse files
SRAlexanderScott Alexander
andauthored
removed splunk logging due to correlation id bug (#137)
* Added Splunk logging required decorator to Token handler * Added additional None checks to potential breaking areas --------- Co-authored-by: Scott Alexander <[email protected]>
1 parent 2da25a3 commit 2e19091

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lambdas/handlers/token_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
OrganisationNotFoundException,
1818
TooManyOrgsException)
1919
from utils.lambda_response import ApiGatewayResponse
20+
from utils.decorators.set_audit_arg import set_request_context_for_logging
2021

2122
logger = LoggingService(__name__)
2223

2324

2425
token_handler_ssm_service = TokenHandlerSSMService()
2526

26-
27+
@set_request_context_for_logging
2728
def lambda_handler(event, context):
2829
oidc_service = OidcService()
2930
ods_api_service = OdsApiService()

lambdas/utils/decorators/set_audit_arg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def interceptor(event, context):
1010
request_context.authorization = None
1111
if event.get("headers"):
1212
token = event.get("headers").get("Authorization")
13-
decoded_token = jwt.decode(
14-
token, algorithms=["RS256"], options={"verify_signature": False}
15-
)
16-
request_context.authorization = decoded_token
13+
if token:
14+
decoded_token = jwt.decode(
15+
token, algorithms=["RS256"], options={"verify_signature": False}
16+
)
17+
request_context.authorization = decoded_token
1718
return lambda_func(event, context)
1819

1920
return interceptor

lambdas/utils/logging_formatter.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66

77
class LoggingFormatter(logging.Formatter):
88
def format(self, record: logging.LogRecord) -> str:
9+
10+
auth = "No Auth"
11+
if request_context.authorization is not None:
12+
auth = request_context.authorization
13+
914
s = super().format(record)
1015
d = {
1116
"correlation_id": request_context.request_id,
12-
"auth": request_context.authorization,
13-
**record.__dict__.get("custom_args", {}),
14-
"Message": s,
17+
"auth": auth,
18+
"Message": s
1519
}
20+
21+
if record.__dict__.get("custom_args", {}) is not None:
22+
d.update(record.__dict__.get("custom_args", {}))
23+
1624
return json.dumps(d)

0 commit comments

Comments
 (0)