mirror of
https://github.com/GSA/notifications-api.git
synced 2026-03-20 18:20:32 -04:00
fix migrations
This commit is contained in:
@@ -118,6 +118,7 @@ class Config(object):
|
||||
NOTIFY_EMAIL_DOMAIN = 'notify.sandbox.10x.gsa.gov'
|
||||
|
||||
# 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']
|
||||
|
||||
# URL of redis instance
|
||||
|
||||
@@ -27,6 +27,7 @@ INBOUND_SMS_COUNTER = Counter(
|
||||
@receive_notifications_blueprint.route('/notifications/sms/receive/sns', methods=['POST'])
|
||||
def receive_sns_sms():
|
||||
"""
|
||||
Expected value of the 'Message' key in the incoming payload from SNS
|
||||
{
|
||||
"originationNumber":"+14255550182",
|
||||
"destinationNumber":"+12125550101",
|
||||
|
||||
@@ -10,8 +10,7 @@ import six
|
||||
from app import redis_store
|
||||
from app.config import Config
|
||||
|
||||
USE_CACHE = True
|
||||
VALIDATE_ARN = True
|
||||
VALIDATE_SNS_TOPICS = Config.VALIDATE_SNS_TOPICS
|
||||
VALID_SNS_TOPICS = Config.VALID_SNS_TOPICS
|
||||
|
||||
|
||||
@@ -27,19 +26,16 @@ class ValidationError(Exception):
|
||||
|
||||
|
||||
def get_certificate(url):
|
||||
if USE_CACHE:
|
||||
res = redis_store.get(url)
|
||||
if res is not None:
|
||||
return res
|
||||
res = requests.get(url).text
|
||||
redis_store.set(url, res, ex=60 * 60) # 60 minutes
|
||||
res = redis_store.get(url)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return requests.get(url).text
|
||||
res = requests.get(url).text
|
||||
redis_store.set(url, res, ex=60 * 60) # 60 minutes
|
||||
return res
|
||||
|
||||
|
||||
def validate_arn(sns_payload):
|
||||
if VALIDATE_ARN:
|
||||
if VALIDATE_SNS_TOPICS:
|
||||
arn = sns_payload.get('TopicArn')
|
||||
topic_name = arn.split(':')[5]
|
||||
if topic_name not in VALID_SNS_TOPICS:
|
||||
|
||||
@@ -20,6 +20,12 @@ DEFAULT_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID']
|
||||
|
||||
def upgrade():
|
||||
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
|
||||
table_name = 'inbound_numbers'
|
||||
@@ -29,12 +35,10 @@ def upgrade():
|
||||
|
||||
# add the inbound number for the default service to service_sms_senders
|
||||
table_name = 'service_sms_senders'
|
||||
id = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'
|
||||
is_default = 'true'
|
||||
sms_sender = INBOUND_NUMBER
|
||||
inbound_number_id = INBOUND_NUMBER_ID
|
||||
archived = 'false'
|
||||
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}')")
|
||||
select_by_col = 'id'
|
||||
select_by_val = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'
|
||||
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
|
||||
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_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'"
|
||||
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_inbound_number)
|
||||
op.execute(delete_service_inbound_permission)
|
||||
op.execute(recreate_mmg_inbound_number)
|
||||
# pass
|
||||
|
||||
Reference in New Issue
Block a user