Skip to content

Commit

Permalink
extend character validations for model,fields,tags and measurements n…
Browse files Browse the repository at this point in the history
…ames , fix #392
  • Loading branch information
Toni Moreno Gimenez committed Aug 17, 2020
1 parent 0008bae commit f199868
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions loudml/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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([
Expand Down
8 changes: 1 addition & 7 deletions loudml/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
key = All(
str,
Length(min=1),
Match("^[a-zA-Z0-9-_@]+$"),
Match("^[a-zA-Z0-9-_@\/\[\]{}:;,.|=%\"\$]+$"),
)

time_str_key = All(
Expand 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),
Expand Down
9 changes: 7 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f199868

Please sign in to comment.