async def call_service(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if "namespace" not in data: raise RequestHandlerException("invalid namespace") if "service" not in data: raise RequestHandlerException("invalid service") else: service = data["service"] if "domain" not in data: d, s = service.split("/") if d and s: domain = d service = s else: raise RequestHandlerException("invalid domain") else: domain = data["domain"] if "data" not in data: service_data = {} else: if "service" in data["data"]: del data["data"]["service"] service_data = data["data"] return await self.AD.services.call_service(data["namespace"], domain, service, service_data)
async def hello(self, data, request_id): if "client_name" not in data: raise RequestHandlerException("client_name required") else: self.client_name = data["client_name"] if self.AD.http.password is None: self.authed = True if not self.authed: await self._auth_data(data) if not self.authed: raise RequestHandlerException("authorization failed") self.stream.set_client_name(self.client_name) self.access.info("New client %s connected", data["client_name"]) response_data = {"version": utils.__version__} event_data = { "event_type": "stream_connected", "data": { "client_name": self.client_name }, } await self.AD.events.process_event("admin", event_data) return response_data
async def get_state(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") namespace = data.get("namespace", None) entity_id = data.get("entity_id", None) if entity_id is not None and namespace is None: raise RequestHandlerException( "entity_id cannot be set without namespace") return self.AD.state.get_entity(namespace, entity_id, self.client_name)
async def cancel_listen_event(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if "handle" not in data: raise RequestHandlerException("invalid handle") if data["handle"] not in self.subscriptions["event"]: raise RequestHandlerException("invalid handle") del self.subscriptions["event"][data["handle"]] return True
async def fire_event(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if "namespace" not in data: raise RequestHandlerException("invalid namespace") if "event" not in data: raise RequestHandlerException("invalid event") event_data = data.get("data", {}) return await self.AD.events.fire_event(data["namespace"], data["event"], **event_data)
async def get_logs(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if "maxlines" in data: ml = data["maxlines"] else: ml = 100 return await self.AD.logging.get_admin_logs(ml)
async def list_dashes(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if self.AD.http is not None and self.AD.http.dashboard_obj is not None: dashes = await utils.run_in_executor( self, self.AD.http.dashboard_obj.list_dashes) else: dashes = None return dashes
async def listen_event(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") if "namespace" not in data: raise RequestHandlerException("invalid namespace") if "event" not in data: raise RequestHandlerException("invalid event") handle = data.get("handle", uuid.uuid4().hex) if handle in self.subscriptions["event"]: raise RequestHandlerException("handle already exists") self.subscriptions["event"][handle] = { "response_id": request_id, "namespace": data["namespace"], "event": data["event"], } return handle
async def get_services(self, data, request_id): if not self.authed: raise RequestHandlerException("unauthorized") return self.AD.services.list_services()