| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import re |
| 6 import types |
| 7 |
| 8 _SEGMENT_RE_BASE = r'[a-zA-Z0-9][a-zA-Z0-9:_\-.]*' |
| 9 _STREAM_NAME_RE = re.compile('^(' + _SEGMENT_RE_BASE + ')(/' + |
| 10 _SEGMENT_RE_BASE + ')*$') |
| 11 _MAX_STREAM_NAME_LENGTH = 4096 |
| 12 |
| 13 _MAX_TAG_KEY_LENGTH = 64 |
| 14 _MAX_TAG_VALUE_LENGTH = 4096 |
| 15 |
| 16 def validate_stream_name(v, maxlen=None): |
| 17 """Verifies that a given stream name is valid. |
| 18 |
| 19 Args: |
| 20 v (str): The stream name string. |
| 21 |
| 22 |
| 23 Raises: |
| 24 ValueError if the stream name is invalid. |
| 25 """ |
| 26 maxlen = maxlen or _MAX_STREAM_NAME_LENGTH |
| 27 if len(v) > maxlen: |
| 28 raise ValueError('Maximum length exceeded (%d > %d)' % (len(v), maxlen)) |
| 29 if _STREAM_NAME_RE.match(v) is None: |
| 30 raise ValueError('Invalid stream name') |
| 31 |
| 32 |
| 33 def validate_tag(key, value): |
| 34 """Verifies that a given tag key/value is valid. |
| 35 |
| 36 Args: |
| 37 k (str): The tag key. |
| 38 v (str): The tag value. |
| 39 |
| 40 Raises: |
| 41 ValueError if the tag is not valid. |
| 42 """ |
| 43 validate_stream_name(key, maxlen=_MAX_TAG_KEY_LENGTH) |
| 44 validate_stream_name(value, maxlen=_MAX_TAG_VALUE_LENGTH) |
| OLD | NEW |