mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge branch 'master' of github.com:alphagov/notifications-api into letter-api
This commit is contained in:
@@ -22,7 +22,6 @@ class QueueNames(object):
|
|||||||
PERIODIC = 'periodic-tasks'
|
PERIODIC = 'periodic-tasks'
|
||||||
PRIORITY = 'priority-tasks'
|
PRIORITY = 'priority-tasks'
|
||||||
DATABASE = 'database-tasks'
|
DATABASE = 'database-tasks'
|
||||||
SEND_COMBINED = 'send-tasks'
|
|
||||||
SEND_SMS = 'send-sms-tasks'
|
SEND_SMS = 'send-sms-tasks'
|
||||||
SEND_EMAIL = 'send-email-tasks'
|
SEND_EMAIL = 'send-email-tasks'
|
||||||
RESEARCH_MODE = 'research-mode-tasks'
|
RESEARCH_MODE = 'research-mode-tasks'
|
||||||
@@ -38,7 +37,6 @@ class QueueNames(object):
|
|||||||
QueueNames.PRIORITY,
|
QueueNames.PRIORITY,
|
||||||
QueueNames.PERIODIC,
|
QueueNames.PERIODIC,
|
||||||
QueueNames.DATABASE,
|
QueueNames.DATABASE,
|
||||||
QueueNames.SEND_COMBINED,
|
|
||||||
QueueNames.SEND_SMS,
|
QueueNames.SEND_SMS,
|
||||||
QueueNames.SEND_EMAIL,
|
QueueNames.SEND_EMAIL,
|
||||||
QueueNames.RESEARCH_MODE,
|
QueueNames.RESEARCH_MODE,
|
||||||
@@ -115,7 +113,6 @@ class Config(object):
|
|||||||
PAGE_SIZE = 50
|
PAGE_SIZE = 50
|
||||||
API_PAGE_SIZE = 250
|
API_PAGE_SIZE = 250
|
||||||
SMS_CHAR_COUNT_LIMIT = 495
|
SMS_CHAR_COUNT_LIMIT = 495
|
||||||
BRANDING_PATH = '/images/email-template/crests/'
|
|
||||||
TEST_MESSAGE_FILENAME = 'Test message'
|
TEST_MESSAGE_FILENAME = 'Test message'
|
||||||
ONE_OFF_MESSAGE_FILENAME = 'Report'
|
ONE_OFF_MESSAGE_FILENAME = 'Report'
|
||||||
MAX_VERIFY_CODE_COUNT = 10
|
MAX_VERIFY_CODE_COUNT = 10
|
||||||
|
|||||||
@@ -145,34 +145,20 @@ def provider_to_use(notification_type, notification_id, international=False):
|
|||||||
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
|
return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
|
||||||
|
|
||||||
|
|
||||||
def get_logo_url(base_url, branding_path, logo_file):
|
def get_logo_url(base_url, logo_file):
|
||||||
"""
|
|
||||||
Get the complete URL for a given logo.
|
|
||||||
|
|
||||||
We have to convert the base_url into a static url. Our hosted environments all have their own cloudfront instances,
|
|
||||||
found at the static subdomain (eg https://static.notifications.service.gov.uk).
|
|
||||||
|
|
||||||
If running locally (dev environment), don't try and use cloudfront - just stick to the actual underlying source
|
|
||||||
({URL}/static/{PATH})
|
|
||||||
"""
|
|
||||||
base_url = parse.urlparse(base_url)
|
base_url = parse.urlparse(base_url)
|
||||||
netloc = base_url.netloc
|
netloc = base_url.netloc
|
||||||
|
|
||||||
# covers both preview and staging
|
if base_url.netloc.startswith('localhost'):
|
||||||
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
|
netloc = 'notify.tools'
|
||||||
path = '/static' + branding_path + logo_file
|
elif base_url.netloc.startswith('www'):
|
||||||
else:
|
# strip "www."
|
||||||
if base_url.netloc.startswith('www'):
|
netloc = base_url.netloc[4:]
|
||||||
# strip "www."
|
|
||||||
netloc = base_url.netloc[4:]
|
|
||||||
|
|
||||||
netloc = 'static.' + netloc
|
|
||||||
path = branding_path + logo_file
|
|
||||||
|
|
||||||
logo_url = parse.ParseResult(
|
logo_url = parse.ParseResult(
|
||||||
scheme=base_url.scheme,
|
scheme=base_url.scheme,
|
||||||
netloc=netloc,
|
netloc='static-logos.' + netloc,
|
||||||
path=path,
|
path=logo_file,
|
||||||
params=base_url.params,
|
params=base_url.params,
|
||||||
query=base_url.query,
|
query=base_url.query,
|
||||||
fragment=base_url.fragment
|
fragment=base_url.fragment
|
||||||
@@ -185,7 +171,6 @@ def get_html_email_options(service):
|
|||||||
if service.organisation:
|
if service.organisation:
|
||||||
logo_url = get_logo_url(
|
logo_url = get_logo_url(
|
||||||
current_app.config['ADMIN_BASE_URL'],
|
current_app.config['ADMIN_BASE_URL'],
|
||||||
current_app.config['BRANDING_PATH'],
|
|
||||||
service.organisation.logo
|
service.organisation.logo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
from app import notify_celery, create_app
|
|
||||||
from credstash import getAllSecrets
|
|
||||||
import os
|
|
||||||
|
|
||||||
# On AWS get secrets and export to env, skip this on Cloud Foundry
|
|
||||||
if os.getenv('VCAP_SERVICES') is None:
|
|
||||||
os.environ.update(getAllSecrets(region="eu-west-1"))
|
|
||||||
|
|
||||||
application = create_app("delivery")
|
|
||||||
application.app_context().push()
|
|
||||||
8
db.py
8
db.py
@@ -1,12 +1,8 @@
|
|||||||
from flask.ext.script import Manager, Server
|
from flask.ext.script import Manager, Server
|
||||||
from flask_migrate import Migrate, MigrateCommand
|
from flask_migrate import Migrate, MigrateCommand
|
||||||
from app import create_app, db
|
|
||||||
from credstash import getAllSecrets
|
|
||||||
import os
|
|
||||||
|
|
||||||
# On AWS get secrets and export to env, skip this on Cloud Foundry
|
from app import create_app, db
|
||||||
if os.getenv('VCAP_SERVICES') is None:
|
|
||||||
os.environ.update(getAllSecrets(region="eu-west-1"))
|
|
||||||
|
|
||||||
application = create_app()
|
application = create_app()
|
||||||
|
|
||||||
|
|||||||
@@ -16,39 +16,39 @@ memory: 1G
|
|||||||
|
|
||||||
applications:
|
applications:
|
||||||
- name: notify-delivery-celery-beat
|
- name: notify-delivery-celery-beat
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery beat --loglevel=INFO
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery beat --loglevel=INFO
|
||||||
instances: 1
|
instances: 1
|
||||||
memory: 128M
|
memory: 128M
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-celery-beat
|
NOTIFY_APP_NAME: delivery-celery-beat
|
||||||
|
|
||||||
- name: notify-delivery-worker-database
|
- name: notify-delivery-worker-database
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q database-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q database-tasks
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker-database
|
NOTIFY_APP_NAME: delivery-worker-database
|
||||||
|
|
||||||
- name: notify-delivery-worker-research
|
- name: notify-delivery-worker-research
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=5 -Q research-mode-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=5 -Q research-mode-tasks
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker-research
|
NOTIFY_APP_NAME: delivery-worker-research
|
||||||
|
|
||||||
- name: notify-delivery-worker-sender
|
- name: notify-delivery-worker-sender
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q send-tasks,send-sms-tasks,send-email-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q send-sms-tasks,send-email-tasks
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker-sender
|
NOTIFY_APP_NAME: delivery-worker-sender
|
||||||
|
|
||||||
- name: notify-delivery-worker-periodic
|
- name: notify-delivery-worker-periodic
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=2 -Q periodic-tasks,statistics-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=2 -Q periodic-tasks,statistics-tasks
|
||||||
instances: 1
|
instances: 1
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker-periodic
|
NOTIFY_APP_NAME: delivery-worker-periodic
|
||||||
|
|
||||||
- name: notify-delivery-worker-priority
|
- name: notify-delivery-worker-priority
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=5 -Q priority-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=5 -Q priority-tasks
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker-priority
|
NOTIFY_APP_NAME: delivery-worker-priority
|
||||||
|
|
||||||
- name: notify-delivery-worker
|
- name: notify-delivery-worker
|
||||||
command: scripts/run_app_paas.sh celery -A aws_run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q job-tasks,retry-tasks,notify-internal-tasks
|
command: scripts/run_app_paas.sh celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=11 -Q job-tasks,retry-tasks,notify-internal-tasks
|
||||||
env:
|
env:
|
||||||
NOTIFY_APP_NAME: delivery-worker
|
NOTIFY_APP_NAME: delivery-worker
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ marshmallow==2.4.2
|
|||||||
marshmallow-sqlalchemy==0.8.0
|
marshmallow-sqlalchemy==0.8.0
|
||||||
flask-marshmallow==0.6.2
|
flask-marshmallow==0.6.2
|
||||||
Flask-Bcrypt==0.6.2
|
Flask-Bcrypt==0.6.2
|
||||||
credstash==1.8.0
|
|
||||||
boto3==1.4.4
|
boto3==1.4.4
|
||||||
celery==3.1.25 # pyup: <4
|
celery==3.1.25 # pyup: <4
|
||||||
monotonic==1.2
|
monotonic==1.2
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# notify_celery is referenced from manifest_delivery_base.yml, and cannot be removed
|
||||||
from app import notify_celery, create_app
|
from app import notify_celery, create_app
|
||||||
|
|
||||||
application = create_app('delivery')
|
application = create_app('delivery')
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from flask.ext.script import Manager, Server
|
from flask.ext.script import Manager, Server
|
||||||
from flask_migrate import Migrate, MigrateCommand
|
from flask_migrate import Migrate, MigrateCommand
|
||||||
from app import (create_app, db, commands)
|
from app import (create_app, db, commands)
|
||||||
from credstash import getAllSecrets
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
default_env_file = '/home/ubuntu/environment'
|
default_env_file = '/home/ubuntu/environment'
|
||||||
@@ -11,10 +10,6 @@ if os.path.isfile(default_env_file):
|
|||||||
with open(default_env_file, 'r') as environment_file:
|
with open(default_env_file, 'r') as environment_file:
|
||||||
environment = environment_file.readline().strip()
|
environment = environment_file.readline().strip()
|
||||||
|
|
||||||
# On AWS get secrets and export to env, skip this on Cloud Foundry
|
|
||||||
if os.getenv('VCAP_SERVICES') is None:
|
|
||||||
os.environ.update(getAllSecrets(region="eu-west-1"))
|
|
||||||
|
|
||||||
from app.config import configs
|
from app.config import configs
|
||||||
|
|
||||||
os.environ['NOTIFY_API_ENVIRONMENT'] = configs[environment]
|
os.environ['NOTIFY_API_ENVIRONMENT'] = configs[environment]
|
||||||
|
|||||||
@@ -435,29 +435,22 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
|||||||
|
|
||||||
renderer = send_to_providers.get_html_email_options(service)
|
renderer = send_to_providers.get_html_email_options(service)
|
||||||
|
|
||||||
assert renderer['brand_logo'] == 'http://localhost:6012/static/images/email-template/crests/justice-league.png'
|
assert renderer['brand_logo'] == 'http://static-logos.notify.tools/justice-league.png'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('base_url, expected_url', [
|
@pytest.mark.parametrize('base_url, expected_url', [
|
||||||
# don't change localhost to prevent errors when testing locally
|
# don't change localhost to prevent errors when testing locally
|
||||||
('http://localhost:6012', 'http://localhost:6012/static/sub-path/filename.png'),
|
('http://localhost:6012', 'http://static-logos.notify.tools/filename.png'),
|
||||||
# on other environments, replace www with staging
|
('https://www.notifications.service.gov.uk', 'https://static-logos.notifications.service.gov.uk/filename.png'),
|
||||||
('https://www.notifications.service.gov.uk', 'https://static.notifications.service.gov.uk/sub-path/filename.png'),
|
('https://notify.works', 'https://static-logos.notify.works/filename.png'),
|
||||||
|
('https://staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
||||||
# staging and preview do not have cloudfront running, so should act as localhost
|
('https://www.notify.works', 'https://static-logos.notify.works/filename.png'),
|
||||||
pytest.mark.xfail(('https://www.notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
('https://www.staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'),
|
||||||
pytest.mark.xfail(('https://www.staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
pytest.mark.xfail(('https://notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
pytest.mark.xfail(('https://staging-notify.works', 'https://static.notify.works/sub-path/filename.png')),
|
|
||||||
# these tests should be removed when cloudfront works on staging/preview
|
|
||||||
('https://www.notify.works', 'https://www.notify.works/static/sub-path/filename.png'),
|
|
||||||
('https://www.staging-notify.works', 'https://www.staging-notify.works/static/sub-path/filename.png'),
|
|
||||||
])
|
])
|
||||||
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
||||||
branding_path = '/sub-path/'
|
|
||||||
logo_file = 'filename.png'
|
logo_file = 'filename.png'
|
||||||
|
|
||||||
logo_url = send_to_providers.get_logo_url(base_url, branding_path, logo_file)
|
logo_url = send_to_providers.get_logo_url(base_url, logo_file)
|
||||||
|
|
||||||
assert logo_url == expected_url
|
assert logo_url == expected_url
|
||||||
|
|
||||||
|
|||||||
7
wsgi.py
7
wsgi.py
@@ -1,13 +1,6 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from app import create_app
|
from app import create_app
|
||||||
from credstash import getAllSecrets
|
|
||||||
|
|
||||||
|
|
||||||
# On AWS get secrets and export to env, skip this on Cloud Foundry
|
|
||||||
if os.getenv('VCAP_SERVICES') is None:
|
|
||||||
os.environ.update(getAllSecrets(region="eu-west-1"))
|
|
||||||
|
|
||||||
application = create_app()
|
application = create_app()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user