Skip to content

fix: Modify principal #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"name": "clickopsnotifier",
"runtime": "python3.12"
}

]
}
36 changes: 27 additions & 9 deletions clickopsnotifier/clickops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,35 @@ 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:
if "readOnly" in event:
Expand Down