def insert_attributes(self, attributes, user, commit=True, owner=True):
    self.logger.debug('User {0} inserts a new attribute'.format(user.username))

    # handle handler attributes

    try:
      # set extended logging
      for attribute in attributes:
        self.set_extended_logging(attribute, user, user.group, True)
        for child in attribute.children:
          self.set_extended_logging(child, user, user.group, True)

      user = self.user_broker.get_by_id(user.identifier)
      # set owner
      for attribute in attributes:
        if owner:
          attribute.properties.is_validated = True
        else:
          attribute.properties.is_proposal = True

        self.attribute_broker.insert(attribute, commit=False)

      self.attribute_broker.do_commit(commit)
      return attributes
    except IntegrityException as error:
      self.logger.debug(error)
      self.logger.info(u'User {0} tried to insert an attribute with uuid "{1}" but the uuid already exists'.format(user.username, attribute.uuid))
      raise ControllerException(u'An attribute with uuid "{0}" already exists'.format(attribute.uuid))
    except BrokerException as error:
      raise ControllerException(error)
Пример #2
0
    def update_event(self, user, event, mkrelations=True, commit=True):
        self.logger.debug('User {0} updates a event {1}'.format(
            user.username, event.identifier))
        try:
            # the the creator

            user = self.user_broker.get_by_id(user.identifier)
            self.set_extended_logging(event, user, user.group, False)
            # TODO relations on update

            self.event_broker.update(event, False)
            # generate relations if needed!
            """
      attributes = get_all_attributes_from_event(event)
      if (mkrelations == 'True' or mkrelations is True) and attributes:
        self.relation_broker.generate_bulk_attributes_relations(event, attributes, False)
      """
            self.event_broker.do_commit(commit)
            return event
        except ValidationException:
            message = ObjectValidator.getFirstValidationError(event)
            raise ControllerException(
                u'Could not update object definition due to: {0}'.format(
                    message))
        except BrokerException as error:
            raise ControllerException(error)
Пример #3
0
    def get_reference_definition(self, json, seen_ref_def=None):
        if seen_ref_def is None:
            seen_ref_def = dict()
        uuid = json.get('definition_id', None)
        if not uuid:
            definition_json = json.get('definition', None)
            if definition_json:
                uuid = definition_json.get('identifier', None)
        if uuid:
            rd = seen_ref_def.get(uuid, None)
            if rd:
                return rd
            else:
                try:
                    definition = self.reference_definiton_broker.get_by_uuid(
                        uuid)
                    seen_ref_def[uuid] = definition
                except NothingFoundException as error:
                    raise ControllerNothingFoundException(error)
                except BrokerException as error:
                    raise ControllerException(error)

                return definition
        raise ControllerException(
            'Could not find "{0}" definition in the reference'.format(
                definition_json))
Пример #4
0
    def create_new_process(self,
                           type_,
                           event_uuid,
                           user,
                           sync_server=None,
                           commit=False):
        try:
            # if syncserver is none then it is for all the known servers
            user = self.user_controller.get_user_by_id(user.identifier)
            process_item = ProcessItem()
            if type_ in ProcessType.TYPES:
                process_item.type_ = type_
            else:
                raise ControllerException(
                    u'Type "{0}" is not supported'.format(type_))
            process_item.status = ProcessStatus.SCHEDULED
            process_item.event_uuid = event_uuid
            if sync_server:
                process_item.server_details_id = sync_server.identifier
                process_item.server_details = sync_server
            self.set_simple_logging(process_item, user, True)

            self.process_broker.insert(process_item, False)
            self.process_broker.do_commit(commit)
            return process_item
        except BrokerException as error:
            raise ControllerException(error)
Пример #5
0
    def insert_composed_observable(self,
                                   observable,
                                   user,
                                   commit=True,
                                   owner=True):
        self.logger.debug('User {0} inserts a new composed observable'.format(
            user.username))
        try:
            user = self.user_broker.get_by_id(user.identifier)
            for obs in observable.observable_composition.observables:
                self.set_extended_logging_observble(obs, user, True)
            self.set_extended_logging(observable, user, user.group, True)

            self.observable_broker.insert(observable, False)
            # TODO: generate relations if needed!
            """
      attributes = get_all_attributes_from_event(event)
      if (mkrelations == 'True' or mkrelations is True) and attributes:
        self.relation_broker.generate_bulk_attributes_relations(event, attributes, False)
      """
            self.observable_broker.do_commit(commit)
            return observable, True
        except ValidationException:
            return observable, False
        except IntegrityException as error:
            self.logger.debug(error)
            self.logger.info(
                u'User {0} tried to insert an observable with uuid "{1}" but the uuid already exists'
                .format(user.username, observable.uuid))
            raise ControllerException(
                u'An observable with uuid "{0}" already exists'.format(
                    observable.uuid))
        except BrokerException as error:
            raise ControllerException(error)
  def insert_reference(self, reference, additional_references, user, commit=True, owner=True):
    self.logger.debug('User {0} inserts a new reference'.format(user.username))

    # handle handler references

    try:

      user = self.user_broker.get_by_id(user.identifier)
      if owner:
        reference.properties.is_validated = True

      self.set_extended_logging(reference, user, user.group, True)
      self.reference_broker.insert(reference, False)

      if additional_references:
        for additional_reference in additional_references:
          if owner:
            additional_reference.properties.is_validated = True

          self.set_extended_logging(additional_reference, user, user.group, True)
          self.reference_broker.insert(additional_reference, commit=False)

      self.reference_broker.do_commit(commit)
      return reference, additional_references
    except IntegrityException as error:
      self.logger.debug(error)
      self.logger.info(u'User {0} tried to insert a reference with uuid "{1}" but the uuid already exists'.format(user.username, reference.uuid))
      raise ControllerException(u'An reference with uuid "{0}" already exists'.format(reference.uuid))
    except BrokerException as error:
      raise ControllerException(error)
