Example #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
Example #2
0
    def getAssociation(self, server_url, handle=None):
        if handle is None:
            return None

        server_url_hash = hashlib.sha256(server_url).hexdigest()
        handle_hash = hashlib.sha256(handle).hexdigest()
        rowkey = "%s_%s" % (server_url_hash, handle_hash)
        
        try:
            assoc_rec = cass.getRecord(self._cf, rowkey)
        except cass.NotFoundError:
            return None
        except cass.DatabaseError:
            raise
        
        server_url = assoc_rec['server_url']
        handle = assoc_rec['handle']
        secret = assoc_rec['secret']
        issued = assoc_rec['issued']
        lifetime = assoc_rec['lifetime']
        assoc_type = assoc_rec['assoc_type']
        
        association = Association(handle, secret, issued, lifetime, assoc_type)
        
        if association.getExpiresIn() == 0:
            return None
        
        return association
 def exists(self, session_key):
     try:
         session_rec = cass.getRecord(self._cf, session_key)
         return True
     except cass.NotFoundError:
         return False
     except cass.DatabaseError:
         raise
 def load(self):
     try:
         session_rec = cass.getRecord(self._cf, self.session_key)
         return self.decode(session_rec["serialized"])
     except cass.NotFoundError:
         self.create()
         return {}
     except cass.DatabaseError:
         raise