fix: endpoint apis

This commit is contained in:
Yeuoly
2024-10-08 23:48:38 +08:00
parent a9c21ef929
commit 570b7d18ac
3 changed files with 94 additions and 41 deletions

View File

@ -3,16 +3,18 @@ from core.plugin.manager.base import BasePluginManager
class PluginEndpointManager(BasePluginManager):
def create_endpoint(self, tenant_id: str, user_id: str, plugin_unique_identifier: str, name: str, settings: dict):
def create_endpoint(
self, tenant_id: str, user_id: str, plugin_unique_identifier: str, name: str, settings: dict
) -> bool:
"""
Create an endpoint for the given plugin.
Errors will be raised if any error occurs.
"""
self._request_with_plugin_daemon_response(
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/setup",
dict,
bool,
headers={
"Content-Type": "application/json",
},
@ -24,7 +26,7 @@ class PluginEndpointManager(BasePluginManager):
},
)
def list_endpoints(self, tenant_id: str, user_id: str):
def list_endpoints(self, tenant_id: str, user_id: str, page: int, page_size: int):
"""
List all endpoints for the given tenant and user.
"""
@ -32,7 +34,7 @@ class PluginEndpointManager(BasePluginManager):
"GET",
f"plugin/{tenant_id}/endpoint/list",
list[EndpointEntity],
params={"page": 1, "page_size": 256},
params={"page": page, "page_size": page_size},
)
def list_plugin_endpoints(self, tenant_id: str, user_id: str, plugin_unique_identifier: str):
@ -55,53 +57,65 @@ class PluginEndpointManager(BasePluginManager):
"""
Update the settings of the given endpoint.
"""
self._request_with_plugin_daemon_response(
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/update",
dict,
bool,
data={
"user_id": user_id,
"endpoint_id": endpoint_id,
"name": name,
"settings": settings,
},
headers={
"Content-Type": "application/json",
},
)
def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
"""
Delete the given endpoint.
"""
self._request_with_plugin_daemon_response(
"DELETE",
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/remove",
dict,
bool,
data={
"endpoint_id": endpoint_id,
},
headers={
"Content-Type": "application/json",
},
)
def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
"""
Enable the given endpoint.
"""
self._request_with_plugin_daemon_response(
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/enable",
dict,
bool,
data={
"endpoint_id": endpoint_id,
},
headers={
"Content-Type": "application/json",
},
)
def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
"""
Disable the given endpoint.
"""
self._request_with_plugin_daemon_response(
return self._request_with_plugin_daemon_response(
"POST",
f"plugin/{tenant_id}/endpoint/disable",
dict,
bool,
data={
"endpoint_id": endpoint_id,
},
headers={
"Content-Type": "application/json",
},
)