Пример #7
0
 def __validate_object(self, obj):
     # validate
     if obj.validate:
         for related_object in obj.related_objects:
             if not related_object.validate:
                 raise ControllerException('Related object is invalid')
     else:
         raise ControllerException('Object is invalid')
 def __validate_report(self, report):
   # validate
   if report.validate:
     for related_report in report.related_reports:
       if not related_report.validate:
         raise ControllerException('Related object is invalid')
   else:
     raise ControllerException('Object is invalid')
 def remove_condition_by_uuid(self, uuid):
     try:
         self.group_broker.remove_by_uuid(uuid)
     except IntegrityException as error:
         raise ControllerException(
             'Cannot delete condition. The condition is referenced by elements.'
         )
     except BrokerException as error:
         raise ControllerException(error)
 def update_condition(self, condition):
     try:
         self.condition_broker.update(condition, True)
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(condition)
         raise ControllerException(
             u'Could not add condition due to: {0}'.format(message))
     except (BrokerException) as error:
         raise ControllerException(error)
Пример #11
0
 def remove_user_by_uuid(self, uuid):
   try:
     self.user_broker.remove_by_uuid(uuid)
   except IntegrityException as error:
     raise ControllerException('Cannot delete user. The user is referenced by elements. Disable this user instead.')
   except DeletionException:
     raise ControllerException('This user cannot be deleted')
   except BrokerException as error:
     raise ControllerException(error)
 def insert_condition(self, condition, commit=True):
     try:
         self.condition_broker.insert(condition, False)
         self.condition_broker.do_commit(commit)
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(condition)
         raise ControllerException(
             u'Could not add condition due to: {0}'.format(message))
     except (BrokerException) as error:
         raise ControllerException(error)
 def update_group(self, group):
     try:
         self.group_broker.update(group)
         return group
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(group)
         raise ControllerException(
             u'Could not update group due to: {0}'.format(message))
     except BrokerException as error:
         raise ControllerException(error)
 def remove_group_by_id(self, identifier):
     try:
         self.group_broker.remove_by_id(identifier)
     except IntegrityException as error:
         raise ControllerException(
             'Cannot delete group. The group is referenced by elements. Disable this group instead.'
         )
     except DeletionException:
         raise ControllerException('This group cannot be deleted')
     except BrokerException as error:
         raise ControllerException(error)
 def insert_report(self, report, user, commit=True):
   try:
     user = self.user_broker.get_by_id(user.identifier)
     self.set_extended_logging(report, user, user.group, True)
     self.report_broker.insert(report)
   except IntegrityException as error:
     self.logger.debug(error)
     self.logger.info(u'User {0} tried to insert a report with uuid "{1}" but the uuid already exists'.format(user.username, report.uuid))
     raise ControllerException(u'An report with uuid "{0}" already exists'.format(report.uuid))
   except BrokerException as error:
     raise ControllerException(error)
    def insert_group(self, group, validate=True, commit=True):
        try:
            self.group_broker.insert(group, commit, validate)

        except ValidationException as error:
            message = ObjectValidator.getFirstValidationError(group)
            raise ControllerException(
                u'Could not add group due to: {0}'.format(message))
        except IntegrityException as error:
            raise ControllerIntegrityException(error)
        except (BrokerException) as error:
            raise ControllerException(error)
Пример #17
0
 def update_mail(self, mail_template, user):
     try:
         user = self.user_broker.get_by_id(user.identifier)
         self.set_simple_logging(mail_template, user, insert=False)
         mail_template = self.mail_broker.update(mail_template)
         return mail_template
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(mail_template)
         raise ControllerException(
             u'Could not update mail due to: {0}'.format(message))
     except BrokerException as error:
         raise ControllerException(error)
