mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
fix migrations
This commit is contained in:
@@ -118,6 +118,7 @@ class Config(object):
|
|||||||
NOTIFY_EMAIL_DOMAIN = 'notify.sandbox.10x.gsa.gov'
|
NOTIFY_EMAIL_DOMAIN = 'notify.sandbox.10x.gsa.gov'
|
||||||
|
|
||||||
# AWS SNS topics for delivery receipts
|
# AWS SNS topics for delivery receipts
|
||||||
|
VALIDATE_SNS_TOPICS = True
|
||||||
VALID_SNS_TOPICS = ['notify_test_bounce', 'notify_test_success', 'notify_test_complaint', 'notify_test_sms_inbound']
|
VALID_SNS_TOPICS = ['notify_test_bounce', 'notify_test_success', 'notify_test_complaint', 'notify_test_sms_inbound']
|
||||||
|
|
||||||
# URL of redis instance
|
# URL of redis instance
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ INBOUND_SMS_COUNTER = Counter(
|
|||||||
@receive_notifications_blueprint.route('/notifications/sms/receive/sns', methods=['POST'])
|
@receive_notifications_blueprint.route('/notifications/sms/receive/sns', methods=['POST'])
|
||||||
def receive_sns_sms():
|
def receive_sns_sms():
|
||||||
"""
|
"""
|
||||||
|
Expected value of the 'Message' key in the incoming payload from SNS
|
||||||
{
|
{
|
||||||
"originationNumber":"+14255550182",
|
"originationNumber":"+14255550182",
|
||||||
"destinationNumber":"+12125550101",
|
"destinationNumber":"+12125550101",
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import six
|
|||||||
from app import redis_store
|
from app import redis_store
|
||||||
from app.config import Config
|
from app.config import Config
|
||||||
|
|
||||||
USE_CACHE = True
|
VALIDATE_SNS_TOPICS = Config.VALIDATE_SNS_TOPICS
|
||||||
VALIDATE_ARN = True
|
|
||||||
VALID_SNS_TOPICS = Config.VALID_SNS_TOPICS
|
VALID_SNS_TOPICS = Config.VALID_SNS_TOPICS
|
||||||
|
|
||||||
|
|
||||||
@@ -27,19 +26,16 @@ class ValidationError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
def get_certificate(url):
|
def get_certificate(url):
|
||||||
if USE_CACHE:
|
res = redis_store.get(url)
|
||||||
res = redis_store.get(url)
|
if res is not None:
|
||||||
if res is not None:
|
|
||||||
return res
|
|
||||||
res = requests.get(url).text
|
|
||||||
redis_store.set(url, res, ex=60 * 60) # 60 minutes
|
|
||||||
return res
|
return res
|
||||||
else:
|
res = requests.get(url).text
|
||||||
return requests.get(url).text
|
redis_store.set(url, res, ex=60 * 60) # 60 minutes
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def validate_arn(sns_payload):
|
def validate_arn(sns_payload):
|
||||||
if VALIDATE_ARN:
|
if VALIDATE_SNS_TOPICS:
|
||||||
arn = sns_payload.get('TopicArn')
|
arn = sns_payload.get('TopicArn')
|
||||||
topic_name = arn.split(':')[5]
|
topic_name = arn.split(':')[5]
|
||||||
if topic_name not in VALID_SNS_TOPICS:
|
if topic_name not in VALID_SNS_TOPICS:
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ DEFAULT_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID']
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.get_bind()
|
op.get_bind()
|
||||||
|
|
||||||
|
# delete the previous inbound_number with mmg as provider
|
||||||
|
table_name = 'inbound_numbers'
|
||||||
|
select_by_col = 'number'
|
||||||
|
select_by_val = INBOUND_NUMBER
|
||||||
|
op.execute(f"delete from {table_name} where {select_by_col} = '{select_by_val}'")
|
||||||
|
|
||||||
# add the inbound number for the default service to inbound_numbers
|
# add the inbound number for the default service to inbound_numbers
|
||||||
table_name = 'inbound_numbers'
|
table_name = 'inbound_numbers'
|
||||||
@@ -29,12 +35,10 @@ def upgrade():
|
|||||||
|
|
||||||
# add the inbound number for the default service to service_sms_senders
|
# add the inbound number for the default service to service_sms_senders
|
||||||
table_name = 'service_sms_senders'
|
table_name = 'service_sms_senders'
|
||||||
id = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'
|
|
||||||
is_default = 'true'
|
|
||||||
sms_sender = INBOUND_NUMBER
|
sms_sender = INBOUND_NUMBER
|
||||||
inbound_number_id = INBOUND_NUMBER_ID
|
select_by_col = 'id'
|
||||||
archived = 'false'
|
select_by_val = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'
|
||||||
op.execute(f"insert into {table_name} (id, sms_sender, service_id, is_default, inbound_number_id, created_at, archived) VALUES('{id}', '{INBOUND_NUMBER}', '{DEFAULT_SERVICE_ID}', '{is_default}', '{INBOUND_NUMBER_ID}', 'now()','{archived}')")
|
op.execute(f"update {table_name} set {'sms_sender'}='{sms_sender}' where {select_by_col} = '{select_by_val}'")
|
||||||
|
|
||||||
# add the inbound number for the default service to inbound_numbers
|
# add the inbound number for the default service to inbound_numbers
|
||||||
table_name = 'service_permissions'
|
table_name = 'service_permissions'
|
||||||
@@ -48,7 +52,9 @@ def downgrade():
|
|||||||
delete_sms_sender = f"delete from service_sms_senders where inbound_number_id = '{INBOUND_NUMBER_ID}'"
|
delete_sms_sender = f"delete from service_sms_senders where inbound_number_id = '{INBOUND_NUMBER_ID}'"
|
||||||
delete_inbound_number = f"delete from inbound_numbers where number = '{INBOUND_NUMBER}'"
|
delete_inbound_number = f"delete from inbound_numbers where number = '{INBOUND_NUMBER}'"
|
||||||
delete_service_inbound_permission = f"delete from service_permissions where service_id = '{DEFAULT_SERVICE_ID}' and permission = 'inbound_sms'"
|
delete_service_inbound_permission = f"delete from service_permissions where service_id = '{DEFAULT_SERVICE_ID}' and permission = 'inbound_sms'"
|
||||||
|
recreate_mmg_inbound_number = f"insert into inbound_numbers (id, number, provider, service_id, active, created_at) VALUES('d7aea27f-340b-4428-9b20-4470dd978bda', '{INBOUND_NUMBER}', 'mmg', 'null', 'false', 'now()')"
|
||||||
op.execute(delete_sms_sender)
|
op.execute(delete_sms_sender)
|
||||||
op.execute(delete_inbound_number)
|
op.execute(delete_inbound_number)
|
||||||
op.execute(delete_service_inbound_permission)
|
op.execute(delete_service_inbound_permission)
|
||||||
|
op.execute(recreate_mmg_inbound_number)
|
||||||
# pass
|
# pass
|
||||||
|
|||||||
Reference in New Issue
Block a user