diff --git a/app/cloudfoundry_config.py b/app/cloudfoundry_config.py index 3a21a7a29..5cb7c437f 100644 --- a/app/cloudfoundry_config.py +++ b/app/cloudfoundry_config.py @@ -19,70 +19,3 @@ def set_config_env_vars(vcap_services): vcap_application = json.loads(os.environ['VCAP_APPLICATION']) os.environ['NOTIFY_ENVIRONMENT'] = vcap_application['space_name'] os.environ['NOTIFY_LOG_PATH'] = '/home/vcap/logs/app.log' - - # Notify common config - for s in vcap_services['user-provided']: - if s['name'] == 'notify-config': - extract_notify_config(s) - elif s['name'] == 'notify-aws': - extract_notify_aws_config(s) - elif s['name'] == 'hosted-graphite': - extract_hosted_graphite_config(s) - elif s['name'] == 'mmg': - extract_mmg_config(s) - elif s['name'] == 'firetext': - extract_firetext_config(s) - elif s['name'] == 'redis': - extract_redis_config(s) - elif s['name'] == 'performance-platform': - extract_performance_platform_config(s) - elif s['name'] == 'notify-template-preview': - extract_template_preview_config(s) - - -def extract_notify_config(notify_config): - os.environ['ADMIN_BASE_URL'] = notify_config['credentials']['admin_base_url'] - os.environ['API_HOST_NAME'] = notify_config['credentials']['api_host_name'] - 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['SMS_INBOUND_WHITELIST'] = json.dumps(notify_config['credentials']['allow_ip_inbound_sms']) - os.environ['FIRETEXT_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['firetext_inbound_sms_auth']) - os.environ['MMG_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['mmg_inbound_sms_auth']) - os.environ['MMG_INBOUND_SMS_USERNAME'] = json.dumps(notify_config['credentials']['mmg_inbound_sms_username']) - os.environ['ROUTE_SECRET_KEY_1'] = notify_config['credentials']['route_secret_key_1'] - os.environ['ROUTE_SECRET_KEY_2'] = notify_config['credentials']['route_secret_key_2'] - - -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'] - os.environ['AWS_SECRET_ACCESS_KEY'] = aws_config['credentials']['aws_secret_access_key'] - - -def extract_hosted_graphite_config(hosted_graphite_config): - os.environ['STATSD_PREFIX'] = hosted_graphite_config['credentials']['statsd_prefix'] - - -def extract_mmg_config(mmg_config): - os.environ['MMG_URL'] = mmg_config['credentials']['api_url'] - os.environ['MMG_API_KEY'] = mmg_config['credentials']['api_key'] - - -def extract_firetext_config(firetext_config): - os.environ['FIRETEXT_API_KEY'] = firetext_config['credentials']['api_key'] - os.environ['LOADTESTING_API_KEY'] = firetext_config['credentials']['loadtesting_api_key'] - - -def extract_redis_config(redis_config): - os.environ['REDIS_ENABLED'] = redis_config['credentials']['redis_enabled'] - os.environ['REDIS_URL'] = redis_config['credentials']['redis_url'] - - -def extract_template_preview_config(template_preview_config): - os.environ['TEMPLATE_PREVIEW_API_HOST'] = template_preview_config['credentials']['api_host'] - os.environ['TEMPLATE_PREVIEW_API_KEY'] = template_preview_config['credentials']['api_key'] diff --git a/tests/app/test_cloudfoundry_config.py b/tests/app/test_cloudfoundry_config.py index aafd894c7..ccf238d49 100644 --- a/tests/app/test_cloudfoundry_config.py +++ b/tests/app/test_cloudfoundry_config.py @@ -6,70 +6,6 @@ import pytest from app.cloudfoundry_config import extract_cloudfoundry_config, set_config_env_vars -@pytest.fixture -def notify_config(): - return { - 'name': 'notify-config', - 'credentials': { - 'admin_base_url': 'admin base url', - 'api_host_name': 'api host name', - 'admin_client_secret': 'admin client secret', - 'secret_key': 'secret key', - 'dangerous_salt': 'dangerous salt', - 'allow_ip_inbound_sms': ['111.111.111.111', '100.100.100.100'], - 'firetext_inbound_sms_auth': ['testkey'], - 'mmg_inbound_sms_auth': ['testkey'], - 'mmg_inbound_sms_username': ['username'], - 'route_secret_key_1': "key_1", - 'route_secret_key_2': "" - } - } - - -@pytest.fixture -def aws_config(): - return { - 'name': 'notify-aws', - 'credentials': { - 'sqs_queue_prefix': 'sqs queue prefix', - 'aws_access_key_id': 'aws access key id', - 'aws_secret_access_key': 'aws secret access key', - } - } - - -@pytest.fixture -def hosted_graphite_config(): - return { - 'name': 'hosted-graphite', - 'credentials': { - 'statsd_prefix': 'statsd prefix' - } - } - - -@pytest.fixture -def mmg_config(): - return { - 'name': 'mmg', - 'credentials': { - 'api_url': 'mmg api url', - 'api_key': 'mmg api key' - } - } - - -@pytest.fixture -def firetext_config(): - return { - 'name': 'firetext', - 'credentials': { - 'api_key': 'firetext api key', - 'loadtesting_api_key': 'loadtesting api key' - } - } - - @pytest.fixture def postgres_config(): return [ @@ -82,62 +18,10 @@ def postgres_config(): @pytest.fixture -def redis_config(): - return { - 'name': 'redis', - 'credentials': { - 'redis_enabled': '1', - 'redis_url': 'redis url' - } - } - - -@pytest.fixture -def performance_platform_config(): - return { - 'name': 'performance-platform', - 'credentials': { - 'foo': 'my_token', - 'bar': 'other_token' - } - } - - -@pytest.fixture -def template_preview_config(): - return { - 'name': 'notify-template-preview', - 'credentials': { - 'api_host': 'template-preview api host', - 'api_key': 'template-preview api key' - } - } - - -@pytest.fixture -def cloudfoundry_config( - postgres_config, - notify_config, - aws_config, - hosted_graphite_config, - mmg_config, - firetext_config, - redis_config, - performance_platform_config, - template_preview_config -): +def cloudfoundry_config(postgres_config): return { 'postgres': postgres_config, - 'user-provided': [ - notify_config, - aws_config, - hosted_graphite_config, - mmg_config, - firetext_config, - redis_config, - performance_platform_config, - template_preview_config - ] + 'user-provided': [] } @@ -167,100 +51,3 @@ def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config): assert 'foo' not in os.environ assert 'bar' not in os.environ - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_notify_config(): - extract_cloudfoundry_config() - - assert os.environ['ADMIN_BASE_URL'] == 'admin base url' - assert os.environ['API_HOST_NAME'] == 'api host name' - assert os.environ['ADMIN_CLIENT_SECRET'] == 'admin client secret' - assert os.environ['SECRET_KEY'] == 'secret key' - assert os.environ['DANGEROUS_SALT'] == 'dangerous salt' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_aws_config(): - extract_cloudfoundry_config() - - assert os.environ['NOTIFICATION_QUEUE_PREFIX'] == 'sqs queue prefix' - assert os.environ['AWS_ACCESS_KEY_ID'] == 'aws access key id' - assert os.environ['AWS_SECRET_ACCESS_KEY'] == 'aws secret access key' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_hosted_graphite_config(): - extract_cloudfoundry_config() - - assert os.environ['STATSD_PREFIX'] == 'statsd prefix' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_mmg_config(): - extract_cloudfoundry_config() - - assert os.environ['MMG_URL'] == 'mmg api url' - assert os.environ['MMG_API_KEY'] == 'mmg api key' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_firetext_config(): - extract_cloudfoundry_config() - - assert os.environ['FIRETEXT_API_KEY'] == 'firetext api key' - assert os.environ['LOADTESTING_API_KEY'] == 'loadtesting api key' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_redis_config(): - extract_cloudfoundry_config() - - assert os.environ['REDIS_ENABLED'] == '1' - assert os.environ['REDIS_URL'] == 'redis url' - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -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_firetext_inbound_sms_auth_config(): - extract_cloudfoundry_config() - - assert os.environ['FIRETEXT_INBOUND_SMS_AUTH'] == json.dumps(['testkey']) - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_mmg_inbound_sms_auth_config(): - extract_cloudfoundry_config() - - assert os.environ['MMG_INBOUND_SMS_AUTH'] == json.dumps(['testkey']) - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_mmg_inbound_sms_username_config(): - extract_cloudfoundry_config() - - assert os.environ['MMG_INBOUND_SMS_USERNAME'] == json.dumps(['username']) - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_performance_platform_config(): - extract_cloudfoundry_config() - - assert json.loads(os.environ['PERFORMANCE_PLATFORM_ENDPOINTS']) == { - 'foo': 'my_token', - 'bar': 'other_token' - } - - -@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') -def test_template_preview_config(): - extract_cloudfoundry_config() - - assert os.environ['TEMPLATE_PREVIEW_API_HOST'] == 'template-preview api host' - assert os.environ['TEMPLATE_PREVIEW_API_KEY'] == 'template-preview api key'