Skip to content

Commit 929d23e

Browse files
committed
refactor(get user info): collect user attributes from token within method
1 parent 156404b commit 929d23e

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

aws_lambda_script/app/resources.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,17 @@ def get_user_attributes(args):
5353
logger.exception("Error verifying token: %s", error)
5454
abort(401, description="Not authorized")
5555

56-
def get_user_information(user_attributes: dict) -> dict:
56+
def get_user_information() -> dict:
5757
"""A function to collect user information from a given Cognito Token.
5858
59-
Args:
60-
user_attributes (dict): The user attributes extracted from the Cognito token.
61-
6259
Returns:
6360
dict: A dictionary containing the user's email and groups.
6461
6562
Raises:
6663
abort: If the email is not found in user attributes.
6764
"""
65+
user_attributes = get_user_attributes(parser.parse_args())
66+
6867
owner_email = user_attributes.get("email", "")
6968
user_groups = user_attributes.get("cognito:groups", [])
7069

@@ -90,8 +89,7 @@ def is_auth_user_in_admin_group(user_groups: list) -> bool:
9089
class User(Resource):
9190
@ns.doc(responses={200: "Success", 401: "Authorization is required"})
9291
def get(self):
93-
user_attributes = get_user_attributes(parser.parse_args())
94-
user_info = get_user_information(user_attributes)
92+
user_info = get_user_information()
9593
owner_email = user_info["email"]
9694
user_groups = user_info["groups"]
9795
return {"email": owner_email, "groups": user_groups}, 200
@@ -396,8 +394,7 @@ def get(self):
396394
},
397395
)
398396
def post(self):
399-
user_attributes = get_user_attributes(parser.parse_args())
400-
user_info = get_user_information(user_attributes)
397+
user_info = get_user_information()
401398
owner_email = user_info["email"]
402399

403400
# Check that required fields are present in the JSON payload
@@ -512,8 +509,7 @@ def get(self, project_name):
512509
},
513510
)
514511
def put(self, project_name):
515-
user_attributes = get_user_attributes(parser.parse_args())
516-
user_info = get_user_information(user_attributes)
512+
user_info = get_user_information()
517513
owner_email = user_info["email"]
518514
user_groups = user_info["groups"]
519515

0 commit comments

Comments
 (0)