2023-08-10 18:02:45 -04:00
|
|
|
from botocore.config import Config
|
|
|
|
|
|
|
|
|
|
AWS_CLIENT_CONFIG = Config(
|
|
|
|
|
# This config is required to enable S3 to connect to FIPS-enabled
|
|
|
|
|
# endpoints. See https://aws.amazon.com/compliance/fips/ for more
|
|
|
|
|
# information.
|
|
|
|
|
s3={
|
2023-08-29 14:54:30 -07:00
|
|
|
"addressing_style": "virtual",
|
2023-08-10 18:02:45 -04:00
|
|
|
},
|
2023-08-29 14:54:30 -07:00
|
|
|
use_fips_endpoint=True,
|
2023-08-10 18:02:45 -04:00
|
|
|
)
|
2023-08-29 14:54:30 -07:00
|
|
|
STATISTICS_REQUESTED = "requested"
|
|
|
|
|
STATISTICS_DELIVERED = "delivered"
|
|
|
|
|
STATISTICS_FAILURE = "failure"
|
2023-08-10 18:02:45 -04:00
|
|
|
|
|
|
|
|
|
2016-02-15 16:01:14 +00:00
|
|
|
class ClientException(Exception):
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
2016-02-15 16:01:14 +00:00
|
|
|
Base Exceptions for sending notifications that fail
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
|
2016-02-15 16:01:14 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Client(object):
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
2016-02-15 16:01:14 +00:00
|
|
|
Base client for sending notifications.
|
2023-08-29 14:54:30 -07:00
|
|
|
"""
|
|
|
|
|
|
2016-02-15 16:01:14 +00:00
|
|
|
pass
|
2016-03-21 09:20:38 +00:00
|
|
|
|
|
|
|
|
|
2020-11-17 12:35:18 +00:00
|
|
|
class NotificationProviderClients(object):
|
2016-05-06 09:47:06 +01:00
|
|
|
sms_clients = {}
|
|
|
|
|
email_clients = {}
|
|
|
|
|
|
|
|
|
|
def init_app(self, sms_clients, email_clients):
|
|
|
|
|
for client in sms_clients:
|
|
|
|
|
self.sms_clients[client.name] = client
|
|
|
|
|
|
|
|
|
|
for client in email_clients:
|
|
|
|
|
self.email_clients[client.name] = client
|
|
|
|
|
|
2016-05-10 09:04:22 +01:00
|
|
|
def get_sms_client(self, name):
|
2016-05-06 09:47:06 +01:00
|
|
|
return self.sms_clients.get(name)
|
|
|
|
|
|
2016-05-10 09:04:22 +01:00
|
|
|
def get_email_client(self, name):
|
2016-05-06 09:47:06 +01:00
|
|
|
return self.email_clients.get(name)
|
2016-05-10 09:04:22 +01:00
|
|
|
|
|
|
|
|
def get_client_by_name_and_type(self, name, notification_type):
|
2023-08-29 14:54:30 -07:00
|
|
|
assert notification_type in ["email", "sms"] # nosec B101
|
2022-08-19 14:32:11 +00:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
if notification_type == "email":
|
2016-05-10 09:04:22 +01:00
|
|
|
return self.get_email_client(name)
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
if notification_type == "sms":
|
2016-05-10 09:04:22 +01:00
|
|
|
return self.get_sms_client(name)
|