mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 02:32:32 -05:00
Allow REDIS_URL to optionally come from PaaS
This is to support a migration from Redislabs to PaaS native Redis, allowing us to toggle between old and new using the env vars for the instance - without needing to change the code.
This commit is contained in:
@@ -16,6 +16,9 @@ def set_config_env_vars(vcap_services):
|
|||||||
# Postgres config
|
# Postgres config
|
||||||
os.environ['SQLALCHEMY_DATABASE_URI'] = vcap_services['postgres'][0]['credentials']['uri'].replace('postgres',
|
os.environ['SQLALCHEMY_DATABASE_URI'] = vcap_services['postgres'][0]['credentials']['uri'].replace('postgres',
|
||||||
'postgresql')
|
'postgresql')
|
||||||
|
# Redis config
|
||||||
|
if 'redis' in vcap_services:
|
||||||
|
os.environ['REDIS_URL'] = vcap_services['redis'][0]['credentials']['uri']
|
||||||
|
|
||||||
vcap_application = json.loads(os.environ['VCAP_APPLICATION'])
|
vcap_application = json.loads(os.environ['VCAP_APPLICATION'])
|
||||||
os.environ['NOTIFY_ENVIRONMENT'] = vcap_application['space_name']
|
os.environ['NOTIFY_ENVIRONMENT'] = vcap_application['space_name']
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ def cloudfoundry_config():
|
|||||||
'uri': 'postgres uri'
|
'uri': 'postgres uri'
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
'redis': [{
|
||||||
|
'credentials': {
|
||||||
|
'uri': 'redis uri'
|
||||||
|
}
|
||||||
|
}],
|
||||||
'user-provided': []
|
'user-provided': []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +36,7 @@ def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_config, v
|
|||||||
extract_cloudfoundry_config()
|
extract_cloudfoundry_config()
|
||||||
|
|
||||||
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgresql uri'
|
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgresql uri'
|
||||||
|
assert os.environ['REDIS_URL'] == 'redis uri'
|
||||||
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
|
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
|
||||||
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
||||||
|
|
||||||
@@ -45,3 +51,9 @@ def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, vcap_a
|
|||||||
|
|
||||||
assert 'foo' not in os.environ
|
assert 'foo' not in os.environ
|
||||||
assert 'bar' not in os.environ
|
assert 'bar' not in os.environ
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_config_env_vars_copes_if_redis_not_set(cloudfoundry_config, vcap_application):
|
||||||
|
del cloudfoundry_config['redis']
|
||||||
|
set_config_env_vars(cloudfoundry_config)
|
||||||
|
assert 'REDIS_URL' not in os.environ
|
||||||
|
|||||||
Reference in New Issue
Block a user