mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
* Process SNS callback, trigger the update notifications celery task * Put autoconfirm into its own method and use in callbacks
26 lines
790 B
Python
26 lines
790 B
Python
from flask import current_app
|
|
import requests
|
|
|
|
|
|
def confirm_subscription(confirmation_request):
|
|
url = confirmation_request.get('SubscribeURL')
|
|
if not url:
|
|
current_app.logger.warning("SubscribeURL does not exist or empty")
|
|
return
|
|
|
|
response = requests.get(url)
|
|
try:
|
|
response.raise_for_status()
|
|
except Exception as e:
|
|
current_app.logger.warning("Response: {}".format(response.text))
|
|
raise e
|
|
|
|
return confirmation_request['TopicArn']
|
|
|
|
|
|
def autoconfirm_subscription(req_json):
|
|
if req_json.get('Type') == 'SubscriptionConfirmation':
|
|
current_app.logger.info("SNS subscription confirmation url: {}".format(req_json['SubscribeURL']))
|
|
subscribed_topic = confirm_subscription(req_json)
|
|
return subscribed_topic
|