From a8077557ee71303e62eff0141aacf423399de1e1 Mon Sep 17 00:00:00 2001 From: Toni Moreno Gimenez Date: Mon, 17 Aug 2020 17:38:33 +0200 Subject: [PATCH] extend character validations for model,fields,tags and measurements names , fix #392 --- loudml/model.py | 8 ++++---- loudml/schemas.py | 8 +------- tests/test_model.py | 18 ------------------ tests/test_schemas.py | 9 +++++++-- 4 files changed, 12 insertions(+), 31 deletions(-) diff --git a/loudml/model.py b/loudml/model.py index e72eead0..439f6181 100644 --- a/loudml/model.py +++ b/loudml/model.py @@ -77,9 +77,9 @@ class Feature: SCHEMA = Schema({ Required('name'): All(schemas.key, Length(max=256)), Required('metric'): All(schemas.key, Length(max=256)), - Required('field'): All(schemas.dotted_key, Length(max=256)), + Required('field'): All(schemas.key, Length(max=256)), 'bucket': Any(None, schemas.key), - 'measurement': Any(None, schemas.dotted_key), + 'measurement': Any(None, schemas.key), 'match_all': Any(None, Schema([ {Required(schemas.key): Any( int, @@ -157,13 +157,13 @@ class FeatureTemplate(Feature): All(schemas.bracket_key, Length(max=256)), ), Required('field'): Any( - All(schemas.dotted_key, Length(max=256)), + All(schemas.key, Length(max=256)), All(schemas.bracket_key, Length(max=256)), ), 'bucket': Any( None, schemas.key, schemas.bracket_key), 'measurement': Any( - None, schemas.dotted_key, schemas.bracket_key), + None, schemas.key, schemas.bracket_key), 'match_all': Any( None, Schema([ diff --git a/loudml/schemas.py b/loudml/schemas.py index df987530..3d285441 100644 --- a/loudml/schemas.py +++ b/loudml/schemas.py @@ -28,7 +28,7 @@ key = All( str, Length(min=1), - Match("^[a-zA-Z0-9-_@]+$"), + Match("^[a-zA-Z0-9-_@\/\[\]{}:;,.|=%\"\$]+$"), ) time_str_key = All( @@ -37,12 +37,6 @@ Match("^[:0-9]+$"), ) -dotted_key = All( - str, - Length(min=1), - Match("^[a-zA-Z0-9-_@.]+$"), -) - bracket_key = All( str, Length(min=1), diff --git a/tests/test_model.py b/tests/test_model.py index ffd3816d..0b43fdbd 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -37,11 +37,6 @@ def test_validate_feature(self): ) # Invalid - self.invalid_feature( - name="foo/invalid", - field="bar", - metric="avg", - ) self.invalid_feature( metric="avg", field="bar", @@ -163,19 +158,6 @@ def test_validate_model(self): ], } ) - self.invalid_model( - settings={ - 'name': 'foo/invalid', - 'type': 'generic', - 'features': [ - { - 'name': 'bar', - 'field': 'baz', - 'metric': 'avg', - }, - ], - } - ) def test_flatten_features(self): res = flatten_features([ diff --git a/tests/test_schemas.py b/tests/test_schemas.py index f24b1e3a..1624b90a 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -22,10 +22,15 @@ def test_key(self): self.valid("Foo-Bar") self.valid("00_foo_00_bar_001") self.valid("_foo") + self.valid("traffic.rxt_et-1/0/0") + self.valid("traffic.rxt_et-[1/0/0]") + self.valid("traffic.rxt_et-{1/0/0}") + self.valid("traffic.rxt_et-00:11:11") + self.valid("traffic.rxt_et=adfa") + self.valid("traffic.rxt_et=\"foo\"") + self.valid("traffic.rxt_et=${value}") self.invalid("") - self.invalid("foo/bar") - self.invalid(".foo") def test_timestamp(self): self.schema = schemas.Timestamp()