Skip to content

Commit

Permalink
use pinpoint pool for specified templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Apr 9, 2024
1 parent b9d0d3a commit ba16317
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 2 additions & 3 deletions app/clients/sms/aws_pinpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def send_sms(self, to, content, reference, multi=True, sender=None):
messageType = "TRANSACTIONAL"
matched = False

for match in phonenumbers.PhoneNumberMatcher(to, "US"):
for match in phonenumbers.PhoneNumberMatcher(to, "US"): # SJA why is this a loop?
matched = True

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable matched is not used.
to = phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)
destinationNumber = to
Expand All @@ -53,8 +53,7 @@ def send_sms(self, to, content, reference, multi=True, sender=None):
self.current_app.logger.info("AWS Pinpoint request finished in {}".format(elapsed_time))
self.statsd_client.timing("clients.pinpoint.request-time", elapsed_time)
self.statsd_client.incr("clients.pinpoint.success")

return response['MessageId']
return response['MessageId']

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'response' may be used before it is initialized.

Check warning

Code scanning / CodeQL

'break' or 'return' statement in finally Warning

'return' in a finally block will swallow any exceptions raised.

if not matched:
self.statsd_client.incr("clients.pinpoint.error")
Expand Down
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Config(object):
AWS_SES_SECRET_KEY = os.getenv("AWS_SES_SECRET_KEY")
AWS_PINPOINT_REGION = os.getenv("AWS_PINPOINT_REGION", "us-west-2")
AWS_PINPOINT_POOL_ID = os.getenv("AWS_PINPOINT_POOL_ID", None)
AWS_PINPOINT_TEMPLATE_IDS = env.list("AWS_PINPOINT_TEMPLATE_IDS", [])
AWS_US_TOLL_FREE_NUMBER = os.getenv("AWS_US_TOLL_FREE_NUMBER")
CSV_UPLOAD_BUCKET_NAME = os.getenv("CSV_UPLOAD_BUCKET_NAME", "notification-alpha-canada-ca-csv-upload")
ASSET_DOMAIN = os.getenv("ASSET_DOMAIN", "assets.notification.canada.ca")
Expand Down
12 changes: 6 additions & 6 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def send_sms_to_provider(notification):
notification.id,
notification.international,
notification.reply_to_text,
template_id=notification.template_id,
)

template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__
Expand Down Expand Up @@ -334,7 +335,10 @@ def update_notification_to_sending(notification, provider):
dao_update_notification(notification)


def provider_to_use(notification_type, notification_id, international=False, sender=None):
def provider_to_use(notification_type, notification_id, international=False, sender=None, template_id=None):
if notification_type == SMS_TYPE and template_id is not None and str(template_id) in Config.AWS_PINPOINT_TEMPLATE_IDS:
return clients.get_client_by_name_and_type('pinpoint', SMS_TYPE)

active_providers_in_order = [
p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
]
Expand All @@ -343,11 +347,7 @@ def provider_to_use(notification_type, notification_id, international=False, sen
current_app.logger.error("{} {} failed as no active providers".format(notification_type, notification_id))
raise Exception("No active {} providers".format(notification_type))

# return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)

if notification_type == SMS_TYPE:
return clients.get_client_by_name_and_type('pinpoint', notification_type)

return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)


def get_html_email_options(service: Service):
Expand Down

0 comments on commit ba16317

Please sign in to comment.