Skip to content

Commit afbf471

Browse files
committed
feat: Refactor claims extraction to use decode_claims function across multiple handlers
1 parent 73cdf47 commit afbf471

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

lambda/activitylogs/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.activitylogs import ActivityLog
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Authorizer event: {event}")
4040
logger.debug(f"Authorizer context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

lambda/incidents/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.incidents import Incident
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Incidents event: {event}")
4040
logger.debug(f"Incidents context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

lambda/locations/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.locations import Location
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Locations event: {event}")
4040
logger.debug(f"Locations context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

lambda/organizations/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
99
from EventCoord.launchdarkly.flags import Flags
1010
from EventCoord.models.organizations import Organization
11-
from EventCoord.utils.response import build_response
11+
from EventCoord.utils.response import build_response, decode_claims
1212
from aws_xray_sdk.core import patch_all, xray_recorder
1313

1414
patch_all() # Automatically patches boto3, requests, etc.
@@ -40,7 +40,7 @@ def lambda_handler(
4040
) -> APIGatewayProxyResponseV2:
4141
logger.debug(f"Organizations event: {event}")
4242
logger.debug(f"Organizations context: {context}")
43-
claims = event.get('requestContext', {}).get('authorizer', {})
43+
claims = decode_claims(event)
4444
if claims is None:
4545
claims = {}
4646
elif not isinstance(claims, dict):

lambda/periods/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.periods import Period
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Periods event: {event}")
4040
logger.debug(f"Periods context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

lambda/radios/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.radios import Radio
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Radios event: {event}")
4040
logger.debug(f"Radios context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

lambda/reports/handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from aws_lambda_typing.events import APIGatewayProxyEventV2
1111
from aws_lambda_typing.context import Context as LambdaContext
1212
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
13-
from EventCoord.utils.response import build_response
13+
from EventCoord.utils.response import build_response, decode_claims
1414
from aws_xray_sdk.core import patch_all, xray_recorder
1515

1616
patch_all() # Automatically patches boto3, requests, etc.
@@ -92,19 +92,19 @@ def lambda_handler(
9292
) -> APIGatewayProxyResponseV2:
9393
logger.debug(f"Reports event: {event}")
9494
logger.debug(f"Reports context: {context}")
95-
claims = event.get('requestContext', {}).get('authorizer', {})
95+
claims = decode_claims(event)
9696
if claims is None:
9797
claims = {}
9898
elif not isinstance(claims, dict):
9999
try:
100100
claims = dict(claims)
101101
except Exception:
102102
claims = {}
103-
org_id = claims.get('hd')
103+
org_id = claims.get('org_id')
104104
if not org_id:
105105
return build_response(
106106
403,
107-
{'error': 'Missing organization (hd claim) in token'},
107+
{'error': 'Missing organization (org_id claim) in token'},
108108
headers=cors_headers
109109
)
110110

lambda/units/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aws_lambda_typing.responses import APIGatewayProxyResponseV2
77
from EventCoord.launchdarkly.flags import Flags
88
from EventCoord.models.units import Unit
9-
from EventCoord.utils.response import build_response
9+
from EventCoord.utils.response import build_response, decode_claims
1010
from aws_xray_sdk.core import patch_all, xray_recorder
1111

1212
patch_all() # Automatically patches boto3, requests, etc.
@@ -38,7 +38,7 @@ def lambda_handler(
3838
) -> APIGatewayProxyResponseV2:
3939
logger.debug(f"Units event: {event}")
4040
logger.debug(f"Units context: {context}")
41-
claims = event.get('requestContext', {}).get('authorizer', {})
41+
claims = decode_claims(event)
4242
if claims is None:
4343
claims = {}
4444
elif not isinstance(claims, dict):

0 commit comments

Comments
 (0)