mirror of
https://github.com/cwinfo/hyperboria-peers.git
synced 2024-11-22 09:30:27 +00:00
Recommended fields vs suggested fields
This commit is contained in:
parent
403bb4dcf2
commit
5c1ff011e4
17
tests.py
17
tests.py
@ -4,10 +4,11 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
REQUIRED_FIELDS = ['publicKey', 'password', 'contact']
|
REQUIRED_FIELDS = ['publicKey', 'password', 'contact']
|
||||||
|
RECOMMENDED_FIELDS = ['gpg']
|
||||||
|
|
||||||
RED = '\x1b[01;31m'
|
RED = '\x1b[01;31m'
|
||||||
GREEN = '\x1b[01;32m'
|
GREEN = '\x1b[01;32m'
|
||||||
|
YELLOW = '\x1b[01;33m'
|
||||||
END = '\x1b[0m'
|
END = '\x1b[0m'
|
||||||
|
|
||||||
|
|
||||||
@ -17,12 +18,22 @@ def validate(path):
|
|||||||
creds = open(path).read()
|
creds = open(path).read()
|
||||||
peers = json.loads("{%s}" % creds)
|
peers = json.loads("{%s}" % creds)
|
||||||
hosts = peers.keys()
|
hosts = peers.keys()
|
||||||
|
warning = False
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
for field in REQUIRED_FIELDS:
|
for field in REQUIRED_FIELDS:
|
||||||
if not field in peers[host]:
|
if not field in peers[host]:
|
||||||
print(" %sHost %s is missing the %s field!%s" % (RED, host, field, END))
|
print(" %sHost %s is missing the required field %s%s" % (RED, host,
|
||||||
|
field, END))
|
||||||
return False
|
return False
|
||||||
print(" %sSuccess!%s" % (GREEN, END))
|
for field in RECOMMENDED_FIELDS:
|
||||||
|
if not field in peers[host]:
|
||||||
|
warning = True
|
||||||
|
print(" %sHost %s is missing the recommended field %s%s" % (YELLOW, host,
|
||||||
|
field, END))
|
||||||
|
if warning:
|
||||||
|
print(" %sSuccess, but missing recommended fields%s" % (YELLOW, END))
|
||||||
|
else:
|
||||||
|
print(" %sSuccess!%s" % (YELLOW, END))
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(" %sInvalid JSON!%s" % (RED, END))
|
print(" %sInvalid JSON!%s" % (RED, END))
|
||||||
|
Loading…
Reference in New Issue
Block a user