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.
This commit is contained in:
Leo Hemsted
2017-08-23 18:11:44 +01:00
parent 89f4f5173e
commit bd2682b521
4 changed files with 35 additions and 20 deletions

View File

@@ -34,6 +34,8 @@ def set_config_env_vars(vcap_services):
extract_firetext_config(s) extract_firetext_config(s)
elif s['name'] == 'redis': elif s['name'] == 'redis':
extract_redis_config(s) extract_redis_config(s)
elif s['name'] == 'performance-platform':
extract_performance_platform_config(s)
def extract_notify_config(notify_config): 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['ADMIN_CLIENT_SECRET'] = notify_config['credentials']['admin_client_secret']
os.environ['SECRET_KEY'] = notify_config['credentials']['secret_key'] os.environ['SECRET_KEY'] = notify_config['credentials']['secret_key']
os.environ['DANGEROUS_SALT'] = notify_config['credentials']['dangerous_salt'] 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']) 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): def extract_notify_aws_config(aws_config):
os.environ['NOTIFICATION_QUEUE_PREFIX'] = aws_config['credentials']['sqs_queue_prefix'] os.environ['NOTIFICATION_QUEUE_PREFIX'] = aws_config['credentials']['sqs_queue_prefix']
os.environ['AWS_ACCESS_KEY_ID'] = aws_config['credentials']['aws_access_key_id'] os.environ['AWS_ACCESS_KEY_ID'] = aws_config['credentials']['aws_access_key_id']

View File

@@ -273,6 +273,10 @@ class Config(object):
SMS_INBOUND_WHITELIST = json.loads(os.environ.get('SMS_INBOUND_WHITELIST', '[]')) 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 ### # Config overrides ###

View File

@@ -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( def test_send_daily_performance_stats_calls_does_not_send_if_inactive(mocker):
notify_db,
notify_db_session,
sample_template,
mocker
):
send_mock = mocker.patch('app.celery.scheduled_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats') send_mock = mocker.patch('app.celery.scheduled_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats')
with patch.object( with patch.object(

View File

@@ -16,7 +16,6 @@ def notify_config():
'admin_client_secret': 'admin client secret', 'admin_client_secret': 'admin client secret',
'secret_key': 'secret key', 'secret_key': 'secret key',
'dangerous_salt': 'dangerous salt', 'dangerous_salt': 'dangerous salt',
'performance_platform_token': 'performance platform token',
'allow_ip_inbound_sms': ['111.111.111.111', '100.100.100.100'] '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 @pytest.fixture
def cloudfoundry_config( def cloudfoundry_config(
@@ -96,7 +105,8 @@ def cloudfoundry_config(
hosted_graphite_config, hosted_graphite_config,
mmg_config, mmg_config,
firetext_config, firetext_config,
redis_config redis_config,
performance_platform_config
): ):
return { return {
'postgres': postgres_config, 'postgres': postgres_config,
@@ -106,7 +116,8 @@ def cloudfoundry_config(
hosted_graphite_config, hosted_graphite_config,
mmg_config, mmg_config,
firetext_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['ADMIN_CLIENT_SECRET'] == 'admin client secret'
assert os.environ['SECRET_KEY'] == 'secret key' assert os.environ['SECRET_KEY'] == 'secret key'
assert os.environ['DANGEROUS_SALT'] == 'dangerous salt' 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') @pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
@@ -205,3 +206,13 @@ def test_sms_inbound_config():
extract_cloudfoundry_config() extract_cloudfoundry_config()
assert os.environ['SMS_INBOUND_WHITELIST'] == json.dumps(['111.111.111.111', '100.100.100.100']) 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'
})