608ffd9663
Adds basic labels support to the registry code (V2), and the API. Note that this does not yet add any UI related support.
20 lines
814 B
Python
20 lines
814 B
Python
class LabelValidator(object):
|
|
""" Helper class for validating that labels meet prefix requirements. """
|
|
def __init__(self, app):
|
|
self.app = app
|
|
|
|
overridden_prefixes = app.config.get('LABEL_KEY_RESERVED_PREFIXES', [])
|
|
for prefix in overridden_prefixes:
|
|
if not prefix.endswith('.'):
|
|
raise Exception('Prefix "%s" in LABEL_KEY_RESERVED_PREFIXES must end in a dot', prefix)
|
|
|
|
default_prefixes = app.config.get('DEFAULT_LABEL_KEY_RESERVED_PREFIXES', [])
|
|
self.reserved_prefixed_set = set(default_prefixes + overridden_prefixes)
|
|
|
|
def has_reserved_prefix(self, label_key):
|
|
""" Validates that the provided label key does not match any reserved prefixes. """
|
|
for prefix in self.reserved_prefixed_set:
|
|
if label_key.startswith(prefix):
|
|
return True
|
|
|
|
return False
|