From c3aa3715c6a7fcacc8a9659db59878e416f94c68 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 23 Nov 2017 19:19:48 +0000 Subject: [PATCH] Add port and protocol validation --- pool.json | 1 - threshold | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) delete mode 100644 pool.json diff --git a/pool.json b/pool.json deleted file mode 100644 index 9e26dfe..0000000 --- a/pool.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/threshold b/threshold index 7835282..5f1790c 100755 --- a/threshold +++ b/threshold @@ -187,6 +187,12 @@ class Helper(object): incUsage("connect") return + try: + int(spl[3]) + except: + failure("Port must be an integer, not %s" % spl[3]) + return + pool[spl[1]] = { "address": spl[2], "port": spl[3], "protocol": protocol, @@ -252,6 +258,16 @@ class Helper(object): if not spl[2] in pool[spl[1]].keys(): failure("No such key: %s" % spl[2]) return + if spl[2] == "port": + try: + int(spl[3]) + except: + failure("Port must be an integer, not %s" % spl[3]) + return + if spl[2] == "protocol": + if not spl[3] in ["ssl", "plain"]: + failure("Protocol must be ssl or plain, not %s" % spl[3]) + return if spl[3] == pool[spl[1]][spl[2]]: failure("Value already exists: %s" % spl[3]) return