From ac8d8d3c299547214496708da7345a6cb34f7aef Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Sat, 25 Jun 2022 18:36:39 -0700 Subject: [PATCH] clean up config --- app/config.py | 5 +++- app/delivery/send_to_providers.py | 4 +-- app/notifications/process_notifications.py | 16 ++++++++++++ app/user/rest.py | 19 ++++++++++++++ manifest.yml | 6 +++-- varsfile.sample | 30 ++++++++++++++++++++++ 6 files changed, 75 insertions(+), 5 deletions(-) diff --git a/app/config.py b/app/config.py index 00dc33d15..7bba7df11 100644 --- a/app/config.py +++ b/app/config.py @@ -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") diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 0dbb66f9e..2aeb4411d 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -169,9 +169,9 @@ provider_cache = TTLCache(maxsize=8, ttl=10) @cached(cache=provider_cache) def provider_to_use(notification_type, international=True): - international = True # TODO: remove or resolve the functionality of this + international = False # TODO: remove or resolve the functionality of this active_providers = [ - p for p in get_provider_details_by_notification_type(notification_type, international) if p.active + p for p in get_provider_details_by_notification_type(notification_type, international) if p.active and p.identifier not in ['firetext','mmg'] ] if not active_providers: diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py index 4aea1ec05..673e7ff49 100644 --- a/app/notifications/process_notifications.py +++ b/app/notifications/process_notifications.py @@ -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) ) diff --git a/app/user/rest.py b/app/user/rest.py index e72dbb7ec..b0832e6a8 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -370,13 +370,19 @@ def send_user_confirm_new_email(user_id): @user_blueprint.route('//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('//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 diff --git a/manifest.yml b/manifest.yml index 95a07af99..425440144 100644 --- a/manifest.yml +++ b/manifest.yml @@ -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)) diff --git a/varsfile.sample b/varsfile.sample index 3fc7f2baa..a13097bab 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -3,3 +3,33 @@ SECRET_KEY: "dev-notify-secret-key" DANGEROUS_SALT: "dev-notify-salt" AWS_ACCESS_KEY_ID: AWS_SECRET_ACCESS_KEY: + +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