diff --git a/reflex_core/requirements.txt b/reflex_core/requirements.txt index 30ddf82..ea948fa 100644 --- a/reflex_core/requirements.txt +++ b/reflex_core/requirements.txt @@ -1 +1,2 @@ boto3 +requests diff --git a/reflex_core/subscription_confirmation.py b/reflex_core/subscription_confirmation.py new file mode 100644 index 0000000..154867d --- /dev/null +++ b/reflex_core/subscription_confirmation.py @@ -0,0 +1,30 @@ +""" Module for the SubscriptionConfirmation class """ +import logging +import os + +import requests + +LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper() +LOGGER = logging.getLogger() +LOGGER.setLevel(LOG_LEVEL) + + +def is_subscription_confirmation(event): + """Determines if event payload is for confirming subscriptions.""" + return event.get("Type") == "SubscriptionConfirmation" + + +def confirm_subscription(event): + """Respond to an outside subscription notification. + + For SNS topic subscriptions that require manual subscription confirmations, this + function will parse the event message and make the request to the confirmation + url. + + Returns: + None + """ + + subscription_url = event.get("SubscribeURL") + LOGGER.info("Confirming subscription by requesting URL: %s", subscription_url) + requests.get(subscription_url) diff --git a/setup.py b/setup.py index b02aef4..3ca5604 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ long_description_content_type="text/markdown", url="https://github.com/pangolock/reflex-core", packages=setuptools.find_packages(), - install_requires=["boto3"], + install_requires=["boto3", "requests"], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",