Merge pull request #11 from 18F/jim/062522/configupdates

clean up config
This commit is contained in:
Jim Moffet
2022-06-25 18:38:52 -07:00
committed by GitHub
5 changed files with 73 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ class TaskNames(object):
class Config(object):
# URL of admin app
ADMIN_BASE_URL = os.getenv('ADMIN_BASE_URL', 'http://localhost:6012')
ADMIN_BASE_URL = os.getenv('ADMIN_BASE_URL')
# URL of api app (on AWS this is the internal api endpoint)
API_HOST_NAME = os.getenv('API_HOST_NAME')
@@ -103,6 +103,9 @@ class Config(object):
# DB conection string
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')
# Redis conection string
REDIS_URL = os.getenv('REDIS_URL')
# AWS SMS
AWS_PINPOINT_REGION = os.getenv("AWS_PINPOINT_REGION", "us-west-2")
AWS_US_TOLL_FREE_NUMBER = os.getenv("AWS_US_TOLL_FREE_NUMBER", "+18446120782")

View File

@@ -105,9 +105,14 @@ def persist_notification(
document_download_count=None,
updated_at=None
):
current_app.logger.info('Presisting notification')
notification_created_at = created_at or datetime.utcnow()
if not notification_id:
notification_id = uuid.uuid4()
current_app.logger.info('Presisting notification with id {}'.format(notification_id))
notification = Notification(
id=notification_id,
template_id=template_id,
@@ -130,6 +135,8 @@ def persist_notification(
document_download_count=document_download_count,
updated_at=updated_at
)
current_app.logger.info('Presisting notification with to address: {}'.format(notification.to))
if notification_type == SMS_TYPE:
formatted_recipient = validate_and_format_phone_number(recipient, international=True)
@@ -139,7 +146,9 @@ def persist_notification(
notification.phone_prefix = recipient_info.country_prefix
notification.rate_multiplier = recipient_info.billable_units
elif notification_type == EMAIL_TYPE:
current_app.logger.info('Presisting notification with type: {}'.format(EMAIL_TYPE))
notification.normalised_to = format_email_address(notification.to)
current_app.logger.info('Presisting notification to formatted email: {}'.format(notification.normalised_to))
elif notification_type == LETTER_TYPE:
notification.postage = postage
notification.international = postage in INTERNATIONAL_POSTAGE_TYPES
@@ -147,17 +156,24 @@ def persist_notification(
# if simulated create a Notification model to return but do not persist the Notification to the dB
if not simulated:
current_app.logger.info('Firing dao_create_notification')
dao_create_notification(notification)
if key_type != KEY_TYPE_TEST and current_app.config['REDIS_ENABLED']:
current_app.logger.info('Redis enabled, querying cache key for service id: {}'.format(service.id))
cache_key = redis.daily_limit_cache_key(service.id)
current_app.logger.info('Redis daily limit cache key: {}'.format(cache_key))
if redis_store.get(cache_key) is None:
current_app.logger.info('Redis daily limit cache key does not exist')
# if cache does not exist set the cache to 1 with an expiry of 24 hours,
# The cache should be set by the time we create the notification
# but in case it is this will make sure the expiry is set to 24 hours,
# where if we let the incr method create the cache it will be set a ttl.
redis_store.set(cache_key, 1, ex=86400)
current_app.logger.info('Set redis daily limit cache key to 1')
else:
current_app.logger.info('Redis daily limit cache key does exist')
redis_store.incr(cache_key)
current_app.logger.info('Redis daily limit cache key has been incremented')
current_app.logger.info(
"{} {} created at {}".format(notification_type, notification_id, notification_created_at)
)

View File

@@ -370,13 +370,19 @@ def send_user_confirm_new_email(user_id):
@user_blueprint.route('/<uuid:user_id>/email-verification', methods=['POST'])
def send_new_user_email_verification(user_id):
current_app.logger.info('Sending email verification for user {}'.format(user_id))
request_json = request.get_json()
# when registering, we verify all users' email addresses using this function
user_to_send_to = get_user_by_id(user_id=user_id)
current_app.logger.info('user_to_send_to is {}'.format(user_to_send_to))
current_app.logger.info('user_to_send_to.email_address is {}'.format(user_to_send_to.email_address))
template = dao_get_template_by_id(current_app.config['NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID'])
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
current_app.logger.info('template.id is {}'.format(template.id))
current_app.logger.info('service.id is {}'.format(service.id))
saved_notification = persist_notification(
template_id=template.id,
@@ -395,18 +401,27 @@ def send_new_user_email_verification(user_id):
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address()
)
current_app.logger.info('Sending notification to queue')
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
current_app.logger.info('Sent notification to queue')
return jsonify({}), 204
@user_blueprint.route('/<uuid:user_id>/email-already-registered', methods=['POST'])
def send_already_registered_email(user_id):
current_app.logger.info('Email already registered for user {}'.format(user_id))
to = email_data_request_schema.load(request.get_json())
current_app.logger.info('To email is {}'.format(to['email']))
template = dao_get_template_by_id(current_app.config['ALREADY_REGISTERED_EMAIL_TEMPLATE_ID'])
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
current_app.logger.info('template.id is {}'.format(template.id))
current_app.logger.info('service.id is {}'.format(service.id))
saved_notification = persist_notification(
template_id=template.id,
@@ -423,8 +438,12 @@ def send_already_registered_email(user_id):
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address()
)
current_app.logger.info('Sending notification to queue')
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
current_app.logger.info('Sent notification to queue')
return jsonify({}), 204

View File

@@ -22,10 +22,12 @@ applications:
FLASK_ENV: production
NOTIFY_ENVIRONMENT: live
API_HOST_NAME: notifications-api.app.cloud.gov
ADMIN_BASE_URL: notifications-admin.app.cloud.gov
API_HOST_NAME: https://notifications-api.app.cloud.gov
ADMIN_BASE_URL: https://notifications-admin.app.cloud.gov
NOTIFICATION_QUEUE_PREFIX: prototype_10x
STATSD_HOST: localhost
INTERNAL_CLIENT_API_KEYS: '{"notify-admin":["dev-notify-secret-key"]}'
# Credentials variables
DANGEROUS_SALT: ((DANGEROUS_SALT))

View File

@@ -3,3 +3,33 @@ SECRET_KEY: "dev-notify-secret-key"
DANGEROUS_SALT: "dev-notify-salt"
AWS_ACCESS_KEY_ID: <replace me>
AWS_SECRET_ACCESS_KEY: <replace me>
ADMIN_BASE_URL: https://notifications-admin.app.cloud.gov
ADMIN_CLIENT_ID: notify-admin
ADMIN_CLIENT_SECRET: dev-notify-secret-key
API_HOST_NAME: https://notifications-api.app.cloud.gov
AWS_ACCESS_KEY_ID: placeholder
AWS_PINPOINT_REGION: us-west-2
AWS_REGION: us-west-2
AWS_SECRET_ACCESS_KEY: placeholder
AWS_US_TOLL_FREE_NUMBER: 18446120782
DANGEROUS_SALT: dev-notify-salt
DVLA_EMAIL_ADDRESSES: []
FIRETEXT_API_KEY: placeholder
FIRETEXT_INBOUND_SMS_AUTH: {}
FIRETEXT_INTERNATIONAL_API_KEY: placeholder
FLASK_APP: application.py
FLASK_ENV: production
INTERNAL_CLIENT_API_KEYS: '{"notify-admin":["dev-notify-secret-key"]}'
MMG_API_KEY: placeholder
MMG_INBOUND_SMS_AUTH: {}
MMG_INBOUND_SMS_USERNAME: {}
NOTIFICATION_QUEUE_PREFIX: prototype_10x
NOTIFY_APP_NAME: api
NOTIFY_EMAIL_DOMAIN: dispostable.com
NOTIFY_ENVIRONMENT: live
NOTIFY_LOG_PATH: /home/vcap/logs/app.log
ROUTE_SECRET_KEY_1: dev-route-secret-key-1
ROUTE_SECRET_KEY_2: dev-route-secret-key-2
SECRET_KEY: dev-notify-secret-key
STATSD_HOST: localhost