mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-28 18:08:25 -04:00
tidy up subscription confirmation to SNS notifs
This commit is contained in:
@@ -16,7 +16,7 @@ DEFAULT_MAX_AGE = timedelta(days=10000)
|
||||
@ses_callback_blueprint.route('/notifications/email/ses', methods=['POST'])
|
||||
def email_ses_callback_handler():
|
||||
try:
|
||||
data = sns_notification_handler(request.data, request.headers)
|
||||
data, _ = sns_notification_handler(request.data, request.headers)
|
||||
except InvalidRequest as e:
|
||||
return jsonify(
|
||||
result="error", message=str(e.message)
|
||||
|
||||
@@ -39,13 +39,16 @@ def receive_sns_sms():
|
||||
"""
|
||||
|
||||
try:
|
||||
post_data = sns_notification_handler(request.data, request.headers)
|
||||
data, message_type = sns_notification_handler(request.data, request.headers)
|
||||
except Exception as e:
|
||||
raise InvalidRequest(f"SMS-SNS callback failed with error: {e}", 400)
|
||||
|
||||
message = json.loads(post_data.get("Message"))
|
||||
# TODO remove after smoke testing implemented on prod
|
||||
current_app.logger.info(f'data is: {data}')
|
||||
|
||||
# TODO wrap this up
|
||||
if "inboundMessageId" in message:
|
||||
if message_type != 'SubscriptionConfirmation':
|
||||
message = json.loads(data.get("Message"))
|
||||
# TODO use standard formatting we use for all US numbers
|
||||
inbound_number = message['destinationNumber'].replace('+','')
|
||||
|
||||
@@ -63,7 +66,7 @@ def receive_sns_sms():
|
||||
content = message.get("messageBody")
|
||||
from_number = message.get('originationNumber')
|
||||
provider_ref = message.get('inboundMessageId')
|
||||
date_received = post_data.get('Timestamp')
|
||||
date_received = data.get('Timestamp')
|
||||
provider_name = "sns"
|
||||
|
||||
inbound = create_inbound_sms_object(service,
|
||||
@@ -73,7 +76,7 @@ def receive_sns_sms():
|
||||
date_received=date_received,
|
||||
provider_name=provider_name)
|
||||
|
||||
# TODO ensure inbound sms callback endpoints are accessible and functioning for notify api users, then uncomment the task below
|
||||
# TODO ensure inbound sms callback endpoints are accessible and functioning for notify api users
|
||||
tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
|
||||
|
||||
current_app.logger.debug(
|
||||
|
||||
@@ -58,9 +58,9 @@ def sns_notification_handler(data, headers):
|
||||
current_app.logger.warning(f"Attempt to raise_for_status()SubscriptionConfirmation Type message files for response: {response.text} with error {e}")
|
||||
raise InvalidRequest("SES-SNS callback failed: attempt to raise_for_status()SubscriptionConfirmation Type message failed", 400)
|
||||
current_app.logger.info("SES-SNS auto-confirm subscription callback succeeded")
|
||||
return message
|
||||
return {'subscriptionConfirmed': True}
|
||||
|
||||
# TODO remove after smoke testing on prod is implemented
|
||||
current_app.logger.info(f"SNS message: {message} is a valid message. Attempting to process it now.")
|
||||
|
||||
return message
|
||||
return message, message.get('Type')
|
||||
|
||||
Reference in New Issue
Block a user