summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-command-templates76
1 files changed, 46 insertions, 30 deletions
diff --git a/scripts/build-command-templates b/scripts/build-command-templates
index 452c420eb..d8abb0a13 100755
--- a/scripts/build-command-templates
+++ b/scripts/build-command-templates
@@ -86,6 +86,37 @@ def make_path(l):
print(path)
return path
+def collect_validators(ve):
+ regexes = []
+ regex_elements = ve.findall("regex")
+ if regex_elements is not None:
+ regexes = list(map(lambda e: e.text.strip().replace('\\','\\\\'), regex_elements))
+ if "" in regexes:
+ print("Warning: empty regex, node will be accepting any value")
+
+ validator_elements = ve.findall("validator")
+ validators = []
+ if validator_elements is not None:
+ for v in validator_elements:
+ v_name = os.path.join(validator_dir, v.get("name"))
+
+ # XXX: lxml returns None for empty arguments
+ v_argument = None
+ try:
+ v_argument = v.get("argument")
+ except:
+ pass
+ if v_argument is None:
+ v_argument = ""
+
+ validators.append("{0} {1}".format(v_name, v_argument))
+
+
+ regex_args = " ".join(map(lambda s: "--regex \\\'{0}\\\'".format(s), regexes))
+ validator_args = " ".join(map(lambda s: "--exec \\\"{0}\\\"".format(s), validators))
+
+ return regex_args + " " + validator_args
+
def get_properties(p):
props = {}
@@ -108,7 +139,8 @@ def get_properties(p):
except:
props["val_help"] = []
- # Get the constraint statements
+ # Get the constraint and constraintGroup statements
+
error_msg = default_constraint_err_msg
# Get the error message if it's there
try:
@@ -117,40 +149,24 @@ def get_properties(p):
pass
vce = p.find("constraint")
- vc = []
+
+ distinct_validator_string = ""
if vce is not None:
# The old backend doesn't support multiple validators in OR mode
# so we emulate it
- regexes = []
- regex_elements = vce.findall("regex")
- if regex_elements is not None:
- regexes = list(map(lambda e: e.text.strip().replace('\\','\\\\'), regex_elements))
- if "" in regexes:
- print("Warning: empty regex, node will be accepting any value")
-
- validator_elements = vce.findall("validator")
- validators = []
- if validator_elements is not None:
- for v in validator_elements:
- v_name = os.path.join(validator_dir, v.get("name"))
-
- # XXX: lxml returns None for empty arguments
- v_argument = None
- try:
- v_argument = v.get("argument")
- except:
- pass
- if v_argument is None:
- v_argument = ""
-
- validators.append("{0} {1}".format(v_name, v_argument))
-
-
- regex_args = " ".join(map(lambda s: "--regex \\\'{0}\\\'".format(s), regexes))
- validator_args = " ".join(map(lambda s: "--exec \\\"{0}\\\"".format(s), validators))
+ distinct_validator_string = collect_validators(vce)
+
+ vcge = p.findall("constraintGroup")
+
+ group_validator_string = ""
+ if len(vcge):
+ for vcg in vcge:
+ group_validator_string = group_validator_string + " --grp " + collect_validators(vcg)
+
+ if vce is not None or len(vcge):
validator_script = '${vyos_libexec_dir}/validate-value'
- validator_string = "exec \"{0} {1} {2} --value \\\'$VAR(@)\\\'\"; \"{3}\"".format(validator_script, regex_args, validator_args, error_msg)
+ validator_string = "exec \"{0} {1} {2} --value \\\'$VAR(@)\\\'\"; \"{3}\"".format(validator_script, distinct_validator_string, group_validator_string, error_msg)
props["constraint"] = validator_string