Пример #1
0
    def check_expiration(self, name, definition):
        field = 'expires_in_version'
        expiration = definition.get(field)

        if not expiration:
            return

        # We forbid new probes from using "expires_in_version" : "default" field/value pair.
        # Old ones that use this are added to the whitelist.
        if expiration == "default" and \
           whitelists is not None and \
           name not in whitelists['expiry_default']:
            ParserError('New histogram "%s" cannot have "default" %s value.' %
                        (name, field)).handle_later()

        # Historical editions of Histograms.json can have the deprecated
        # expiration format 'N.Na1'. Fortunately, those scripts set
        # self._strict_type_checks to false.
        if expiration != "default" and \
           not utils.validate_expiration_version(expiration) and \
           self._strict_type_checks:
            ParserError(('Error for histogram {} - invalid {}: {}.'
                        '\nSee: {}#expires-in-version')
                        .format(name, field, expiration, HISTOGRAMS_DOC_URL)).handle_later()

        expiration = utils.add_expiration_postfix(expiration)

        definition[field] = expiration
Пример #2
0
    def check_expiration(self, name, definition):
        field = 'expires_in_version'
        expiration = definition.get(field)

        if not expiration:
            return

        # We forbid new probes from using "expires_in_version" : "default" field/value pair.
        # Old ones that use this are added to the whitelist.
        if expiration == "default" and \
           whitelists is not None and \
           name not in whitelists['expiry_default']:
            raise ParserError(
                'New histogram "%s" cannot have "default" %s value.' %
                (name, field))

        if expiration != "default" and not utils.validate_expiration_version(
                expiration):
            raise ParserError(('Error for histogram {} - invalid {}: {}.'
                               '\nSee: {}#expires-in-version').format(
                                   name, field, expiration,
                                   HISTOGRAMS_DOC_URL))

        expiration = utils.add_expiration_postfix(expiration)

        definition[field] = expiration
Пример #3
0
    def check_expiration(self, name, definition):
        field = 'expires_in_version'
        expiration = definition.get(field)

        if not expiration:
            return

        # We forbid new probes from using "expires_in_version" : "default" field/value pair.
        # Old ones that use this are added to the whitelist.
        if expiration == "default" and \
           whitelists is not None and \
           name not in whitelists['expiry_default']:
            ParserError('New histogram "%s" cannot have "default" %s value.' %
                        (name, field)).handle_later()

        # Historical editions of Histograms.json can have the deprecated
        # expiration format 'N.Na1'. Fortunately, those scripts set
        # self._strict_type_checks to false.
        if expiration != "default" and \
           not utils.validate_expiration_version(expiration) and \
           self._strict_type_checks:
            ParserError(('Error for histogram {} - invalid {}: {}.'
                        '\nSee: {}#expires-in-version')
                        .format(name, field, expiration, HISTOGRAMS_DOC_URL)).handle_later()

        expiration = utils.add_expiration_postfix(expiration)

        definition[field] = expiration
