Move config handling into a provider class to make testing much easier
This commit is contained in:
parent
c0c27648ea
commit
6d604a656a
8 changed files with 207 additions and 121 deletions
|
@ -7,35 +7,6 @@ def generate_secret_key():
|
|||
return str(cryptogen.getrandbits(256))
|
||||
|
||||
|
||||
def import_yaml(config_obj, config_file):
|
||||
with open(config_file) as f:
|
||||
c = yaml.safe_load(f)
|
||||
if not c:
|
||||
logger.debug('Empty YAML config file')
|
||||
return
|
||||
|
||||
if isinstance(c, str):
|
||||
raise Exception('Invalid YAML config file: ' + str(c))
|
||||
|
||||
for key in c.iterkeys():
|
||||
if key.isupper():
|
||||
config_obj[key] = c[key]
|
||||
|
||||
|
||||
def export_yaml(config_obj, config_file):
|
||||
with open(config_file, 'w') as f:
|
||||
f.write(yaml.safe_dump(config_obj, encoding='utf-8', allow_unicode=True))
|
||||
|
||||
|
||||
def set_config_value(config_file, config_key, value):
|
||||
""" Loads the configuration from the given YAML config file, sets the given key to
|
||||
the given value, and then writes it back out to the given YAML config file. """
|
||||
config_obj = {}
|
||||
import_yaml(config_obj, config_file)
|
||||
config_obj[config_key] = value
|
||||
export_yaml(config_obj, config_file)
|
||||
|
||||
|
||||
def add_enterprise_config_defaults(config_obj, current_secret_key, hostname):
|
||||
""" Adds/Sets the config defaults for enterprise registry config. """
|
||||
# These have to be false.
|
||||
|
|
Reference in a new issue