mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 01:13:12 -04:00
Use VCAP_APPLICATION to detect CloudFoundry environment
VCAP_SERVICES is not set on PaaS if no services are bound to the application, so we need to check for VCAP_APPLICATION to parse the application name and environment.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
if os.environ.get('VCAP_SERVICES'):
|
if os.environ.get('VCAP_APPLICATION'):
|
||||||
# on cloudfoundry, config is a json blob in VCAP_SERVICES - unpack it, and populate
|
# on cloudfoundry, config is a json blob in VCAP_APPLICATION - unpack it, and populate
|
||||||
# standard environment variables from it
|
# standard environment variables from it
|
||||||
from app.cloudfoundry_config import extract_cloudfoundry_config
|
from app.cloudfoundry_config import extract_cloudfoundry_config
|
||||||
extract_cloudfoundry_config()
|
extract_cloudfoundry_config()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def reload_config():
|
|||||||
|
|
||||||
def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
||||||
os.environ['API_HOST_NAME'] = 'env'
|
os.environ['API_HOST_NAME'] = 'env'
|
||||||
monkeypatch.setenv('VCAP_SERVICES', 'some json blob')
|
monkeypatch.setenv('VCAP_APPLICATION', 'some json blob')
|
||||||
|
|
||||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config:
|
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config:
|
||||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||||
@@ -41,7 +41,7 @@ def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
|||||||
def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config):
|
def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config):
|
||||||
os.environ['API_HOST_NAME'] = 'env'
|
os.environ['API_HOST_NAME'] = 'env'
|
||||||
|
|
||||||
monkeypatch.delenv('VCAP_SERVICES', raising=False)
|
monkeypatch.delenv('VCAP_APPLICATION', raising=False)
|
||||||
|
|
||||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config:
|
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config:
|
||||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||||
|
|||||||
Reference in New Issue
Block a user