mirror of
https://git.dn42.dev/dn42/registry.git
synced 2025-05-06 20:55:23 +08:00
fix
This commit is contained in:
parent
cef18d1988
commit
6accee0a74
4 changed files with 23 additions and 6 deletions
|
@ -6,17 +6,24 @@ if [ $# -eq 0 ]
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" = "--all" ]]
|
||||||
|
then
|
||||||
|
MNT=""
|
||||||
|
else
|
||||||
|
MNT="-m $1"
|
||||||
|
fi
|
||||||
|
|
||||||
BASE="$(realpath "$0")"
|
BASE="$(realpath "$0")"
|
||||||
BASE="$(dirname "$BASE")"
|
BASE="$(dirname "$BASE")"
|
||||||
cd "$BASE" || exit 1
|
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
|
exit 0
|
||||||
|
|
||||||
git diff --cached --name-only | while IFS='/' read -ra LINE; do
|
git diff --cached --name-only | while IFS='/' read -ra LINE; do
|
||||||
if [[ "${LINE[0]}" = "data" ]]; then
|
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 "# 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 reset HEAD -- " ${LINE[1]}/${LINE[1]}/${LINE[2]}
|
||||||
echo "# git checkout -- " ${LINE[1]}/${LINE[1]}/${LINE[2]}
|
echo "# git checkout -- " ${LINE[1]}/${LINE[1]}/${LINE[2]}
|
||||||
|
|
|
@ -4,4 +4,4 @@ admin-c: JRB0001-DN42
|
||||||
tech-c: JRB0001-DN42
|
tech-c: JRB0001-DN42
|
||||||
mnt-by: JRB0001-MNT
|
mnt-by: JRB0001-MNT
|
||||||
status: ASSIGNED
|
status: ASSIGNED
|
||||||
cidr: fd42:5d71:217:ffff:ffff:ffff:0467::/112
|
cidr: fd42:5d71:217:ffff:ffff:ffff:467::/112
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
schema: SCHEMA-SCHEMA
|
schema: SCHEMA-SCHEMA
|
||||||
ref: dn42.schema
|
ref: dn42.schema
|
||||||
key: schema required single schema > [name]
|
key: schema required single schema primary > [name]
|
||||||
key: ref required single primary > [schema]
|
key: ref required single > [schema]
|
||||||
key: key required multiple > [key-name]
|
key: key required multiple > [key-name]
|
||||||
{required|optional|recommend|deprecate}
|
{required|optional|recommend|deprecate}
|
||||||
{one|many} {single|multi} {primary|} {schema|}
|
{one|many} {single|multi} {primary|} {schema|}
|
||||||
|
|
|
@ -20,6 +20,8 @@ class SchemaDOM:
|
||||||
schema = None
|
schema = None
|
||||||
name = None
|
name = None
|
||||||
ref = None
|
ref = None
|
||||||
|
primary = None
|
||||||
|
type = None
|
||||||
|
|
||||||
def __init__(self, fn):
|
def __init__(self, fn):
|
||||||
self.src = fn
|
self.src = fn
|
||||||
|
@ -39,6 +41,7 @@ class SchemaDOM:
|
||||||
|
|
||||||
v = v.split()
|
v = v.split()
|
||||||
key = v.pop(0)
|
key = v.pop(0)
|
||||||
|
|
||||||
schema[key] = set()
|
schema[key] = set()
|
||||||
for i in v:
|
for i in v:
|
||||||
if i == ">":
|
if i == ">":
|
||||||
|
@ -47,7 +50,11 @@ class SchemaDOM:
|
||||||
schema[key].add(i)
|
schema[key].add(i)
|
||||||
|
|
||||||
for k, v in schema.items():
|
for k, v in schema.items():
|
||||||
|
if 'schema' in v:
|
||||||
|
self.type = k
|
||||||
|
|
||||||
if 'primary' in v:
|
if 'primary' in v:
|
||||||
|
self.primary = k
|
||||||
schema[k].add("oneline")
|
schema[k].add("oneline")
|
||||||
if "multiline" in v:
|
if "multiline" in v:
|
||||||
schema[k].remove("multiline")
|
schema[k].remove("multiline")
|
||||||
|
@ -71,7 +78,6 @@ class SchemaDOM:
|
||||||
|
|
||||||
def check_file(self, f, lookups=None):
|
def check_file(self, f, lookups=None):
|
||||||
status = "PASS"
|
status = "PASS"
|
||||||
|
|
||||||
for k, v in self.schema.items():
|
for k, v in self.schema.items():
|
||||||
if 'required' in v and k not in f.keys:
|
if 'required' in v and k not in f.keys:
|
||||||
log.error(
|
log.error(
|
||||||
|
@ -102,6 +108,10 @@ class SchemaDOM:
|
||||||
status = "FAIL"
|
status = "FAIL"
|
||||||
|
|
||||||
for k, v, l in f.dom:
|
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-"):
|
if k.startswith("x-"):
|
||||||
log.info("%s Line %d: Key [%s] is user defined." % (f.src, l, k))
|
log.info("%s Line %d: Key [%s] is user defined." % (f.src, l, k))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue