def get(self): if not os.environ["SERVER_SOFTWARE"].startswith('Development'): return # Delete all bridges and filters so that we have a fresh testing environment for bridge in GandalfBridge.all(): bridge.delete() for filter in GandalfFilter.all(): filter.delete() step = self.request.get("step") v = None if step == "creating_bridge": v = self.creating_bridge() elif step == "can_cross_empty_bridge": v = self.can_cross_empty_bridge() elif step == "can_cross_all_users_whitelist": v = self.can_cross_all_users_whitelist() elif step == "can_cross_all_users_blacklist": v = self.can_cross_all_users_blacklist() elif step == "can_cross_all_users_whitelist_and_blacklist": v = self.can_cross_all_users_whitelist_and_blacklist() elif step == "can_cross_all_users_inside_percentage": v = self.can_cross_all_users_inside_percentage() elif step == "can_cross_all_users_outside_percentage": v = self.can_cross_all_users_outside_percentage() self.response.out.write(json.dumps(v))
def can_cross_empty_bridge(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) return gandalf(bridge_name)
def can_cross_empty_bridge(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) return gandalf(bridge_name)
def get(self): if not os.environ["SERVER_SOFTWARE"].startswith('Development'): return # Delete all bridges and filters so that we have a fresh testing environment for bridge in GandalfBridge.all(): bridge.delete() for filter in GandalfFilter.all(): filter.delete() step = self.request.get("step") v = None if step == "creating_bridge": v = self.creating_bridge() elif step == "can_cross_empty_bridge": v = self.can_cross_empty_bridge() elif step == "can_cross_all_users_whitelist": v = self.can_cross_all_users_whitelist() elif step == "can_cross_all_users_blacklist": v = self.can_cross_all_users_blacklist() elif step == "can_cross_all_users_whitelist_and_blacklist": v = self.can_cross_all_users_whitelist_and_blacklist() elif step == "can_cross_all_users_inside_percentage": v = self.can_cross_all_users_inside_percentage() elif step == "can_cross_all_users_outside_percentage": v = self.can_cross_all_users_outside_percentage() self.response.out.write(json.dumps(v))
def can_cross_all_users_blacklist(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=False).put() return gandalf(bridge_name)
def can_cross_all_users_blacklist(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=False).put() return gandalf(bridge_name)
def get(self): if not can_control_gandalf(): return bridges = GandalfBridge.all().fetch(900) context = { "bridges": bridges, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def get(self): if not can_control_gandalf(): return bridges = GandalfBridge.all().fetch(900) context = { "bridges": bridges, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def can_cross_all_users_outside_percentage(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) filter = GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=True) filter.put() identity_percentage = BridgeFilter._identity_percentage(filter.key()) filter.percentage = identity_percentage filter.put() return gandalf(bridge_name)
def can_cross_all_users_outside_percentage(self): bridge_name = "balrog" filter_type = "all-users" bridge = GandalfBridge.get_or_insert(bridge_name) filter = GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=True) filter.put() identity_percentage = BridgeFilter._identity_percentage(filter.key()) filter.percentage = identity_percentage filter.put() return gandalf(bridge_name)
def load_from_datastore(): gandalf_cache = GandalfCache() bridges = GandalfBridge.all() for bridge in bridges: key = bridge.key().name() gandalf_cache.bridges[key] = db.model_to_protobuf(bridge).Encode() filters = bridge.gandalffilter_set gandalf_cache.filters[key] = [] for filter in filters: gandalf_cache.filters[key].append(db.model_to_protobuf(filter).Encode()) memcache.set(GandalfCache.MEMCACHE_KEY, gandalf_cache) return gandalf_cache
def load_from_datastore(): gandalf_cache = GandalfCache() bridges = GandalfBridge.all() for bridge in bridges: key = bridge.key().name() gandalf_cache.bridges[key] = db.model_to_protobuf(bridge).Encode() filters = bridge.gandalffilter_set gandalf_cache.filters[key] = [] for filter in filters: gandalf_cache.filters[key].append(db.model_to_protobuf(filter).Encode()) memcache.set(GandalfCache.MEMCACHE_KEY, gandalf_cache) return gandalf_cache
def post(self): if not can_control_gandalf(): return action = self.request.get('action') bridge_name = self.request.get('bridge_name') if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_or_insert(bridge_name) if action == 'delete': bridge.delete() context = { "success": True, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def post(self): if not can_control_gandalf(): return action = self.request.get('action') bridge_name = self.request.get('bridge_name') if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_or_insert(bridge_name) if action == 'delete': bridge.delete() context = { "success": True, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def get(self): if not can_control_gandalf(): return bridge_name = self.request.get('bridge_name') if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_by_key_name(bridge_name) if not bridge: raise Exception("Bridge '%s' does not exist" % bridge_name) filters = bridge.gandalffilter_set whitelist_filters = filter(lambda f: f.whitelist, filters) blacklist_filters = filter(lambda f: not f.whitelist, filters) if whitelist_filters: whitelist_filters[0].whitelist_message = True if blacklist_filters: blacklist_filters[0].blacklist_message = True filters = whitelist_filters + blacklist_filters context = { 'filters': filters, 'filter_types': BridgeFilter.get_filter_types(), 'bridge': bridge, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def get(self): if not can_control_gandalf(): return bridge_name = self.request.get('bridge_name') if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_by_key_name(bridge_name) if not bridge: raise Exception("Bridge '%s' does not exist" % bridge_name) filters = bridge.gandalffilter_set whitelist_filters = filter(lambda f: f.whitelist, filters) blacklist_filters = filter(lambda f: not f.whitelist, filters) if whitelist_filters: whitelist_filters[0].whitelist_message = True if blacklist_filters: blacklist_filters[0].blacklist_message = True filters = whitelist_filters + blacklist_filters context = { 'filters': filters, 'filter_types': BridgeFilter.get_filter_types(), 'bridge': bridge, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def post(self): if not can_control_gandalf(): return action = self.request.get('action') if action == "new": filter_type = self.request.get('filter_type') bridge_name = self.request.get('bridge_name') whitelist = self.request.get('whitelist') == "1" if not filter_type: raise Exception("Must include 'filter_type' parameter") if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_by_key_name(bridge_name) if not bridge: raise Exception("Bridge '%s' does not exist" % bridge_name) context = BridgeFilter.find_subclass(filter_type).initial_context() filter = GandalfFilter(bridge=bridge, filter_type=filter_type, context=context, whitelist=whitelist) filter.put() else: filter_key = self.request.get('filter_key') if not filter_key: raise Exception("Must include 'filter_key' parameter") filter = GandalfFilter.get(filter_key) if action == "delete": filter.delete() elif action == "save": try: percentage = int(self.request.get('percentage')) if 0 <= percentage <= 100: filter.percentage = percentage except ValueError: pass for key in filter.context: value = self.request.get(key) if value is not None: filter.context[key] = value filter.put() context = { "success": True, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))
def can_cross_empty_bridge(self): bridge_name = "balrog" GandalfBridge.get_or_insert(bridge_name) return gandalf(bridge_name)
def post(self): if not can_control_gandalf(): return action = self.request.get('action') if action == "new": filter_type = self.request.get('filter_type') bridge_name = self.request.get('bridge_name') whitelist = self.request.get('whitelist') == "1" if not filter_type: raise Exception("Must include 'filter_type' parameter") if not bridge_name: raise Exception("Must include 'bridge_name' parameter") bridge = GandalfBridge.get_by_key_name(bridge_name) if not bridge: raise Exception("Bridge '%s' does not exist" % bridge_name) context = BridgeFilter.find_subclass(filter_type).initial_context() filter = GandalfFilter(bridge=bridge, filter_type=filter_type, context=context, whitelist=whitelist) filter.put() else: filter_key = self.request.get('filter_key') if not filter_key: raise Exception("Must include 'filter_key' parameter") filter = GandalfFilter.get(filter_key) if action == "delete": filter.delete() elif action == "save": try: percentage = int(self.request.get('percentage')) if 0 <= percentage <= 100: filter.percentage = percentage except ValueError: pass for key in filter.context: value = self.request.get(key) if value is not None: filter.context[key] = value filter.put() context = { "success": True, } self.response.headers["Content-Type"] = "application/json" self.response.out.write(jsonify(context))