Пример #1
0
    def save(self, database_handler: DatabaseHandler) -> bool:
        default_source = self.source if self.operation == DatabaseOperation.delete else None
        try:
            object_text = self.object_text.strip()
            # If an object turns out to be a key-cert, and strict_import_keycert_objects
            # is set, parse it again with strict validation to load it in the GPG keychain.
            obj = rpsl_object_from_text(object_text,
                                        strict_validation=False,
                                        default_source=default_source)
            if self.strict_validation_key_cert and obj.__class__ == RPSLKeyCert:
                obj = rpsl_object_from_text(object_text,
                                            strict_validation=True,
                                            default_source=default_source)

        except UnknownRPSLObjectClassException as exc:
            # Unknown object classes are only logged if they have not been filtered out.
            if not self.object_class_filter or exc.rpsl_object_class.lower(
            ) in self.object_class_filter:
                logger.info(f'Ignoring NRTM operation {str(self)}: {exc}')
            return False

        if self.object_class_filter and obj.rpsl_object_class.lower(
        ) not in self.object_class_filter:
            return False

        if obj.messages.errors():
            errors = '; '.join(obj.messages.errors())
            logger.critical(
                f'Parsing errors occurred while processing NRTM operation {str(self)}. '
                f'This operation is ignored, causing potential data inconsistencies. '
                f'A new operation for this update, without errors, '
                f'will still be processed and cause the inconsistency to be resolved. '
                f'Parser error messages: {errors}; original object text follows:\n{self.object_text}'
            )
            database_handler.record_mirror_error(
                self.source, f'Parsing errors: {obj.messages.errors()}, '
                f'original object text follows:\n{self.object_text}')
            return False

        if 'source' in obj.parsed_data and obj.parsed_data['source'].upper(
        ) != self.source:
            msg = (
                f'Incorrect source in NRTM object: stream has source {self.source}, found object with '
                f'source {obj.source()} in operation {self.serial}/{self.operation.value}/{obj.pk()}. '
                f'This operation is ignored, causing potential data inconsistencies.'
            )
            database_handler.record_mirror_error(self.source, msg)
            logger.critical(msg)
            return False

        if self.operation == DatabaseOperation.add_or_update:
            database_handler.upsert_rpsl_object(obj, self.serial)
        elif self.operation == DatabaseOperation.delete:
            database_handler.delete_rpsl_object(obj, self.serial)

        logger.info(f'Completed NRTM operation {str(self)}/{obj.pk()}')
        return True
Пример #2
0
 def save(self, database_handler: DatabaseHandler) -> None:
     """Save the change to the database."""
     if self.status != UpdateRequestStatus.PROCESSING or not self.rpsl_obj_new:
         raise ValueError(
             "ChangeRequest can only be saved in status PROCESSING")
     if self.request_type == UpdateRequestType.DELETE and self.rpsl_obj_current is not None:
         logger.info(
             f'{id(self)}: Saving change for {self.rpsl_obj_new}: deleting current object'
         )
         database_handler.delete_rpsl_object(self.rpsl_obj_current)
     else:
         logger.info(
             f'{id(self)}: Saving change for {self.rpsl_obj_new}: inserting/updating current object'
         )
         database_handler.upsert_rpsl_object(self.rpsl_obj_new)
     self.status = UpdateRequestStatus.SAVED
Пример #3
0
 def save(self, database_handler: DatabaseHandler) -> None:
     """Save the change to the database."""
     if self.status != UpdateRequestStatus.PROCESSING or not self.rpsl_obj_new:
         raise ValueError(
             'ChangeRequest can only be saved in status PROCESSING')
     if self.request_type == UpdateRequestType.DELETE and self.rpsl_obj_current is not None:
         logger.info(
             f'{id(self)}: Saving change for {self.rpsl_obj_new}: deleting current object'
         )
         database_handler.delete_rpsl_object(self.rpsl_obj_current)
     else:
         if not self.used_override:
             self.rpsl_obj_new.overwrite_date_new_changed_attributes(
                 self.rpsl_obj_current)
             # This call may have emitted a new info message.
             self._import_new_rpsl_obj_info_messages()
         logger.info(
             f'{id(self)}: Saving change for {self.rpsl_obj_new}: inserting/updating current object'
         )
         database_handler.upsert_rpsl_object(self.rpsl_obj_new)
     self.status = UpdateRequestStatus.SAVED