diff options
| author | John Estabrook <jestabro@vyos.io> | 2024-10-24 11:04:39 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2024-10-24 11:04:39 -0500 |
| commit | 73e0836d9d64c9dbbf53b82d18ab84e525f59ad6 (patch) | |
| tree | f858ca6fe042a79fbd809aeafe9e33a7ef946cb9 /src/reference_tree.ml | |
| parent | 8bb9e607eb1c7b0a701292a36583c91f4a0cdc7b (diff) | |
| download | vyos1x-config-73e0836d9d64c9dbbf53b82d18ab84e525f59ad6.tar.gz vyos1x-config-73e0836d9d64c9dbbf53b82d18ab84e525f59ad6.zip | |
T6718: validate_path returns unit instead of (path, value)
Splitting of path arg into (path, value), as originally returned by
validate_path, is now handled by a utility function. validate_path
returns unit on success and raises error with output on failure.
Diffstat (limited to 'src/reference_tree.ml')
| -rw-r--r-- | src/reference_tree.ml | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index 6472cb5..bda7b0e 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -261,20 +261,20 @@ let validate_path validators_dir node path = begin match path with | [] -> - if data.valueless then (List.rev acc, None) + if data.valueless then () else let msg = Printf.sprintf "Configuration path %s requires a value" (show_path acc) in raise (Validation_error msg) | [p] -> if not data.valueless then - let res, out = + let res = try Value_checker.validate_any validators_dir data.constraints p with Value_checker.Bad_validator msg -> raise (Validation_error msg) in match res with - | true -> (List.rev acc, Some p) - | false -> + | None -> () + | Some out -> raise (Validation_error (out ^ data.constraint_error_message)) else let msg = Printf.sprintf "Node %s cannot have a value" (show_path acc) @@ -294,13 +294,13 @@ let validate_path validators_dir node path = Printf.sprintf "Illegal character \"%s\" in node name \"%s\"" c p in raise (Validation_error msg) | None -> - let res, out = + let res = try Value_checker.validate_any validators_dir data.constraints p with Value_checker.Bad_validator msg -> raise (Validation_error msg) in begin match res with - | true -> + | None -> let child = Vytree.find node p' in begin match child with @@ -310,7 +310,7 @@ let validate_path validators_dir node path = Printf.sprintf "Node %s has no child %s" (show_path acc) p' in raise (Validation_error msg) end - | false -> + | Some out -> let msg = Printf.sprintf "%s is not a valid child name for node %s" p (show_path acc) in @@ -326,14 +326,14 @@ let validate_path validators_dir node path = Printf.sprintf "Illegal character \"%s\" in node name \"%s\"" c p in raise (Validation_error msg) | None -> - let res, out = + let res = try Value_checker.validate_any validators_dir data.constraints p with Value_checker.Bad_validator msg -> raise (Validation_error msg) in begin match res with - | true -> (List.rev acc, None) - | false -> + | None -> () + | Some out -> let msg = Printf.sprintf "%s is not a valid child name for node %s" p (show_path acc) in @@ -349,7 +349,7 @@ let validate_path validators_dir node path = | Other -> begin match path with - | [] -> (List.rev acc, None) + | [] -> () | p :: ps -> let child = Vytree.find node p in match child with @@ -360,6 +360,41 @@ let validate_path validators_dir node path = end in aux node path [] +(* This is only to be used after the path has been validated *) +let split_path node path = + let rec aux node path acc = + let data = Vytree.data_of_node node in + match data.node_type with + | Leaf -> + begin + match path with + | [] -> (List.rev acc, None) + | [p] -> (List.rev acc, Some p) + | _ -> (List.rev acc, None) + end + | Tag -> + begin + match path with + | p :: p' :: ps -> + (let child = Vytree.find node p' in + match child with + | Some c -> aux c ps (p' :: p :: acc) + | None -> (List.rev acc, None)) + | [_] -> (List.rev acc, None) + | _ -> (List.rev acc, None) + end + | Other -> + begin + match path with + | [] -> (List.rev acc, None) + | p :: ps -> + let child = Vytree.find node p in + match child with + | Some c -> aux c ps (p :: acc) + | None -> (List.rev acc, None) + end + in aux node path [] + let is_multi reftree path = let data = Vytree.get_data reftree path in data.multi |
