From 5196a0bb4a002cede8085c4bc3298d87287007db Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Thu, 27 Mar 2025 14:52:39 -0400 Subject: [PATCH 1/2] modify principal --- clickopsnotifier/clickops.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/clickopsnotifier/clickops.py b/clickopsnotifier/clickops.py index 6c4d9a7..c76b988 100644 --- a/clickopsnotifier/clickops.py +++ b/clickopsnotifier/clickops.py @@ -16,16 +16,34 @@ def __init__(self, event) -> None: @staticmethod def __user_email(event) -> str: - if "userIdentity" in event: - match = re.search( - r"[\w.+-]+@[\w-]+\.[\w.-]+", json.dumps(event["userIdentity"]) - ) - if match is None: - return "Unknown" - else: - return match.group(0) - else: + if "userIdentity" not in event: return "Unknown" + + user_identity = event["userIdentity"] + + # Try to get email from principalId if it exists + if "principalId" in user_identity: + # Handle cases like "AROAXK4KVD27BINQTHSKU:paul@cloudandthings.io" + parts = user_identity["principalId"].split(":") + if len(parts) > 1: + return parts[1] + + # Try to get email from userName if it exists + if "userName" in user_identity: + return user_identity["userName"] + + # Try to get email from arn if it exists + if "arn" in user_identity: + match = re.search(r"[\w.+-]+@[\w-]+\.[\w.-]+", user_identity["arn"]) + if match: + return match.group(0) + + # Try to get email from the entire userIdentity object + match = re.search(r"[\w.+-]+@[\w-]+\.[\w.-]+", json.dumps(user_identity)) + if match: + return match.group(0) + + return "Unknown" @staticmethod def __readonly_event(event) -> bool: From df123416233ebf3e000094a5d9cb6a3db7495ae2 Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Thu, 27 Mar 2025 15:37:32 -0400 Subject: [PATCH 2/2] fix: Modify principal --- build_targets.json | 2 +- clickopsnotifier/clickops.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build_targets.json b/build_targets.json index a1d387a..6d723fb 100644 --- a/build_targets.json +++ b/build_targets.json @@ -20,6 +20,6 @@ "name": "clickopsnotifier", "runtime": "python3.12" } - + ] } diff --git a/clickopsnotifier/clickops.py b/clickopsnotifier/clickops.py index c76b988..787ab88 100644 --- a/clickopsnotifier/clickops.py +++ b/clickopsnotifier/clickops.py @@ -18,31 +18,31 @@ def __init__(self, event) -> None: def __user_email(event) -> str: if "userIdentity" not in event: return "Unknown" - + user_identity = event["userIdentity"] - + # Try to get email from principalId if it exists if "principalId" in user_identity: # Handle cases like "AROAXK4KVD27BINQTHSKU:paul@cloudandthings.io" parts = user_identity["principalId"].split(":") if len(parts) > 1: return parts[1] - + # Try to get email from userName if it exists if "userName" in user_identity: return user_identity["userName"] - + # Try to get email from arn if it exists if "arn" in user_identity: match = re.search(r"[\w.+-]+@[\w-]+\.[\w.-]+", user_identity["arn"]) if match: return match.group(0) - + # Try to get email from the entire userIdentity object match = re.search(r"[\w.+-]+@[\w-]+\.[\w.-]+", json.dumps(user_identity)) if match: return match.group(0) - + return "Unknown" @staticmethod