set_linked_multi_variables

This commit is contained in:
Emmanuel Garette 2022-04-28 21:46:26 +02:00
parent 127dba8c52
commit 76a99dc532
2 changed files with 40 additions and 24 deletions

View file

@ -37,17 +37,21 @@ with open('servers.json', 'r') as server_fh:
MODULES = jsonfile['modules'] 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, **kwargs: dict,
) -> None: ) -> 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: if linked_server is None:
return return
if linked_server not in CONFIGS: if linked_server not in CONFIGS:
warn_explicit(ValueWarning(f'cannot find linked server "{linked_server}"'), warn_explicit(ValueWarning(f'cannot find linked server "{linked_server}"'),
ValueWarning, ValueWarning,
__file__, __file__,
0, 3,
) )
return return
config = CONFIGS[linked_server][0] config = CONFIGS[linked_server][0]
@ -74,27 +78,35 @@ async def set_linked_multi_variables(linked_server: str,
dynamic = None dynamic = None
slave_idx = None slave_idx = None
await config.property.read_write() await config.property.read_write()
first_variable = variables[0]['value']
if not isinstance(variables[0]['value'], list):
variables[0]['value'] = [variables[0]['value']]
try: try:
for index in sorted(list(variables)): for var_index in range(len(variables[0]['value'])):
path = variables[index]['path'] pass
value = variables[index]['value'] for index in sorted(list(variables)):
if dynamic: path = variables[index]['path']
path = path.replace('{suffix}', dynamic) if index == 0:
else: value = variables[index]['value'][var_index]
dynamic = normalize_family(value) dynamic = normalize_family(value)
option = config.forcepermissive.option(path, slave_idx) else:
multi = await option.option.ismulti() value = variables[index]['value']
if multi and await option.option.isfollower(): path = path.replace('{suffix}', dynamic)
multi = await option.option.issubmulti() option = config.forcepermissive.option(path, slave_idx)
if multi: multi = await option.option.ismulti()
values = await option.value.get() if multi and await option.option.isfollower():
if value not in values: multi = await option.option.issubmulti()
values.append(value) if multi:
await option.value.set(values) values = await option.value.get()
if await option.option.isleader(): if value not in values:
slave_idx = values.index(value) values.append(value)
else: await option.value.set(values)
await option.value.set(value) 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: except Exception as err:
await config.property.read_only() await config.property.read_only()
raise err from err raise err from err
@ -324,6 +336,8 @@ def build_module(module_name, datas, module_infos):
def calc_depends(appname, added): def calc_depends(appname, added):
if appname in added: if appname in added:
return return
if appname not in applications:
raise Exception(f'cannot find application dependency "{appname}" in application "{module_name}"')
as_dir = applications[appname] as_dir = applications[appname]
cfg.modules.append(appname) cfg.modules.append(appname)
dictionaries_dir = join(as_dir, 'dictionaries') 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): async def templates(server_name, config, cfg, srv, int_idx):
values = await config.value.dict() values = await config.value.dict()
engine = RougailSystemdTemplate(config, cfg) engine = RougailSystemdTemplate(config, cfg)
# if server_name == 'revprox.in.silique.fr': # if server_name == 'dovecot.in.silique.fr':
# print() # print()
# print(f'=== Configuration: {server_name} ===') # print(f'=== Configuration: {server_name} ===')
# pprint(values) # pprint(values)

View file

@ -154,6 +154,8 @@ def gen_cert_iter(cn,
if not isfile(cert_ca_name): if not isfile(cert_ca_name):
raise Exception(f'cannot find CA file "{cert_ca_name}"') raise Exception(f'cannot find CA file "{cert_ca_name}"')
if not isfile(cert_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): if not isdir(dir_name):
makedirs(dir_name) makedirs(dir_name)
if isfile(sn_name): if isfile(sn_name):