Added possibility of if directive in each entry
This commit is contained in:
@@ -42,7 +42,8 @@ ConfigDictTemplate = [
|
|||||||
"default": "rspamd",
|
"default": "rspamd",
|
||||||
"customizable": True,
|
"customizable": True,
|
||||||
"question": "Please select your antispam utility",
|
"question": "Please select your antispam utility",
|
||||||
"values": ["rspamd", "amavis"]
|
"values": ["rspamd", "amavis"],
|
||||||
|
"if": ["antispam.enabled=true"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -293,6 +293,16 @@ def random_key(l=16):
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
def check_if_condition(config, entry):
|
||||||
|
"""Check if the "if" directive is present and computes it"""
|
||||||
|
section_if = True
|
||||||
|
for condition in entry:
|
||||||
|
config_key, value = condition.split("=")
|
||||||
|
section_name, option = config_key.split(".")
|
||||||
|
section_if = config.get(section_name, option) == value
|
||||||
|
return section_if
|
||||||
|
|
||||||
|
|
||||||
def validate(value, config_entry):
|
def validate(value, config_entry):
|
||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
@@ -362,15 +372,19 @@ def load_config_template(interactive):
|
|||||||
for section in tpl_dict:
|
for section in tpl_dict:
|
||||||
interactive_section = interactive
|
interactive_section = interactive
|
||||||
if "if" in section:
|
if "if" in section:
|
||||||
for condition in section.get("if"):
|
condition = check_if_condition(config, section["if"])
|
||||||
config_key, value = condition.split("=")
|
interactive_section = condition and interactive
|
||||||
section_name, option = config_key.split(".")
|
|
||||||
interactive_section = interactive_section and (
|
|
||||||
config.get(section_name, option) == value)
|
|
||||||
|
|
||||||
config.add_section(section["name"])
|
config.add_section(section["name"])
|
||||||
for config_entry in section["values"]:
|
for config_entry in section["values"]:
|
||||||
value = get_entry_value(config_entry, interactive_section)
|
if config_entry.get("if") is not None:
|
||||||
|
interactive_section = (interactive_section and
|
||||||
|
check_if_condition(
|
||||||
|
config, config_entry["if"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
value = get_entry_value(config_entry,
|
||||||
|
interactive_section)
|
||||||
config.set(section["name"], config_entry["option"], value)
|
config.set(section["name"], config_entry["option"], value)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user