Skip to content
Permalink
Browse files

Make use of label quoting realized with #6972

The GUI filters for tags and labels now use the new dict key/value
quoting mechanism.

There is a new central function to apply the quoting
livestatus.quote_dict().

Change-Id: I4699db2cab2725594c41b623cee7b9ed82668b5f
  • Loading branch information...
LarsMichelsen committed Jun 11, 2019
1 parent 72c6062 commit 7ca740b3d106345c5df1c1bd3b1d1007e417ef80
@@ -2501,8 +2501,8 @@ def _tag_filter(self, tag_group, tag, negate):
return "Filter: %s_tags %s %s %s" % (
livestatus.lqencode(self.object_type),
'!=' if negate else '=',
livestatus.lqencode(tag_group),
livestatus.lqencode(tag),
livestatus.lqencode(livestatus.quote_dict(tag_group)),
livestatus.lqencode(livestatus.quote_dict(tag)),
)

def double_height(self):
@@ -2589,8 +2589,9 @@ def filter(self, infoname):
return ''

def _host_auxtags_filter(self, tag, negate):
return "Filter: host_tags %s %s %s" % ("!=" if negate else "=", livestatus.lqencode(tag),
livestatus.lqencode(tag))
return "Filter: host_tags %s %s %s" % ("!=" if negate else "=",
livestatus.lqencode(livestatus.quote_dict(tag)),
livestatus.lqencode(livestatus.quote_dict(tag)))

def double_height(self):
return True
@@ -2646,8 +2647,8 @@ def _get_label_filters(self, labels):
def _label_filter(self, label_id, label_value):
return "Filter: %s = %s %s\n" % (
livestatus.lqencode(self._column),
livestatus.lqencode(label_id),
livestatus.lqencode(label_value),
livestatus.lqencode(livestatus.quote_dict(label_id)),
livestatus.lqencode(livestatus.quote_dict(label_value)),
)


@@ -116,6 +116,11 @@ def lqencode(s):
return ensure_unicode(s).replace(u"\n", u"")


def quote_dict(s):
"""Apply the quoting used for dict-valued columns (See #6972)"""
return "'%s'" % s.replace(u"'", u"''")


def site_local_ca_path():
"""Path to the site local CA bundle"""
omd_root = os.getenv("OMD_ROOT")
@@ -58,6 +58,17 @@ def test_lqencode(query_part):
assert result == u"xyzabc"


@pytest.mark.parametrize("inp,expected_result", [
("ab c", u"'ab c'"),
("ab'c", u"'ab''c'"),
(u"ä \nabc", u"\nabc'"),
])
def test_quote_dict(inp, expected_result):
result = livestatus.quote_dict(inp)
assert isinstance(result, unicode)
assert result == expected_result


def test_livestatus_local_connection_omd_root_not_set(monkeypatch, tmpdir):
with pytest.raises(livestatus.MKLivestatusConfigError, match="OMD_ROOT is not set"):
livestatus.LocalConnection()

0 comments on commit 7ca740b

Please sign in to comment.
You can’t perform that action at this time.