From 8bb565e938fb227bb27345cfda53957884b01d6b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 7 Jun 2022 11:45:06 -0400 Subject: [PATCH] Implement error on invalid attribute filter This will cause noderange to probably error out. Note that invalid attribute names starting with net, power, or custom are treated as always valid. --- .../confluent/config/configmanager.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index 2ccce28b..91f48ffc 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -1167,6 +1167,18 @@ def hook_new_configmanagers(callback): pass +def attribute_name_is_invalid(attrname): + if attrname.startswith('custom.') or attrname.startswith('net.') or attrname.startswith('power.'): + return False + if '?' in attrname or '*' in attrname: + for attr in allattributes.node: + if fnmatch.fnmatch(attr, attrname): + return False + return True + attrname = _get_valid_attrname(attrname) + return attrname not in allattributes.node + + class ConfigManager(object): if os.name == 'nt': _cfgdir = os.path.join( @@ -1275,6 +1287,9 @@ class ConfigManager(object): raise Exception('Invalid Expression') if attribute.startswith('secret.'): raise Exception('Filter by secret attributes is not supported') + if attribute_name_is_invalid(attribute): + raise ValueError( + '{0} is not a valid attribute name'.format(attribute)) for node in nodes: try: currvals = [self._cfgstore['nodes'][node][attribute]['value']]