Ejemplo n.º 1
0
    def useNonce(self, server_url, timestamp, salt):
        if abs(timestamp - time.time()) > nonce.SKEW:
            return False

        server_url_hash = hashlib.sha256(server_url).hexdigest()
        rowkey = "%s_%s_%s" % (server_url_hash, str(timestamp), str(salt))
        
        #Let's check if this nonce exists
        try:
            assoc_rec = cass.getRecord(self._nonce_cf, rowkey)
        except cass.NotFoundError:
            columns = {'server_url': server_url,
                       'timestamp': timestamp,
                       'salt': salt}
            #Not found so try and insert
            try:
                cass.insertRecord(self._nonce_cf, rowkey, columns)
                #Inserted successfully, nonce is valid
                return True
            except cass.DatabaseError:
                raise
        except cass.DatabaseError:
            raise
        else:
            #Nonce already existed so nonce is invalid
            return False
    def save(self, must_create=False):
        if must_create and self.exists(self.session_key):
            raise CreateError

        session_key = self.session_key
        session_data = self.encode(self._get_session(no_load=must_create))
        expire_age = self.get_expiry_age()
        try:
            cass.insertRecord(self._cf, session_key, {"serialized": session_data}, ttl=expire_age)
        except cass.DatabaseError:
            raise
 def receive_data_chunk(self, raw_data, start):
     """
     Add the data to the cassandra row
     """
     self.chunk_list.append(start)
     try:
         cass.insertRecord(self._cf, self.uuid, {str(start):raw_data})
     except cass.DatabaseError:
         raise StopUpload("Error inserting chunk at offset %d into cassandra" % start)
     
     # Returning none stops any future handlers from storing the data
     return None
 def new_file(self, *args, **kwargs):
     super(CassandraFileUploadHandler, self).new_file(*args, **kwargs)
     
     # set chunk size to 256KB. default is 64KB
     self.chunk_size = 256 * 2 ** 10
     
     # generate a random uuid to use for cassandra row key
     self.uuid = uuid.uuid4().hex
     
     self.chunk_list = []
     self._cf = cass.getColumnFamily("TempFiles")
     try:
         cass.insertRecord(self._cf, self.uuid, {})
     except cass.DatabaseError:
         raise UploadFileException("Error inserting temporary file record into cassandra")
Ejemplo n.º 5
0
 def storeAssociation(self, server_url, assoc):
     server_url_hash = hashlib.sha256(server_url).hexdigest()
     handle_hash = hashlib.sha256(assoc.handle).hexdigest()
     rowkey = "%s_%s" % (server_url_hash, handle_hash)
     
     columns = {'server_url': server_url,
                'handle': assoc.handle,
                'secret': assoc.secret,
                'issued': assoc.issued,
                'lifetime': assoc.lifetime,
                'assoc_type': assoc.assoc_type}
     
     try:
         cass.insertRecord(self._cf, rowkey, columns)
     except cass.DatabaseError:
         raise
 def file_complete(self, file_size):
     """
     Return a file object if we're activated.
     """
     try:
         columns = {'username':self.request.session.get('username', ''),
                    'size':file_size,
                    'chunk_list':','.join(str(c) for c in self.chunk_list)}
         cass.insertRecord(self._cf, self.uuid, columns)
     except cass.DatabaseError:
         raise UploadFileException("Error inserting final columns into cassandra")
     
     return CassandraUploadedFile(row_key = self.uuid,
                                  chunk_list = self.chunk_list,
                                  size = file_size,
                                  name = self.file_name,
                                  content_type = self.content_type,
                                  charset = self.charset)