def gandalf(bridge_name): if not bridge_name: raise Exception("Must include 'bridge_name' parameter") gandalf_cache = GandalfCache.get() bridge = gandalf_cache.get_bridge_model(bridge_name) if not bridge: logging.error("User tried to cross bridge '%s', which does not exist" % bridge_name) return False filters = gandalf_cache.get_filter_models(bridge_name) identity = current_logged_in_identity() # Currently do not support users with no identity if not identity: return False # A user needs to pass a single whitelist, and pass no blacklists, to pass a bridge passes_a_whitelist = False for filter in filters: if filter.whitelist: if filter.filter_class.passes_filter(filter, identity): passes_a_whitelist = True else: if filter.filter_class.passes_filter(filter, identity): return False return passes_a_whitelist
def gandalf(bridge_name): if not bridge_name: raise Exception("Must include 'bridge_name' parameter") gandalf_cache = GandalfCache.get() with gandalf_cache.get_lock(): # Lock while getting models because they are built lazily and # so might modify the cache object. bridge = gandalf_cache.get_bridge_model(bridge_name) if not bridge: if not App.is_dev_server: logging.error("User tried to cross non-existent bridge '%s'" % bridge_name) return False filters = gandalf_cache.get_filter_models(bridge_name) identity = current_logged_in_identity() # A user needs to pass a single whitelist, and pass no blacklists, # to pass a bridge passes_a_whitelist = False for filter in filters: if filter.whitelist: if filter.filter_class.passes_filter(filter, identity): passes_a_whitelist = True else: if filter.filter_class.passes_filter(filter, identity): return False return passes_a_whitelist
def delete(self, **kwargs): super(GandalfFilter, self).delete(**kwargs) from gandalf.cache import GandalfCache GandalfCache.delete_from_memcache()
def put(self, **kwargs): super(GandalfFilter, self).put(**kwargs) db.get(self.key()) # Force-commit, needed for high-replication store from gandalf.cache import GandalfCache GandalfCache.delete_from_memcache()
def put(self, **kwargs): super(GandalfBridge, self).put(**kwargs) # TODO(csilvers): any reason not to move this to the top of the file? from gandalf.cache import GandalfCache GandalfCache.delete_from_memcache()
def put(self, **kwargs): from gandalf.cache import GandalfCache super(GandalfFilter, self).put(**kwargs) GandalfCache.delete_from_memcache()
def put(self, **kwargs): super(GandalfBridge, self).put(**kwargs) from gandalf.cache import GandalfCache GandalfCache.delete_from_memcache()