@@ -174,14 +174,37 @@ def generate_webhook_test_payload(webhook_type: WebhookType, token_type: TokenTy
174174 timestamp = datetime .now (),
175175 )
176176 return TokenAlertDetailsDiscord (embeds = [embeds ])
177- # Fix initial test webhook
178- # elif webhook_type == WebhookType.MS_TEAMS:
179- # section = MsTeamsTitleSection(
180- # activityTitle="<b>Validating new Canarytokens webhook</b>"
181- # )
182- # return TokenAlertDetailsMsTeams(
183- # summary="Validating new Canarytokens webhook", sections=[section]
184- # )
177+ elif webhook_type == WebhookType .MS_TEAMS :
178+ columns = [
179+ MsTeamsColumn (
180+ items = [
181+ MsTeamsColumnItem (
182+ type = "TextBlock" ,
183+ text = "Validating new Canarytokens webhook" ,
184+ weight = "Bolder" ,
185+ size = "Large" ,
186+ )
187+ ]
188+ )
189+ ]
190+
191+ return TokenAlertDetailsMsTeams (
192+ attachments = [
193+ TokenAlertAttachmentMsTeams (
194+ content = TokenAlertContentMsTeams (
195+ body = [MsTeamsColumnSet (columns = columns )],
196+ actions = [
197+ MsTeamsAction (
198+ type = "Action.OpenUrl" ,
199+ title = "Canarytokens.org" ,
200+ url = "https://canarytokens.org/nest/" ,
201+ iconUrl = CANARY_LOGO_ROUND_PUBLIC_URL ,
202+ )
203+ ],
204+ )
205+ )
206+ ]
207+ )
185208 elif webhook_type == WebhookType .GENERIC :
186209 return TokenAlertDetails (
187210 manage_url = WEBHOOK_TEST_URL ,
@@ -798,10 +821,10 @@ def _format_as_ms_teams_canaryalert(
798821 MsTeamsFactSet (facts = facts ),
799822 ]
800823
801- return TokenAlertAttachmentMsTeams (
824+ return TokenAlertDetailsMsTeams (
802825 attachments = [
803- TokenAlertContentMsTeams (
804- content = TokenAlertDetailsMsTeams (
826+ TokenAlertAttachmentMsTeams (
827+ content = TokenAlertContentMsTeams (
805828 body = body ,
806829 actions = [
807830 MsTeamsAction (
@@ -822,34 +845,68 @@ def _format_as_ms_teams_canaryalert(
822845 )
823846
824847
825- # def _format_as_ms_teams_token_exposed(
826- # details: TokenExposedDetails,
827- # ) -> TokenAlertDetailsMsTeams:
828- # facts = [
829- # MsTeamsFact(name="Key ID", value=details.key_id),
830- # MsTeamsFact(name="Token Reminder", value=details.memo),
831- # MsTeamsFact(
832- # name="Key exposed at",
833- # value=details.exposed_time.strftime("%Y-%m-%d %H:%M:%S (UTC)"),
834- # ),
835- # MsTeamsFact(name="Key exposed here", value=details.public_location),
836- # ]
837-
838- # sections = [
839- # MsTeamsTitleSection(activityTitle="<b>Canarytoken Exposed</b>"),
840- # MsTeamsDetailsSection(
841- # facts=facts, text=_get_exposed_token_description(details.token_type)
842- # ),
843- # ]
844-
845- # return TokenAlertDetailsMsTeams(
846- # summary="Canarytoken Exposed",
847- # themeColor=HexColor.WARNING.value_without_hash,
848- # sections=sections,
849- # potentialAction=[
850- # MsTeamsPotentialAction(name="Manage token", target=[details.manage_url])
851- # ],
852- # )
848+ def _format_as_ms_teams_token_exposed (
849+ details : TokenExposedDetails ,
850+ ) -> TokenAlertDetailsMsTeams :
851+ columns = [
852+ MsTeamsColumn (
853+ items = [
854+ MsTeamsColumnItem (
855+ type = "Image" , url = CANARY_LOGO_ROUND_PUBLIC_URL , size = "Medium"
856+ )
857+ ]
858+ ),
859+ MsTeamsColumn (
860+ items = [
861+ MsTeamsColumnItem (
862+ type = "TextBlock" ,
863+ text = "Canarytoken Exposed" ,
864+ weight = "Bolder" ,
865+ size = "ExtraLarge" ,
866+ )
867+ ]
868+ ),
869+ ]
870+
871+ text = MsTeamsTextblock (text = _get_exposed_token_description (details .token_type ))
872+
873+ facts = [
874+ MsTeamsFact (title = "Key ID" , value = details .key_id ),
875+ MsTeamsFact (title = "Token Reminder" , value = details .memo ),
876+ MsTeamsFact (
877+ title = "Key exposed at" ,
878+ value = details .exposed_time .strftime ("%Y-%m-%d %H:%M:%S (UTC)" ),
879+ ),
880+ MsTeamsFact (title = "Key exposed here" , value = details .public_location ),
881+ ]
882+
883+ body : list [Union [MsTeamsColumnSet , MsTeamsTextblock , MsTeamsFactSet ]] = [
884+ MsTeamsColumnSet (columns = columns ),
885+ text ,
886+ MsTeamsFactSet (facts = facts ),
887+ ]
888+ return TokenAlertDetailsMsTeams (
889+ attachments = [
890+ TokenAlertAttachmentMsTeams (
891+ content = TokenAlertContentMsTeams (
892+ body = body ,
893+ actions = [
894+ MsTeamsAction (
895+ type = "Action.OpenUrl" ,
896+ title = "⚙️ Manage token" ,
897+ url = details .manage_url ,
898+ ),
899+ MsTeamsAction (
900+ type = "Action.OpenUrl" ,
901+ title = "Canarytokens.org" ,
902+ url = "https://canarytokens.org/nest/" ,
903+ iconUrl = CANARY_LOGO_ROUND_PUBLIC_URL ,
904+ ),
905+ ],
906+ )
907+ )
908+ ]
909+ )
853910
854911
855912def _data_to_ms_teams_facts (data : dict [str , Union [str , dict ]]) -> list [MsTeamsFact ]:
@@ -865,6 +922,12 @@ def _data_to_ms_teams_facts(data: dict[str, Union[str, dict]]) -> list[MsTeamsFa
865922 return facts
866923
867924
925+ class MsTeamsTextblock (BaseModel ):
926+ type : str = "TextBlock"
927+ text : str
928+ wrap : bool = True
929+
930+
868931class MsTeamsAction (BaseModel ):
869932 type : str
870933 title : str
@@ -902,23 +965,25 @@ class MsTeamsColumnSet(BaseModel):
902965 columns : Optional [list [MsTeamsColumn ]] = None
903966
904967
905- class TokenAlertDetailsMsTeams (BaseModel ):
968+ class TokenAlertContentMsTeams (BaseModel ):
906969 schema_ : str = Field (
907970 "https://adaptivecards.io/schemas/adaptive-card.json" , alias = "$schema"
908971 )
909972 type : str = "AdaptiveCard"
910973 version : str = "1.5"
911- body : Optional [list [Union [MsTeamsColumnSet , MsTeamsFactSet ]]] = None
974+ body : Optional [
975+ list [Union [MsTeamsColumnSet , MsTeamsFactSet , MsTeamsTextblock ]]
976+ ] = None
912977 actions : Optional [list [MsTeamsAction ]] = None
913978
914979
915- class TokenAlertContentMsTeams (BaseModel ):
980+ class TokenAlertAttachmentMsTeams (BaseModel ):
916981 contentType : str = "application/vnd.microsoft.teams.card.o365connector"
917- content : TokenAlertDetailsMsTeams
982+ content : TokenAlertContentMsTeams
918983
919984
920- class TokenAlertAttachmentMsTeams (BaseModel ):
921- attachments : list [TokenAlertContentMsTeams ]
985+ class TokenAlertDetailsMsTeams (BaseModel ):
986+ attachments : list [TokenAlertAttachmentMsTeams ]
922987
923988 def json_safe_dict (self ) -> dict [str , str ]:
924989 return self .dict (by_alias = True , exclude_none = True )
0 commit comments