Skip to content
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

adds logic for gcn.notices. notices, replace healpix_file if present #162

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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
25 changes: 25 additions & 0 deletions gcn_email/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from email.message import EmailMessage
import logging
import os
import json

import boto3
from boto3.dynamodb.conditions import Key
Expand All @@ -27,6 +28,26 @@
log = logging.getLogger(__name__)


REPLACEMENT_TEXT = (
"This content is too large for email. "
"To receive it, see https://gcn.nasa.gov/quickstart"
)


def replace_long_values(data, max_length):
if isinstance(data, dict):
iter = data.items()
elif isinstance(data, list):
iter = enumerate(data)
else:
return
for key, value in iter:
if isinstance(value, str) and len(value) > max_length:
data[key] = REPLACEMENT_TEXT
else:
replace_long_values(value, max_length)


def get_email_notification_subscription_table():
client = boto3.client("ssm")
result = client.get_parameter(
Expand Down Expand Up @@ -85,6 +106,10 @@ def kafka_message_to_email(message):
maintype="application",
subtype="xml",
)
elif topic.startswith("gcn.notices."):
valueJson = json.loads(message.value().decode())
replace_long_values(valueJson, 512)
email_message.set_content(json.dumps(valueJson, indent=4))
else:
email_message.add_attachment(
message.value(),
Expand Down