5
0
mirror of https://github.com/cwinfo/hyperboria-peers.git synced 2024-11-22 04:50:28 +00:00

Recommended fields vs suggested fields

This commit is contained in:
Finn 2015-11-25 14:57:26 -08:00
parent 403bb4dcf2
commit 5c1ff011e4

View File

@ -4,10 +4,11 @@ import os
import sys
REQUIRED_FIELDS = ['publicKey', 'password', 'contact']
RECOMMENDED_FIELDS = ['gpg']
RED = '\x1b[01;31m'
GREEN = '\x1b[01;32m'
YELLOW = '\x1b[01;33m'
END = '\x1b[0m'
@ -17,12 +18,22 @@ def validate(path):
creds = open(path).read()
peers = json.loads("{%s}" % creds)
hosts = peers.keys()
warning = False
for host in hosts:
for field in REQUIRED_FIELDS:
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
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
except ValueError:
print(" %sInvalid JSON!%s" % (RED, END))