From bd2682b5219a888951d19738c9e30b049320ad93 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 23 Aug 2017 18:11:44 +0100 Subject: [PATCH] add new performance-platform section to cf config it's a new cf-service we've got to create, that contains endpoints and the bearer tokens for them. --- app/cloudfoundry_config.py | 7 ++++- app/config.py | 4 +++ tests/app/celery/test_scheduled_tasks.py | 7 +---- tests/app/test_cloudfoundry_config.py | 37 +++++++++++++++--------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/cloudfoundry_config.py b/app/cloudfoundry_config.py index c890a8333..33cd4f753 100644 --- a/app/cloudfoundry_config.py +++ b/app/cloudfoundry_config.py @@ -34,6 +34,8 @@ def set_config_env_vars(vcap_services): extract_firetext_config(s) elif s['name'] == 'redis': extract_redis_config(s) + elif s['name'] == 'performance-platform': + extract_performance_platform_config(s) def extract_notify_config(notify_config): @@ -42,10 +44,13 @@ def extract_notify_config(notify_config): os.environ['ADMIN_CLIENT_SECRET'] = notify_config['credentials']['admin_client_secret'] os.environ['SECRET_KEY'] = notify_config['credentials']['secret_key'] os.environ['DANGEROUS_SALT'] = notify_config['credentials']['dangerous_salt'] - os.environ['PERFORMANCE_PLATFORM_TOKEN'] = notify_config['credentials'].get('performance_platform_token', '') os.environ['SMS_INBOUND_WHITELIST'] = json.dumps(notify_config['credentials']['allow_ip_inbound_sms']) +def extract_performance_platform_config(performance_platform_config): + os.environ['PERFORMANCE_PLATFORM_ENDPOINTS'] = json.dumps(performance_platform_config['credentials']) + + def extract_notify_aws_config(aws_config): os.environ['NOTIFICATION_QUEUE_PREFIX'] = aws_config['credentials']['sqs_queue_prefix'] os.environ['AWS_ACCESS_KEY_ID'] = aws_config['credentials']['aws_access_key_id'] diff --git a/app/config.py b/app/config.py index d98e9fa1a..c6c5291eb 100644 --- a/app/config.py +++ b/app/config.py @@ -273,6 +273,10 @@ class Config(object): SMS_INBOUND_WHITELIST = json.loads(os.environ.get('SMS_INBOUND_WHITELIST', '[]')) + # Format is as follows: + # {"dataset_1": "token_1", ...} + PERFORMANCE_PLATFORM_ENDPOINTS = json.loads(os.environ.get('PERFORMANCE_PLATFORM_ENDPOINTS', '{}')) + ###################### # Config overrides ### diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 9a2454a8f..d05423e00 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -270,12 +270,7 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days( ] -def test_send_daily_performance_stats_calls_does_not_send_if_inactive( - notify_db, - notify_db_session, - sample_template, - mocker -): +def test_send_daily_performance_stats_calls_does_not_send_if_inactive(mocker): send_mock = mocker.patch('app.celery.scheduled_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats') with patch.object( diff --git a/tests/app/test_cloudfoundry_config.py b/tests/app/test_cloudfoundry_config.py index a393fc8bb..c299976d9 100644 --- a/tests/app/test_cloudfoundry_config.py +++ b/tests/app/test_cloudfoundry_config.py @@ -16,7 +16,6 @@ def notify_config(): 'admin_client_secret': 'admin client secret', 'secret_key': 'secret key', 'dangerous_salt': 'dangerous salt', - 'performance_platform_token': 'performance platform token', 'allow_ip_inbound_sms': ['111.111.111.111', '100.100.100.100'] } } @@ -87,6 +86,16 @@ def redis_config(): } } +@pytest.fixture +def performance_platform_config(): + return { + 'name': 'performance-platform', + 'credentials': { + 'foo': 'my_token', + 'bar': 'other_token' + } + } + @pytest.fixture def cloudfoundry_config( @@ -96,7 +105,8 @@ def cloudfoundry_config( hosted_graphite_config, mmg_config, firetext_config, - redis_config + redis_config, + performance_platform_config ): return { 'postgres': postgres_config, @@ -106,7 +116,8 @@ def cloudfoundry_config( hosted_graphite_config, mmg_config, firetext_config, - redis_config + redis_config, + performance_platform_config ] } @@ -148,16 +159,6 @@ def test_notify_config(): assert os.environ['ADMIN_CLIENT_SECRET'] == 'admin client secret' assert os.environ['SECRET_KEY'] == 'secret key' assert os.environ['DANGEROUS_SALT'] == 'dangerous salt' - assert os.environ['PERFORMANCE_PLATFORM_TOKEN'] == 'performance platform token' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_notify_config_if_perf_platform_not_set(cloudfoundry_config): - del cloudfoundry_config['user-provided'][0]['credentials']['performance_platform_token'] - - set_config_env_vars(cloudfoundry_config) - - assert os.environ['PERFORMANCE_PLATFORM_TOKEN'] == '' @pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') @@ -205,3 +206,13 @@ def test_sms_inbound_config(): extract_cloudfoundry_config() assert os.environ['SMS_INBOUND_WHITELIST'] == json.dumps(['111.111.111.111', '100.100.100.100']) + + +@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') +def test_performance_platform_config(): + extract_cloudfoundry_config() + + assert os.environ['PERFORMANCE_PLATFORM_ENDPOINTS'] == json.dumps({ + 'foo': 'my_token', + 'bar': 'other_token' + })