summaryrefslogtreecommitdiff
path: root/src/value_checker.ml
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-10-23 18:50:46 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-10-27 20:50:41 -0500
commit5d7927e392e70436aaca1f8261e5d4ab8e4ec8f8 (patch)
treed824589851f788ab4864c31b44ec6cbab2f5cefe /src/value_checker.ml
parentdd9271b4304c6b1a5a2576821d1b2b8fd3aa6bf5 (diff)
downloadvyconf-5d7927e392e70436aaca1f8261e5d4ab8e4ec8f8.tar.gz
vyconf-5d7927e392e70436aaca1f8261e5d4ab8e4ec8f8.zip
T6718: update build system, drop batteries, and adjust for lib changes
Update as needed for use with contemporary vyos1x-config: . update build system to use dune . drop use of batteries . update for protoc breaking changes in versions >= 3.0 . remove files now in vyos1x-config (config_tree et. al.; parsing)
Diffstat (limited to 'src/value_checker.ml')
-rw-r--r--src/value_checker.ml39
1 files changed, 0 insertions, 39 deletions
diff --git a/src/value_checker.ml b/src/value_checker.ml
deleted file mode 100644
index aa88f7b..0000000
--- a/src/value_checker.ml
+++ /dev/null
@@ -1,39 +0,0 @@
-module F = Filename
-
-type value_constraint = Regex of string | External of string * string option
-
-exception Bad_validator of string
-
-let validate_value dir value_constraint value =
- match value_constraint with
- | Regex s ->
- (try
- let _ = Pcre.exec ~pat:s value in true
- with Not_found -> false)
- | External (v, c) ->
- (* XXX: Using Unix.system is a bad idea on multiple levels,
- especially when the input comes directly from the user...
- We should do something about it.
- *)
- let validator = F.concat dir v in
- let arg = BatOption.default "" c in
- let safe_arg = Printf.sprintf "'%s'" (Pcre.qreplace ~pat:"\"" ~templ:"\\\"" arg) in
- let result = Unix.system (Printf.sprintf "%s %s %s" validator safe_arg value) in
- match result with
- | Unix.WEXITED 0 -> true
- | Unix.WEXITED 127 -> raise (Bad_validator (Printf.sprintf "Could not execute validator %s" validator))
- | _ -> false
-
-(* If no constraints given, consider it valid.
- Otherwise consider it valid if it satisfies at least
- one constraint *)
-let validate_any validators constraints value =
- let rec aux validators constraints value =
- match constraints with
- | [] -> false
- | c :: cs -> if validate_value validators c value then true
- else aux validators cs value
- in
- match constraints with
- | [] -> true
- | _ -> aux validators constraints value