support env vars in config.yml: awsaccesskeyid: {env: AWS_KEY}

This commit is contained in:
Hans-Christoph Steiner 2020-10-22 19:08:08 +02:00
parent d3d48dba5e
commit 2d115135f7
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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)