mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-02 09:10:11 +02:00
support env vars in config.yml: awsaccesskeyid: {env: AWS_KEY}
This commit is contained in:
parent
d3d48dba5e
commit
2d115135f7
@ -388,6 +388,20 @@ def read_config(opts):
|
||||
limit = config['git_mirror_size_limit']
|
||||
config['git_mirror_size_limit'] = parse_human_readable_size(limit)
|
||||
|
||||
for configname, dictvalue in config.items():
|
||||
if isinstance(dictvalue, dict) \
|
||||
and configname not in ('ndk_paths', 'java_paths', 'char_limits', 'keyaliases'):
|
||||
for k, v in dictvalue.items():
|
||||
if k == 'env':
|
||||
env = os.getenv(v)
|
||||
config[configname] = env
|
||||
if not env:
|
||||
logging.error(_('Environment variable {var} from {configname} is not set!')
|
||||
.format(var=k, configname=configname))
|
||||
else:
|
||||
logging.error(_('Unknown entry {key} in {configname}')
|
||||
.format(key=k, configname=configname))
|
||||
|
||||
return config
|
||||
|
||||
|
||||
|
@ -1431,6 +1431,18 @@ class CommonTest(unittest.TestCase):
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
self.assertEqual('yml', config.get('apksigner'))
|
||||
|
||||
def test_with_config_yml_with_env_var(self):
|
||||
"""Make sure it is possible to use config.yml alone."""
|
||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
||||
os.chdir(testdir)
|
||||
os.environ['SECRET'] = 'mysecretpassword'
|
||||
with open('config.yml', 'w') as fp:
|
||||
fp.write("""keypass: {'env': 'SECRET'}""")
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
self.assertEqual(os.getenv('SECRET', 'fail'), config.get('keypass'))
|
||||
|
||||
def test_with_config_py(self):
|
||||
"""Make sure it is still possible to use config.py alone."""
|
||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
||||
|
Loading…
Reference in New Issue
Block a user