Skip to content

Commit

Permalink
Remove body_length conditional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcthinkst committed Nov 18, 2024
1 parent 88360d1 commit 07735d9
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions canarytokens/channel_output_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,53 +381,39 @@ def format_report_html(
return minify_html.minify(rendered_html)

@staticmethod
def format_report_text(details: TokenAlertDetails, body_length: int = 999999999):
def format_report_text(details: TokenAlertDetails):
"""Returns a string containing an incident report in text,
suitable for emailing"""

if body_length <= 140:
body = """Canarydrop@{time} via {channel_name}: """.format(
channel_name=details.channel, time=details.time
)
capacity = 140 - len(body)
body += details.memo[:capacity]
else:
additional_data = "\n" + "\n".join(
f"{k}: {v}" for k, v in details.additional_data.items()
)
body = textwrap.dedent(
f"""
One of your canarydrops was triggered.
Channel: {details.channel}
Time : {details.time}
Memo : {details.memo}{additional_data}
Manage your settings for this Canarydrop:
{details.manage_url}
"""
).strip()
additional_data = "\n" + "\n".join(
f"{k}: {v}" for k, v in details.additional_data.items()
)
body = textwrap.dedent(
f"""
One of your canarydrops was triggered.
Channel: {details.channel}
Time : {details.time}
Memo : {details.memo}{additional_data}
Manage your settings for this Canarydrop:
{details.manage_url}
"""
).strip()
return body

@staticmethod
def format_token_exposed_text(
details: TokenExposedDetails, body_length: int = 999999999
):
def format_token_exposed_text(details: TokenExposedDetails):
"""Returns a string containing an incident report in text,
suitable for emailing"""
if body_length <= 140:
body = f"Canarytoken exposed on the internet @ {details.exposed_time}: "
capacity = 140 - len(body)
body += details.memo[:capacity]
else:
body = textwrap.dedent(
f"""
One of your Canarytokens was exposed on the internet.
Location: {details.public_location or "unknown"}
Time : {details.exposed_time}
Memo : {details.memo}
Manage your settings for this Canarydrop:
{details.manage_url}
"""
).strip()
body = textwrap.dedent(
f"""
One of your Canarytokens was exposed on the internet.
Location: {details.public_location or "unknown"}
Time : {details.exposed_time}
Memo : {details.memo}
Manage your settings for this Canarydrop:
{details.manage_url}
"""
).strip()
return body

@staticmethod
Expand Down

0 comments on commit 07735d9

Please sign in to comment.