mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-callback-receipt-1
This commit is contained in:
@@ -388,6 +388,7 @@ class Staging(Config):
|
||||
FROM_NUMBER = 'stage'
|
||||
API_RATE_LIMIT_ENABLED = True
|
||||
CHECK_PROXY_HEADER = True
|
||||
REDIS_ENABLED = False
|
||||
|
||||
API_KEY_LIMITS = {
|
||||
KEY_TYPE_TEAM: {
|
||||
@@ -416,7 +417,7 @@ class Live(Config):
|
||||
FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID = 'ba9e1789-a804-40b8-871f-cc60d4c1286f'
|
||||
PERFORMANCE_PLATFORM_ENABLED = True
|
||||
API_RATE_LIMIT_ENABLED = True
|
||||
CHECK_PROXY_HEADER = False
|
||||
CHECK_PROXY_HEADER = True
|
||||
|
||||
|
||||
class CloudFoundryConfig(Config):
|
||||
|
||||
@@ -178,6 +178,7 @@ INTERNATIONAL_SMS_TYPE = 'international_sms'
|
||||
INBOUND_SMS_TYPE = 'inbound_sms'
|
||||
SCHEDULE_NOTIFICATIONS = 'schedule_notifications'
|
||||
EMAIL_AUTH = 'email_auth'
|
||||
LETTERS_AS_PDF = 'letters_as_pdf'
|
||||
|
||||
SERVICE_PERMISSION_TYPES = [
|
||||
EMAIL_TYPE,
|
||||
@@ -187,6 +188,7 @@ SERVICE_PERMISSION_TYPES = [
|
||||
INBOUND_SMS_TYPE,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
EMAIL_AUTH,
|
||||
LETTERS_AS_PDF,
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from notifications_utils.recipients import (
|
||||
from app import redis_store
|
||||
from app.celery import provider_tasks
|
||||
from app.config import QueueNames
|
||||
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_TEST,
|
||||
@@ -26,6 +27,8 @@ from app.dao.notifications_dao import (
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_created_scheduled_notification
|
||||
)
|
||||
|
||||
from app.statsd_decorators import statsd
|
||||
from app.v2.errors import BadRequestError
|
||||
from app.utils import get_template_instance, cache_key_for_service_template_counter, convert_bst_to_utc
|
||||
|
||||
@@ -43,6 +46,7 @@ def check_placeholders(template_object):
|
||||
raise BadRequestError(fields=[{'template': message}], message=message)
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def persist_notification(
|
||||
*,
|
||||
template_id,
|
||||
@@ -112,6 +116,7 @@ def persist_notification(
|
||||
return notification
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def send_notification_to_queue(notification, research_mode, queue=None):
|
||||
if research_mode or notification.key_type == KEY_TYPE_TEST:
|
||||
queue = QueueNames.RESEARCH_MODE
|
||||
|
||||
@@ -14,6 +14,7 @@ from app.models import (
|
||||
KEY_TYPE_TEST, KEY_TYPE_TEAM, SCHEDULE_NOTIFICATIONS
|
||||
)
|
||||
from app.service.utils import service_allowed_to_send_to
|
||||
from app.statsd_decorators import statsd
|
||||
from app.v2.errors import TooManyRequestsError, BadRequestError, RateLimitError
|
||||
from app import redis_store
|
||||
from app.notifications.process_notifications import create_content_for_notification
|
||||
@@ -22,7 +23,7 @@ from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
|
||||
|
||||
def check_service_over_api_rate_limit(service, api_key):
|
||||
if current_app.config['API_RATE_LIMIT_ENABLED']:
|
||||
if current_app.config['API_RATE_LIMIT_ENABLED'] and current_app.config['REDIS_ENABLED']:
|
||||
cache_key = rate_limit_cache_key(service.id, api_key.key_type)
|
||||
rate_limit = current_app.config['API_KEY_LIMITS'][api_key.key_type]['limit']
|
||||
interval = current_app.config['API_KEY_LIMITS'][api_key.key_type]['interval']
|
||||
@@ -32,7 +33,7 @@ def check_service_over_api_rate_limit(service, api_key):
|
||||
|
||||
|
||||
def check_service_over_daily_message_limit(key_type, service):
|
||||
if key_type != KEY_TYPE_TEST:
|
||||
if key_type != KEY_TYPE_TEST and current_app.config['REDIS_ENABLED']:
|
||||
cache_key = daily_limit_cache_key(service.id)
|
||||
service_stats = redis_store.get(cache_key)
|
||||
if not service_stats:
|
||||
@@ -46,6 +47,7 @@ def check_service_over_daily_message_limit(key_type, service):
|
||||
raise TooManyRequestsError(service.message_limit)
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def check_rate_limiting(service, api_key):
|
||||
check_service_over_api_rate_limit(service, api_key)
|
||||
check_service_over_daily_message_limit(api_key.key_type, service)
|
||||
@@ -80,12 +82,14 @@ def service_has_permission(notify_type, permissions):
|
||||
return notify_type in [p.permission for p in permissions]
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def check_service_has_permission(notify_type, permissions):
|
||||
if not service_has_permission(notify_type, permissions):
|
||||
raise BadRequestError(message="Cannot send {}".format(
|
||||
get_public_notify_type_text(notify_type, plural=True)))
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def check_service_can_schedule_notification(permissions, scheduled_for):
|
||||
if scheduled_for:
|
||||
if not service_has_permission(SCHEDULE_NOTIFICATIONS, permissions):
|
||||
@@ -117,6 +121,7 @@ def check_sms_content_char_count(content_count):
|
||||
raise BadRequestError(message=message)
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def validate_template(template_id, personalisation, service, notification_type):
|
||||
try:
|
||||
template = templates_dao.dao_get_template_by_id_and_service_id(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
def create_post_sms_response_from_notification(notification, content, from_number, url_root, scheduled_for):
|
||||
noti = __create_notification_response(notification, url_root, scheduled_for)
|
||||
@@ -8,6 +10,7 @@ def create_post_sms_response_from_notification(notification, content, from_numbe
|
||||
return noti
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root, scheduled_for):
|
||||
noti = __create_notification_response(notification, url_root, scheduled_for)
|
||||
noti['content'] = {
|
||||
|
||||
@@ -34,6 +34,7 @@ from app.notifications.validators import (
|
||||
check_service_sms_sender_id
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.statsd_decorators import statsd
|
||||
from app.v2.errors import BadRequestError
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
@@ -49,6 +50,7 @@ from app.v2.notifications.create_response import (
|
||||
|
||||
|
||||
@v2_notification_blueprint.route('/<notification_type>', methods=['POST'])
|
||||
@statsd(namespace="performance-testing")
|
||||
def post_notification(notification_type):
|
||||
if notification_type == EMAIL_TYPE:
|
||||
form = validate(request.get_json(), post_email_request)
|
||||
@@ -118,6 +120,7 @@ def post_notification(notification_type):
|
||||
return jsonify(resp), 201
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def process_sms_or_email_notification(*, form, notification_type, api_key, template, service, reply_to_text=None):
|
||||
form_send_to = form['email_address'] if notification_type == EMAIL_TYPE else form['phone_number']
|
||||
|
||||
@@ -187,6 +190,7 @@ def process_letter_notification(*, letter_data, api_key, template):
|
||||
return notification
|
||||
|
||||
|
||||
@statsd(namespace="performance-testing")
|
||||
def get_reply_to_text(notification_type, form):
|
||||
reply_to = None
|
||||
if notification_type == EMAIL_TYPE:
|
||||
|
||||
Reference in New Issue
Block a user