Exemple #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']:
            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
Exemple #2
0
    def validate_values(self, definition):
        """This function checks that the fields have the correct values.

        :param definition: the dictionary containing the scalar properties.
        :raises ParserError: if a scalar definition field contains an unexpected value.
        """

        if not self._strict_type_checks:
            return

        # Validate the scalar kind.
        scalar_kind = definition.get('kind')
        if scalar_kind not in SCALAR_TYPES_MAP.keys():
            ParserError(self._name + ' - unknown scalar kind: ' + scalar_kind +
                        '.\nSee: {}'.format(BASE_DOC_URL)).handle_later()

        # Validate the collection policy.
        collection_policy = definition.get('release_channel_collection', None)
        if collection_policy and collection_policy not in [
                'opt-in', 'opt-out'
        ]:
            ParserError(self._name + ' - unknown collection policy: ' +
                        collection_policy +
                        '.\nSee: {}#optional-fields'.format(BASE_DOC_URL)
                        ).handle_later()

        # Validate the cpp_guard.
        cpp_guard = definition.get('cpp_guard')
        if cpp_guard and re.match(r'\W', cpp_guard):
            ParserError(self._name + ' - invalid cpp_guard: ' + cpp_guard +
                        '.\nSee: {}#optional-fields'.format(BASE_DOC_URL)
                        ).handle_later()

        # Validate 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._name +
                            ' - unknown value in record_in_processes: ' +
                            proc +
                            '.\nSee: {}'.format(BASE_DOC_URL)).handle_later()

        # Validate product.
        products = definition.get('products', [])
        for product in products:
            if not utils.is_valid_product(product):
                ParserError(self._name + ' - unknown value in products: ' +
                            product +
                            '.\nSee: {}'.format(BASE_DOC_URL)).handle_later()

        # Validate the expiration version.
        # Historical versions of Scalars.json may contain expiration versions
        # using the deprecated format 'N.Na1'. Those scripts set
        # self._strict_type_checks to false.
        expires = definition.get('expires')
        if not utils.validate_expiration_version(
                expires) and self._strict_type_checks:
            ParserError(
                '{} - invalid expires: {}.\nSee: {}#required-fields'.format(
                    self._name, expires, BASE_DOC_URL)).handle_later()
Exemple #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
    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
Exemple #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)
Exemple #6
0
    def validate_values(self, definition):
        """This function checks that the fields have the correct values.

        :param definition: the dictionary containing the scalar properties.
        :raises ParserError: if a scalar definition field contains an unexpected value.
        """

        if not self._strict_type_checks:
            return

        # Validate the scalar kind.
        scalar_kind = definition.get('kind')
        if scalar_kind not in SCALAR_TYPES_MAP.keys():
            raise ParserError(self._name + ' - unknown scalar kind: ' + scalar_kind +
                              '.\nSee: {}'.format(BASE_DOC_URL))

        # Validate the collection policy.
        collection_policy = definition.get('release_channel_collection', None)
        if collection_policy and collection_policy not in ['opt-in', 'opt-out']:
            raise ParserError(self._name + ' - unknown collection policy: ' + collection_policy +
                              '.\nSee: {}#optional-fields'.format(BASE_DOC_URL))

        # Validate the cpp_guard.
        cpp_guard = definition.get('cpp_guard')
        if cpp_guard and re.match(r'\W', cpp_guard):
            raise ParserError(self._name + ' - invalid cpp_guard: ' + cpp_guard +
                              '.\nSee: {}#optional-fields'.format(BASE_DOC_URL))

        # Validate 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._name + ' - unknown value in record_in_processes: ' + proc +
                                  '.\nSee: {}'.format(BASE_DOC_URL))

        # Validate the expiration version.
        # Historical versions of Scalars.json may contain expiration versions
        # using the deprecated format 'N.Na1'. Those scripts set
        # self._strict_type_checks to false.
        expires = definition.get('expires')
        if not utils.validate_expiration_version(expires) and self._strict_type_checks:
            raise ParserError('{} - invalid expires: {}.\nSee: {}#required-fields'
                              .format(self._name, expires, BASE_DOC_URL))
Exemple #7
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)
Exemple #8
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.
        expiry_version = definition.get('expiry_version', 'never')
        if not utils.validate_expiration_version(expiry_version):
            raise ParserError('{}: invalid expiry_version: {}.'.format(
                self.identifier, expiry_version))
        definition['expiry_version'] = utils.add_expiration_postfix(
            expiry_version)