diff --git a/app/config.py b/app/config.py index 99b77cc8d..cfd37fa33 100644 --- a/app/config.py +++ b/app/config.py @@ -22,7 +22,6 @@ class QueueNames(object): PERIODIC = 'periodic-tasks' PRIORITY = 'priority-tasks' DATABASE = 'database-tasks' - SEND_COMBINED = 'send-tasks' SEND_SMS = 'send-sms-tasks' SEND_EMAIL = 'send-email-tasks' RESEARCH_MODE = 'research-mode-tasks' @@ -38,7 +37,6 @@ class QueueNames(object): QueueNames.PRIORITY, QueueNames.PERIODIC, QueueNames.DATABASE, - QueueNames.SEND_COMBINED, QueueNames.SEND_SMS, QueueNames.SEND_EMAIL, QueueNames.RESEARCH_MODE, @@ -115,7 +113,6 @@ class Config(object): PAGE_SIZE = 50 API_PAGE_SIZE = 250 SMS_CHAR_COUNT_LIMIT = 495 - BRANDING_PATH = '/images/email-template/crests/' TEST_MESSAGE_FILENAME = 'Test message' ONE_OFF_MESSAGE_FILENAME = 'Report' MAX_VERIFY_CODE_COUNT = 10 diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 5e33e2113..fcf4348d8 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -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) -def get_logo_url(base_url, branding_path, 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}) - """ +def get_logo_url(base_url, logo_file): base_url = parse.urlparse(base_url) netloc = base_url.netloc - # covers both preview and staging - if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc: - path = '/static' + branding_path + logo_file - else: - if base_url.netloc.startswith('www'): - # strip "www." - netloc = base_url.netloc[4:] - - netloc = 'static.' + netloc - path = branding_path + logo_file + if base_url.netloc.startswith('localhost'): + netloc = 'notify.tools' + elif base_url.netloc.startswith('www'): + # strip "www." + netloc = base_url.netloc[4:] logo_url = parse.ParseResult( scheme=base_url.scheme, - netloc=netloc, - path=path, + netloc='static-logos.' + netloc, + path=logo_file, params=base_url.params, query=base_url.query, fragment=base_url.fragment @@ -185,7 +171,6 @@ def get_html_email_options(service): if service.organisation: logo_url = get_logo_url( current_app.config['ADMIN_BASE_URL'], - current_app.config['BRANDING_PATH'], service.organisation.logo ) diff --git a/aws_run_celery.py b/aws_run_celery.py deleted file mode 100644 index 36a1f480a..000000000 --- a/aws_run_celery.py +++ /dev/null @@ -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() diff --git a/db.py b/db.py index 3a8da01d4..bc558cbd2 100644 --- a/db.py +++ b/db.py @@ -1,12 +1,8 @@ from flask.ext.script import Manager, Server 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 -if os.getenv('VCAP_SERVICES') is None: - os.environ.update(getAllSecrets(region="eu-west-1")) +from app import create_app, db + application = create_app() diff --git a/manifest-delivery-base.yml b/manifest-delivery-base.yml index 597df9f3f..78053a729 100644 --- a/manifest-delivery-base.yml +++ b/manifest-delivery-base.yml @@ -16,39 +16,39 @@ memory: 1G applications: - 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 memory: 128M env: NOTIFY_APP_NAME: delivery-celery-beat - 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: NOTIFY_APP_NAME: delivery-worker-database - 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: NOTIFY_APP_NAME: delivery-worker-research - 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: NOTIFY_APP_NAME: delivery-worker-sender - 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 env: NOTIFY_APP_NAME: delivery-worker-periodic - 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: NOTIFY_APP_NAME: delivery-worker-priority - 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: NOTIFY_APP_NAME: delivery-worker diff --git a/requirements.txt b/requirements.txt index 0c9b3f1e0..61390b6c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ marshmallow==2.4.2 marshmallow-sqlalchemy==0.8.0 flask-marshmallow==0.6.2 Flask-Bcrypt==0.6.2 -credstash==1.8.0 boto3==1.4.4 celery==3.1.25 # pyup: <4 monotonic==1.2 diff --git a/run_celery.py b/run_celery.py index 066735e63..013499615 100644 --- a/run_celery.py +++ b/run_celery.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# notify_celery is referenced from manifest_delivery_base.yml, and cannot be removed from app import notify_celery, create_app application = create_app('delivery') diff --git a/server_commands.py b/server_commands.py index 85bf13137..af071db47 100644 --- a/server_commands.py +++ b/server_commands.py @@ -1,7 +1,6 @@ from flask.ext.script import Manager, Server from flask_migrate import Migrate, MigrateCommand from app import (create_app, db, commands) -from credstash import getAllSecrets import os 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: 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 os.environ['NOTIFY_API_ENVIRONMENT'] = configs[environment] diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index e1a4ec4a2..d14fee6d8 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -435,29 +435,22 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api): 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', [ # don't change localhost to prevent errors when testing locally - ('http://localhost:6012', 'http://localhost:6012/static/sub-path/filename.png'), - # on other environments, replace www with staging - ('https://www.notifications.service.gov.uk', 'https://static.notifications.service.gov.uk/sub-path/filename.png'), - - # staging and preview do not have cloudfront running, so should act as localhost - pytest.mark.xfail(('https://www.notify.works', 'https://static.notify.works/sub-path/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'), + ('http://localhost:6012', 'http://static-logos.notify.tools/filename.png'), + ('https://www.notifications.service.gov.uk', 'https://static-logos.notifications.service.gov.uk/filename.png'), + ('https://notify.works', 'https://static-logos.notify.works/filename.png'), + ('https://staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'), + ('https://www.notify.works', 'https://static-logos.notify.works/filename.png'), + ('https://www.staging-notify.works', 'https://static-logos.staging-notify.works/filename.png'), ]) def test_get_logo_url_works_for_different_environments(base_url, expected_url): - branding_path = '/sub-path/' 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 diff --git a/wsgi.py b/wsgi.py index 2df2c3976..9fbeb28ac 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,13 +1,6 @@ -import os - 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() if __name__ == "__main__":