From 20e2fbebcb6b040397412d437ea48197323409c6 Mon Sep 17 00:00:00 2001 From: e-moran Date: Fri, 22 Nov 2024 15:06:51 +0100 Subject: [PATCH] update validator --- validate.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/validate.js b/validate.js index e13ad40..a7c5380 100644 --- a/validate.js +++ b/validate.js @@ -57,6 +57,44 @@ if (process.argv[2] === "--check") { console.error("Item is missing required `validation` array field:", item); process.exit(1); } + for (const verify of item.verification) { + if (verify.type === "cidr") { + if (!Array.isArray(verify.sources)) { + console.error("Item cidr validation entry is missing required `sources` array field:", item, verify); + process.exit(1); + } + for (const source of verify.sources) { + if (source.type !== "http-json") { + console.error("Cidr source `type` must be a valid type (currently only `http-json` is supported)", item, verify, source); + process.exit(1); + } + + if (typeof source.url !== "string") { + console.error("Cidr source `url` must be a string", item, verify, source); + process.exit(1); + } + + if (typeof source.selector !== "string") { + console.error("Cidr source `selector` must be a string", item, verify, source); + process.exit(1); + } + } + } else if (verify.type === "dns") { + if (!Array.isArray(verify.masks)) { + console.error("Item dns validation entry is missing required `masks` array field:", item, verify); + process.exit(1); + } + for (const mask of verify.masks) { + if (typeof mask !== "string") { + console.error("Mask was not a string:", item, verify, mask); + process.exit(1); + } + } + } else { + console.error("Item validation entry is incorrect, only `dns` and `cidr` are supported:", item, verify); + process.exit(1); + } + } // TODO: Check `addition_date` is defined properly // TODO: Check or remove `depends_on` field if (typeof item.instances !== "undefined") {