2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-26 03:19:48 +00:00

Implement more robust input handling of attributes

Instead of naively looking for '{', use format() to thoroughly check and
support escaping { and } with {{ and }}
This commit is contained in:
Jarrod Johnson 2014-03-02 13:01:19 -05:00
parent 9bf68c1639
commit 5773c3d237
2 changed files with 27 additions and 6 deletions

1
BUGS
View File

@ -4,7 +4,6 @@
the next setting comes to work and then we get a stack trace
Should leave value out of it and set 'broken' with a reason as the
value to the key
-cannot set expression value through confetty
-expressionkeys never gets smaller - perf impact
-need event notification for config change- e.g. set attribute triggers consol
session object check to see if credentials changed

View File

@ -164,9 +164,23 @@ class InputAttributes(ConfluentMessage):
if nodes is None:
self.attribs = inputdata
for attrib in self.attribs:
if (type(self.attribs[attrib]) in (str, unicode) and
'{' in self.attribs[attrib]):
self.attribs[attrib] = {'expression': self.attribs[attrib]}
if type(self.attribs[attrib]) in (str, unicode):
try:
# ok, try to use format against the string
# store back result to the attribute to
# handle things like '{{' and '}}'
# if any weird sort of error should
# happen, it means the string has something
# that formatter is looking to fulfill, but
# is unable to do so, meaning it is an expression
tv = self.attribs[attrib].format()
self.attribs[attrib] = tv
except:
# this means format() actually thought there was work
# that suggested parameters, push it in as an
# expression
self.attribs[attrib] = {
'expression': self.attribs[attrib]}
return
for node in nodes:
if node in inputdata:
@ -185,8 +199,16 @@ class InputAttributes(ConfluentMessage):
return {}
nodeattr = self.nodeattribs[node]
for attr in nodeattr:
if type(nodeattr[attr]) in (str, unicode) and '{' in nodeattr[attr]:
nodeattr[attr] = {'expression': nodeattr[attr]}
if type(nodeattr[attr]) in (str, unicode):
try:
# as above, use format() to see if string follows
# expression, store value back in case of escapes
tv = nodeattr[attr].format()
nodeattr[attr] = tv
except:
# an expression string will error if format() done
# use that as cue to put it into config as an expr
nodeattr[attr] = {'expression': nodeattr[attr]}
return nodeattr