diff --git a/bootstrap.py b/bootstrap.py index 4eb9937..51313b7 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -37,17 +37,21 @@ with open('servers.json', 'r') as server_fh: MODULES = jsonfile['modules'] -async def set_linked_multi_variables(linked_server: str, +async def set_linked_multi_variables(value: str, + linked_server: str=None, **kwargs: dict, ) -> None: - + if value is not None and linked_server is not None and 'linked_value_0' not in kwargs: + kwargs['linked_value_0'] = value + elif linked_server is None: + linked_server = value if linked_server is None: return if linked_server not in CONFIGS: warn_explicit(ValueWarning(f'cannot find linked server "{linked_server}"'), ValueWarning, __file__, - 0, + 3, ) return config = CONFIGS[linked_server][0] @@ -74,27 +78,35 @@ async def set_linked_multi_variables(linked_server: str, dynamic = None slave_idx = None await config.property.read_write() + first_variable = variables[0]['value'] + if not isinstance(variables[0]['value'], list): + variables[0]['value'] = [variables[0]['value']] try: - for index in sorted(list(variables)): - path = variables[index]['path'] - value = variables[index]['value'] - if dynamic: - path = path.replace('{suffix}', dynamic) - else: - dynamic = normalize_family(value) - option = config.forcepermissive.option(path, slave_idx) - multi = await option.option.ismulti() - if multi and await option.option.isfollower(): - multi = await option.option.issubmulti() - if multi: - values = await option.value.get() - if value not in values: - values.append(value) - await option.value.set(values) - if await option.option.isleader(): - slave_idx = values.index(value) - else: - await option.value.set(value) + for var_index in range(len(variables[0]['value'])): + pass + for index in sorted(list(variables)): + path = variables[index]['path'] + if index == 0: + value = variables[index]['value'][var_index] + dynamic = normalize_family(value) + else: + value = variables[index]['value'] + path = path.replace('{suffix}', dynamic) + option = config.forcepermissive.option(path, slave_idx) + multi = await option.option.ismulti() + if multi and await option.option.isfollower(): + multi = await option.option.issubmulti() + if multi: + values = await option.value.get() + if value not in values: + values.append(value) + await option.value.set(values) + if await option.option.isleader(): + slave_idx = values.index(value) + else: + if isinstance(value, list): + value = value[var_index] + await option.value.set(value) except Exception as err: await config.property.read_only() raise err from err @@ -324,6 +336,8 @@ def build_module(module_name, datas, module_infos): def calc_depends(appname, added): if appname in added: return + if appname not in applications: + raise Exception(f'cannot find application dependency "{appname}" in application "{module_name}"') as_dir = applications[appname] cfg.modules.append(appname) dictionaries_dir = join(as_dir, 'dictionaries') @@ -488,7 +502,7 @@ async def valid_mandatories(server_name, config): async def templates(server_name, config, cfg, srv, int_idx): values = await config.value.dict() engine = RougailSystemdTemplate(config, cfg) -# if server_name == 'revprox.in.silique.fr': +# if server_name == 'dovecot.in.silique.fr': # print() # print(f'=== Configuration: {server_name} ===') # pprint(values) diff --git a/src/risotto/x509.py b/src/risotto/x509.py index f6d41f1..54731c1 100644 --- a/src/risotto/x509.py +++ b/src/risotto/x509.py @@ -154,6 +154,8 @@ def gen_cert_iter(cn, if not isfile(cert_ca_name): raise Exception(f'cannot find CA file "{cert_ca_name}"') if not isfile(cert_name): + if not isfile(key_ca_name): + raise Exception(f"cannot find CA private key (\"{authority_cn}\") to sign certificat for \"{cn}\", is it a Let's Encrypt certification?") if not isdir(dir_name): makedirs(dir_name) if isfile(sn_name):