From 5c1ff011e426ecaa4aec333990855ebcbde1528b Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 25 Nov 2015 14:57:26 -0800 Subject: [PATCH] Recommended fields vs suggested fields --- tests.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index f2b207a..ee06f4a 100755 --- a/tests.py +++ b/tests.py @@ -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))