Пример #18
0
 def update_reference_definition(self, reference_definition, user):
     try:
         user = self.user_broker.get_by_id(user.identifier)
         self.set_simple_logging(reference_definition, user, insert=False)
         reference_definition = self.reference_definition_broker.update(
             reference_definition)
         return reference_definition
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(
             reference_definition)
         raise ControllerException(
             u'Could not update reference due to: {0}'.format(message))
     except BrokerException as error:
         raise ControllerException(error)
Пример #19
0
 def insert_object_definition(self, obj, user, commit=True):
     try:
         obj.chksum = gen_obj_chksum(obj)
         user = self.user_broker.get_by_id(user.identifier)
         self.set_simple_logging(obj, user, insert=True)
         self.obj_def_broker.insert(obj, False)
         self.obj_def_broker.do_commit(commit)
         return obj
     except ValidationException as error:
         message = ObjectValidator.getFirstValidationError(obj)
         raise ControllerException(
             u'Could not insert object definition due to: {0}'.format(
                 message))
     except BrokerException as error:
         raise ControllerException(error)
 def update_report(self, report, user, commit=True):
   try:
     user = self.user_broker.get_by_id(user.identifier)
     self.set_extended_logging(report, user, user.group, False)
     self.report_broker.update(report, commit)
   except BrokerException as error:
     raise ControllerException(error)
 def get_reference_by_id(self, identifier):
   try:
     return self.reference_broker.get_by_id(identifier)
   except NothingFoundException as error:
     raise ControllerNothingFoundException(error)
   except BrokerException as error:
     raise ControllerException(error)
Пример #22
0
 def update_comment(self, user, comment):
     try:
         user = self.user_broker.get_by_id(user.identifier)
         self.set_extended_logging(comment, user, user.group, False)
         self.comment_broker.update(comment, True)
     except BrokerException as error:
         raise ControllerException(error)
Пример #23
0
 def get_user_by_activation_str(self, act_str):
   try:
     return self.user_broker.get_user_by_act_str(act_str)
   except NothingFoundException as error:
     raise ControllerNothingFoundException(error)
   except BrokerException as error:
     raise ControllerException(error)
Пример #24
0
 def remove_event(self, user, event):
     self.logger.debug('User {0} deleted a event {1}'.format(
         user.username, event.identifier))
     try:
         self.event_broker.remove_by_id(event.identifier)
     except BrokerException as error:
         raise ControllerException(error)
Пример #25
0
  def get_all_notifiable_users(self):
    try:
      users = self.user_broker.get_all_notifiable_users()
      return users

    except BrokerException as error:
      raise ControllerException(error)
Пример #26
0
    def generate_attribute_relations(self, attribute, commit=False):
        try:
            """

      Generates the relations for the given attribue
      :param attribute:
      :type attribute: Attribute
      :param commit:
      :type commit: Boolean

      """
            if attribute.definition.relation:
                clazz = ValueBroker.get_class_by_attr_def(attribute.definition)
                relations = self.__look_for_value_by_attrib_id(
                    clazz, attribute.plain_value,
                    attribute.definition.identifier, '==', True)
                event = attribute.object.event
                for relation in relations:

                    # make insert foo
                    if relation.event_id != event.identifier:
                        # make relation in both ways
                        relation_entry = Relation()
                        relation_entry.event_id = event.identifier
                        relation_entry.rel_event_id = relation.event_id
                        relation_entry.attribute_id = attribute.identifier
                        relation_entry.rel_attribute_id = relation.attribute_id
                        try:
                            self.relation_broker.insert(relation_entry, False)
                        except IntegrityException:
                            # do nothing if duplicate
                            pass
                self.relation_broker.do_commit(commit)
        except BrokerException as error:
            raise ControllerException(error)
Пример #27
0
  def update_user(self, user):
    try:
      if user.gpg_key:
        self.mail_controller.import_gpg_key(user.gpg_key)

      self.user_broker.update(user)
      # add it again in case of changes
      # TODO import gpg key
      # if user.gpg_key:
      #  self.mail_handler.import_gpg_key(user.gpg_key)
      return user
    except ValidationException as error:
      message = ObjectValidator.getFirstValidationError(user)
      raise ControllerException(u'Could not update user due to: {0}'.format(message))
    except BrokerException as error:
      raise ControllerException(error)
Пример #28
0
 def get_user_by_id(self, user_id):
   try:
     return self.user_broker.get_by_id(user_id)
   except NothingFoundException as error:
     raise ControllerNothingFoundException(error)
   except BrokerException as error:
     raise ControllerException(error)
 def get_reference_by_uuid(self, uuid):
   try:
     return self.reference_broker.get_by_uuid(uuid)
   except NothingFoundException as error:
     raise ControllerNothingFoundException(error)
   except BrokerException as error:
     raise ControllerException(error)
Пример #30
0
 def get_user_by_username(self, username):
   try:
     return self.user_broker.getUserByUserName(username)
   except NothingFoundException as error:
     raise ControllerNothingFoundException(error)
   except BrokerException as error:
     raise ControllerException(error)