示例#1
0
    def WriteHuntObject(self, hunt_obj, cursor=None):
        """Writes a hunt object to the database."""
        query = """
    INSERT INTO hunts (hunt_id, creator, description, duration_micros,
                       hunt_state,
                       client_rate, client_limit,
                       hunt)
    VALUES (%(hunt_id)s, %(creator)s, %(description)s, %(duration_micros)s,
            %(hunt_state)s,
            %(client_rate)s, %(client_limit)s,
            %(hunt)s)
    """

        args = {
            "hunt_id": db_utils.HuntIDToInt(hunt_obj.hunt_id),
            "creator": hunt_obj.creator,
            "description": hunt_obj.description,
            "duration_micros": hunt_obj.duration.microseconds,
            "hunt_state": int(rdf_hunt_objects.Hunt.HuntState.PAUSED),
            "client_rate": hunt_obj.client_rate,
            "client_limit": hunt_obj.client_limit,
            "hunt": hunt_obj.SerializeToBytes(),
        }

        try:
            cursor.execute(query, args)
        except MySQLdb.IntegrityError as error:
            raise db.DuplicatedHuntError(hunt_id=hunt_obj.hunt_id, cause=error)
示例#2
0
    def WriteHuntObject(self, hunt_obj):
        """Writes a hunt object to the database."""
        if hunt_obj.hunt_id in self.hunts:
            raise db.DuplicatedHuntError(hunt_id=hunt_obj.hunt_id)

        clone = self._DeepCopy(hunt_obj)
        clone.create_time = rdfvalue.RDFDatetime.Now()
        clone.last_update_time = rdfvalue.RDFDatetime.Now()
        self.hunts[(hunt_obj.hunt_id)] = clone