Skip to content

Commit

Permalink
Merge branch 'master' into 2429-remote-config
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed May 19, 2015
2 parents 8ccc6b2 + 0f145a5 commit 332dce7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
15 changes: 10 additions & 5 deletions ckan/config/environment.py
Expand Up @@ -232,13 +232,18 @@ def genshi_lookup_attr(cls, obj, key):
p.load_all(config)


# A list of config settings that can be overridden by environmental variable.
ENV_VAR_WHITELIST = {
# A mapping of config settings that can be overridden by env vars.
CONFIG_FROM_ENV_VARS = {
'sqlalchemy.url': 'CKAN_SQLALCHEMY_URL',
'ckan.datastore.write_url': 'CKAN_DATASTORE_WRITE_URL',
'ckan.datastore.read_url': 'CKAN_DATASTORE_READ_URL',
'solr_url': 'CKAN_SOLR_URL',
'ckan.site_id': 'CKAN_SITE_ID'
'ckan.site_id': 'CKAN_SITE_ID',
'smtp.server': 'CKAN_SMTP_SERVER',
'smtp.starttls': 'CKAN_SMTP_STARTTLS',
'smtp.user': 'CKAN_SMTP_USER',
'smtp.password': 'CKAN_SMTP_PASSWORD',
'smtp.mail_from': 'CKAN_SMTP_MAIL_FROM'
}


Expand All @@ -261,8 +266,8 @@ def update_config():
log.warn(msg)
config['sqlalchemy.url'] = ckan_db

for option in ENV_VAR_WHITELIST:
from_env = os.environ.get(ENV_VAR_WHITELIST[option], None)
for option in CONFIG_FROM_ENV_VARS:
from_env = os.environ.get(CONFIG_FROM_ENV_VARS[option], None)
if from_env:
config[option] = from_env

Expand Down
22 changes: 15 additions & 7 deletions ckan/tests/config/test_environment.py
Expand Up @@ -20,7 +20,12 @@ class TestUpdateConfig(h.FunctionalTestBase):
('CKAN_DATASTORE_READ_URL', 'http://mynewdbreadurl/'),
('CKAN_SOLR_URL', 'http://mynewsolrurl/solr'),
('CKAN_SITE_ID', 'my-site'),
('CKAN_DB', 'postgresql://mydeprectatesqlurl/')
('CKAN_DB', 'postgresql://mydeprectatesqlurl/'),
('CKAN_SMTP_SERVER', 'mail.example.com'),
('CKAN_SMTP_STARTTLS', 'True'),
('CKAN_SMTP_USER', 'my_user'),
('CKAN_SMTP_PASSWORD', 'password'),
('CKAN_SMTP_MAIL_FROM', 'server@example.com')
]

def _setup_env_vars(self):
Expand All @@ -43,19 +48,22 @@ def test_update_config_env_vars(self):
'''
self._setup_env_vars()

nosetools.assert_equal(config['solr_url'],
'http://mynewsolrurl/solr')
nosetools.assert_equal(config['solr_url'], 'http://mynewsolrurl/solr')
nosetools.assert_equal(config['sqlalchemy.url'],
'postgresql://mynewsqlurl/')
nosetools.assert_equal(config['ckan.datastore.write_url'],
'http://mynewdbwriteurl/')
nosetools.assert_equal(config['ckan.datastore.read_url'],
'http://mynewdbreadurl/')
nosetools.assert_equal(config['ckan.site_id'],
'my-site')
nosetools.assert_equal(config['ckan.site_id'], 'my-site')
nosetools.assert_equal(config['smtp.server'], 'mail.example.com')
nosetools.assert_equal(config['smtp.starttls'], 'True')
nosetools.assert_equal(config['smtp.user'], 'my_user')
nosetools.assert_equal(config['smtp.password'], 'password')
nosetools.assert_equal(config['smtp.mail_from'], 'server@example.com')

def test_update_config_db_url_precidence(self):
'''CKAN_SQLALCHEMY_URL in the env takes precidence over CKAN_DB'''
def test_update_config_db_url_precedence(self):
'''CKAN_SQLALCHEMY_URL in the env takes precedence over CKAN_DB'''
os.environ.setdefault('CKAN_DB', 'postgresql://mydeprectatesqlurl/')
os.environ.setdefault('CKAN_SQLALCHEMY_URL',
'postgresql://mynewsqlurl/')
Expand Down

0 comments on commit 332dce7

Please sign in to comment.