Пример #4
0
    def __init__(self, category, name, definition):
        self._category = category
        self._name = name
        self._definition = definition

        type_check_event_fields(self.identifier, name, definition)

        # Check method & object string patterns.
        for method in self.methods:
            string_check(self.identifier, field='methods', value=method,
                         min_length=1, max_length=MAX_METHOD_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)
        for obj in self.objects:
            string_check(self.identifier, field='objects', value=obj,
                         min_length=1, max_length=MAX_OBJECT_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if rcc not in allowed_rcc:
            raise ParserError("%s: Value for %s should be one of: %s" %
                              (self.identifier, rcc_key, ", ".join(allowed_rcc)))

        # Check record_in_processes.
        record_in_processes = definition.get('record_in_processes')
        for proc in record_in_processes:
            if not utils.is_valid_process_name(proc):
                raise ParserError(self.identifier + ': Unknown value in record_in_processes: ' +
                                  proc)

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            raise ParserError("%s: Number of extra_keys exceeds limit %d." %
                              (self.identifier, MAX_EXTRA_KEYS_COUNT))
        for key in extra_keys.iterkeys():
            string_check(self.identifier, field='extra_keys', value=key,
                         min_length=1, max_length=MAX_EXTRA_KEY_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if 'expiry_version' not in definition and 'expiry_date' not in definition:
            raise ParserError("%s: event is missing an expiration - either expiry_version or"
                              " expiry_date is required" % (self.identifier))
        expiry_date = definition.get('expiry_date')
        if expiry_date and isinstance(expiry_date, basestring) and expiry_date != 'never':
            if not re.match(DATE_PATTERN, expiry_date):
                raise ParserError("%s: Event has invalid expiry_date, it should be either 'never'"
                                  " or match this format: %s" % (self.identifier, DATE_PATTERN))
            # Parse into date.
            definition['expiry_date'] = datetime.datetime.strptime(expiry_date, '%Y-%m-%d')

        # Finish setup.
        definition['expiry_version'] = \
            utils.add_expiration_postfix(definition.get('expiry_version', 'never'))
Пример #5
0
    def __init__(self, category, name, definition, strict_type_checks=False):
        self._category = category
        self._name = name
        self._definition = definition
        self._strict_type_checks = strict_type_checks

        type_check_event_fields(self.identifier, name, definition)

        # Check method & object string patterns.
        for method in self.methods:
            string_check(self.identifier, field='methods', value=method,
                         min_length=1, max_length=MAX_METHOD_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)
        for obj in self.objects:
            string_check(self.identifier, field='objects', value=obj,
                         min_length=1, max_length=MAX_OBJECT_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if rcc not in allowed_rcc:
            raise ParserError("%s: Value for %s should be one of: %s" %
                              (self.identifier, rcc_key, ", ".join(allowed_rcc)))

        # Check record_in_processes.
        record_in_processes = definition.get('record_in_processes')
        for proc in record_in_processes:
            if not utils.is_valid_process_name(proc):
                raise ParserError(self.identifier + ': Unknown value in record_in_processes: ' +
                                  proc)

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            raise ParserError("%s: Number of extra_keys exceeds limit %d." %
                              (self.identifier, MAX_EXTRA_KEYS_COUNT))
        for key in extra_keys.iterkeys():
            string_check(self.identifier, field='extra_keys', value=key,
                         min_length=1, max_length=MAX_EXTRA_KEY_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if 'expiry_version' not in definition:
            raise ParserError("%s: event is missing required field expiry_version"
                              % (self.identifier))

        # Finish setup.
        # Historical versions of Events.yaml may contain expiration versions
        # using the deprecated format 'N.Na1'. Those scripts set
        # self._strict_type_checks to false.
        expiry_version = definition.get('expiry_version', 'never')
        if not utils.validate_expiration_version(expiry_version) and self._strict_type_checks:
            raise ParserError('{}: invalid expiry_version: {}.'
                              .format(self.identifier, expiry_version))
        definition['expiry_version'] = utils.add_expiration_postfix(expiry_version)
Пример #6
0
    def __init__(self, category, name, definition, strict_type_checks=True):
        self._category = category
        self._name = name
        self._definition = definition
        self._strict_type_checks = strict_type_checks

        type_check_event_fields(self.identifier, name, definition, strict_type_checks)

        # Check method & object string patterns.
        for method in self.methods:
            string_check(self.identifier, field='methods', value=method,
                         min_length=1, max_length=MAX_METHOD_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)
        for obj in self.objects:
            string_check(self.identifier, field='objects', value=obj,
                         min_length=1, max_length=MAX_OBJECT_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if not rcc in allowed_rcc:
            raise ValueError, "%s: value for %s should be one of: %s" %\
                              (self.identifier, rcc_key, ", ".join(allowed_rcc))

        # Check record_in_processes.
        record_in_processes = definition.get('record_in_processes', ['main'])
        for proc in record_in_processes:
            if not utils.is_valid_process_name(proc):
                raise ValueError(self.identifier + ': unknown value in record_in_processes: ' + proc)

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            raise ValueError, "%s: number of extra_keys exceeds limit %d" %\
                              (self.identifier, MAX_EXTRA_KEYS_COUNT)
        for key in extra_keys.iterkeys():
            string_check(self.identifier, field='extra_keys', value=key,
                         min_length=1, max_length=MAX_EXTRA_KEY_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if not 'expiry_version' in definition and not 'expiry_date' in definition:
            raise KeyError, "%s: event is missing an expiration - either expiry_version or expiry_date is required" %\
                            (self.identifier)
        expiry_date = definition.get('expiry_date')
        if expiry_date and isinstance(expiry_date, basestring) and expiry_date != 'never':
            if not re.match(DATE_PATTERN, expiry_date):
                raise ValueError, "%s: event has invalid expiry_date, it should be either 'never' or match this format: %s" %\
                                  (self.identifier, DATE_PATTERN)
            # Parse into date.
            definition['expiry_date'] = datetime.datetime.strptime(expiry_date, '%Y-%m-%d')

        # Finish setup.
        definition['expiry_version'] = utils.add_expiration_postfix(definition.get('expiry_version', 'never'))
Пример #7
0
    def __init__(self, category, definition):
        type_check_event_fields(category, definition)

        string_check(category,
                     'methods',
                     definition.get('methods')[0],
                     1,
                     MAX_METHOD_NAME_LENGTH,
                     regex=IDENTIFIER_PATTERN)
        string_check(category,
                     'objects',
                     definition.get('objects')[0],
                     1,
                     MAX_OBJECT_NAME_LENGTH,
                     regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if not rcc in allowed_rcc:
            raise ValueError, "Value for %s in %s should be one of: %s" %\
                              (rcc_key, category, ", ".join(allowed_rcc))

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            raise ValueError, "Number of extra_keys in %s exceeds limit %d" %\
                              (category, MAX_EXTRA_KEYS_COUNT)
        for key in extra_keys.iterkeys():
            string_check(category,
                         'extra_keys',
                         key,
                         1,
                         MAX_EXTRA_KEY_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if not 'expiry_version' in definition and not 'expiry_date' in definition:
            raise KeyError, "Event in %s is missing an expiration - either expiry_version or expiry_date is required" %\
                            (category)
        expiry_date = definition.get('expiry_date')
        if expiry_date and isinstance(expiry_date,
                                      basestring) and expiry_date != 'never':
            if not re.match(DATE_PATTERN, expiry_date):
                raise ValueError, "Event in %s has invalid expiry_date, it should be either 'never' or match this format: %s" %\
                                  (category, DATE_PATTERN)
            # Parse into date.
            definition['expiry_date'] = datetime.datetime.strptime(
                expiry_date, '%Y-%m-%d')

        # Finish setup.
        self._category = category
        self._definition = definition
        definition['expiry_version'] = add_expiration_postfix(
            definition.get('expiry_version', 'never'))
Пример #8
0
    def __init__(self, group_name, probe_name, definition):
        # Validate and set the name, so we don't need to pass it to the other
        # validation functions.
        self.validate_names(group_name, probe_name)
        self._name = probe_name
        self._group_name = group_name

        # Validating the scalar definition.
        self.validate_types(definition)
        self.validate_values(definition)

        # Everything is ok, set the rest of the data.
        self._definition = definition
        definition['expires'] = add_expiration_postfix(definition['expires'])
Пример #9
0
    def __init__(self, category_name, probe_name, definition, strict_type_checks):
        # Validate and set the name, so we don't need to pass it to the other
        # validation functions.
        self._strict_type_checks = strict_type_checks
        self.validate_names(category_name, probe_name)
        self._name = probe_name
        self._category_name = category_name

        # Validating the scalar definition.
        self.validate_types(definition)
        self.validate_values(definition)

        # Everything is ok, set the rest of the data.
        self._definition = definition
        self._expires = utils.add_expiration_postfix(definition['expires'])
    def __init__(self, category_name, probe_name, definition, strict_type_checks):
        # Validate and set the name, so we don't need to pass it to the other
        # validation functions.
        self._strict_type_checks = strict_type_checks
        self.validate_names(category_name, probe_name)
        self._name = probe_name
        self._category_name = category_name

        # Validating the scalar definition.
        self.validate_types(definition)
        self.validate_values(definition)

        # Everything is ok, set the rest of the data.
        self._definition = definition
        self._expires = utils.add_expiration_postfix(definition['expires'])
Пример #11
0
    def __init__(self, category, definition):
        type_check_event_fields(category, definition)

        string_check(category, 'methods', definition.get('methods')[0], 1, MAX_METHOD_NAME_LENGTH, regex=IDENTIFIER_PATTERN)
        string_check(category, 'objects', definition.get('objects')[0], 1, MAX_OBJECT_NAME_LENGTH, regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if not rcc in allowed_rcc:
            raise ValueError, "Value for %s in %s should be one of: %s" %\
                              (rcc_key, category, ", ".join(allowed_rcc))

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            raise ValueError, "Number of extra_keys in %s exceeds limit %d" %\
                              (category, MAX_EXTRA_KEYS_COUNT)
        for key in extra_keys.iterkeys():
            string_check(category, 'extra_keys', key, 1, MAX_EXTRA_KEY_NAME_LENGTH, regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if not 'expiry_version' in definition and not 'expiry_date' in definition:
            raise KeyError, "Event in %s is missing an expiration - either expiry_version or expiry_date is required" %\
                            (category)
        expiry_date = definition.get('expiry_date')
        if expiry_date and isinstance(expiry_date, basestring) and expiry_date != 'never':
            if not re.match(DATE_PATTERN, expiry_date):
                raise ValueError, "Event in %s has invalid expiry_date, it should be either 'never' or match this format: %s" %\
                                  (category, DATE_PATTERN)
            # Parse into date.
            definition['expiry_date'] = datetime.datetime.strptime(expiry_date, '%Y-%m-%d')

        # Finish setup.
        self._category = category
        self._definition = definition
        definition['expiry_version'] = add_expiration_postfix(definition.get('expiry_version', 'never'))
Пример #12
0
    def __init__(self, category, name, definition, strict_type_checks=False):
        self._category = category
        self._name = name
        self._definition = definition
        self._strict_type_checks = strict_type_checks

        type_check_event_fields(self.identifier, name, definition)

        # Check method & object string patterns.
        for method in self.methods:
            string_check(self.identifier,
                         field='methods',
                         value=method,
                         min_length=1,
                         max_length=MAX_METHOD_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)
        for obj in self.objects:
            string_check(self.identifier,
                         field='objects',
                         value=obj,
                         min_length=1,
                         max_length=MAX_OBJECT_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check release_channel_collection
        rcc_key = 'release_channel_collection'
        rcc = definition.get(rcc_key, 'opt-in')
        allowed_rcc = ["opt-in", "opt-out"]
        if rcc not in allowed_rcc:
            ParserError("%s: Value for %s should be one of: %s" %
                        (self.identifier, rcc_key,
                         ", ".join(allowed_rcc))).handle_later()

        # Check record_in_processes.
        record_in_processes = definition.get('record_in_processes')
        for proc in record_in_processes:
            if not utils.is_valid_process_name(proc):
                ParserError(self.identifier +
                            ': Unknown value in record_in_processes: ' +
                            proc).handle_later()

        # Check products.
        products = definition.get('products', [])
        for product in products:
            if not utils.is_valid_product(product):
                ParserError(self.identifier + ': Unknown value in products: ' +
                            product).handle_later()

        # Check extra_keys.
        extra_keys = definition.get('extra_keys', {})
        if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
            ParserError(
                "%s: Number of extra_keys exceeds limit %d." %
                (self.identifier, MAX_EXTRA_KEYS_COUNT)).handle_later()
        for key in extra_keys.iterkeys():
            string_check(self.identifier,
                         field='extra_keys',
                         value=key,
                         min_length=1,
                         max_length=MAX_EXTRA_KEY_NAME_LENGTH,
                         regex=IDENTIFIER_PATTERN)

        # Check expiry.
        if 'expiry_version' not in definition:
            ParserError("%s: event is missing required field expiry_version" %
                        (self.identifier)).handle_later()

        # Finish setup.
        # Historical versions of Events.yaml may contain expiration versions
        # using the deprecated format 'N.Na1'. Those scripts set
        # self._strict_type_checks to false.
        expiry_version = definition.get('expiry_version', 'never')
        if not utils.validate_expiration_version(
                expiry_version) and self._strict_type_checks:
            ParserError('{}: invalid expiry_version: {}.'.format(
                self.identifier, expiry_version)).handle_now()
        definition['expiry_version'] = utils.add_expiration_postfix(
            expiry_version)