This commit is contained in:
xuu 2017-11-10 14:57:21 -07:00
parent cef18d1988
commit 6accee0a74
No known key found for this signature in database
GPG key ID: 8B3B0604F164E04F
4 changed files with 23 additions and 6 deletions

View file

@ -6,17 +6,24 @@ if [ $# -eq 0 ]
exit
fi
if [[ "$1" = "--all" ]]
then
MNT=""
else
MNT="-m $1"
fi
BASE="$(realpath "$0")"
BASE="$(dirname "$BASE")"
cd "$BASE" || exit 1
utils/schema-check/dn42-schema.py -v scan data/ -m "$1" || ( echo "Schema validation failed, please check above!" ; exit 1 )
utils/schema-check/dn42-schema.py -v scan data/ $MNT || ( echo "Schema validation failed, please check above!" ; exit 1 )
exit 0
git diff --cached --name-only | while IFS='/' read -ra LINE; do
if [[ "${LINE[0]}" = "data" ]]; then
if ! utils/schema-check/dn42-schema.py policy ${LINE[1]} ${LINE[2]} $1; then
if ! utils/schema-check/dn42-schema.py policy ${LINE[1]} ${LINE[2]} $MNT; then
echo "# This file fails policy checks. To continue with the commit revert the change."
echo "# git reset HEAD -- " ${LINE[1]}/${LINE[1]}/${LINE[2]}
echo "# git checkout -- " ${LINE[1]}/${LINE[1]}/${LINE[2]}

View file

@ -4,4 +4,4 @@ admin-c: JRB0001-DN42
tech-c: JRB0001-DN42
mnt-by: JRB0001-MNT
status: ASSIGNED
cidr: fd42:5d71:217:ffff:ffff:ffff:0467::/112
cidr: fd42:5d71:217:ffff:ffff:ffff:467::/112

View file

@ -1,7 +1,7 @@
schema: SCHEMA-SCHEMA
ref: dn42.schema
key: schema required single schema > [name]
key: ref required single primary > [schema]
key: schema required single schema primary > [name]
key: ref required single > [schema]
key: key required multiple > [key-name]
{required|optional|recommend|deprecate}
{one|many} {single|multi} {primary|} {schema|}

View file

@ -20,6 +20,8 @@ class SchemaDOM:
schema = None
name = None
ref = None
primary = None
type = None
def __init__(self, fn):
self.src = fn
@ -39,6 +41,7 @@ class SchemaDOM:
v = v.split()
key = v.pop(0)
schema[key] = set()
for i in v:
if i == ">":
@ -47,7 +50,11 @@ class SchemaDOM:
schema[key].add(i)
for k, v in schema.items():
if 'schema' in v:
self.type = k
if 'primary' in v:
self.primary = k
schema[k].add("oneline")
if "multiline" in v:
schema[k].remove("multiline")
@ -71,7 +78,6 @@ class SchemaDOM:
def check_file(self, f, lookups=None):
status = "PASS"
for k, v in self.schema.items():
if 'required' in v and k not in f.keys:
log.error(
@ -102,6 +108,10 @@ class SchemaDOM:
status = "FAIL"
for k, v, l in f.dom:
if k == self.primary and not f.src.endswith("/" + v.replace("/","_").replace(" ","")):
log.error("%s Line %d: Primary [%s: %s] does not match filename." % (f.src, l, k, v))
status = "FAIL"
if k.startswith("x-"):
log.info("%s Line %d: Key [%s] is user defined." % (f.src, l, k))