From f52eec6c199dd5461b494578c4dd6ad32d3012e4 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 14 Jul 2015 11:21:39 -0400 Subject: [PATCH] Force Input data to be correct data Provide a way to coerce input string data to integer for alert parameters that are numeric. --- confluent_server/confluent/messages.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 7b02e436..c60a6e76 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -692,11 +692,11 @@ class AlertDestination(ConfluentMessage): class InputAlertDestination(ConfluentMessage): - valid_alert_params = ( - 'acknowledge', - 'ip', - 'retries' - ) + valid_alert_params = { + 'acknowledge': lambda x: x, + 'ip': lambda x: x, + 'retries': lambda x: int(x) + } def __init__(self, path, nodes, inputdata, multinode=False): self.alertcfg = {} @@ -709,14 +709,22 @@ class InputAlertDestination(ConfluentMessage): 'Unrecognized alert parameter ' + key) if isinstance(inputdata[node][key], dict): self.alertcfg[node][key] = \ - inputdata[node][key]['value'] + self.valid_alert_params[key]( + inputdata[node][key]['value']) + else: + self.alertcfg[node][key] = \ + self.valid_alert_params[key](inputdata[node][key]) else: for key in inputdata: if key not in self.valid_alert_params: raise exc.InvalidArgumentException( 'Unrecognized alert parameter ' + key) if isinstance(inputdata[key], dict): - inputdata[key] = inputdata[key]['value'] + inputdata[key] = self.valid_alert_params[key]( + inputdata[key]['value']) + else: + inputdata[key] = self.valid_alert_params[key]( + inputdata[key]) for node in nodes: self.alertcfg[node] = inputdata