diff --git a/api/controllers/console/workspace/endpoint.py b/api/controllers/console/workspace/endpoint.py index 6cafd15994..9c9c76c9f4 100644 --- a/api/controllers/console/workspace/endpoint.py +++ b/api/controllers/console/workspace/endpoint.py @@ -67,6 +67,36 @@ class EndpointListApi(Resource): ) +class EndpointListForSinglePluginApi(Resource): + @setup_required + @login_required + @account_initialization_required + def get(self): + user = current_user + + parser = reqparse.RequestParser() + parser.add_argument("page", type=int, required=True, location="args") + parser.add_argument("page_size", type=int, required=True, location="args") + parser.add_argument("plugin_id", type=str, required=True, location="args") + args = parser.parse_args() + + page = args["page"] + page_size = args["page_size"] + plugin_id = args["plugin_id"] + + return jsonable_encoder( + { + "endpoints": EndpointService.list_endpoints_for_single_plugin( + tenant_id=user.current_tenant_id, + user_id=user.id, + plugin_id=plugin_id, + page=page, + page_size=page_size, + ) + } + ) + + class EndpointDeleteApi(Resource): @setup_required @login_required @@ -169,6 +199,7 @@ class EndpointDisableApi(Resource): api.add_resource(EndpointCreateApi, "/workspaces/current/endpoints/create") api.add_resource(EndpointListApi, "/workspaces/current/endpoints/list") +api.add_resource(EndpointListForSinglePluginApi, "/workspaces/current/endpoints/list/plugin") api.add_resource(EndpointDeleteApi, "/workspaces/current/endpoints/delete") api.add_resource(EndpointUpdateApi, "/workspaces/current/endpoints/update") api.add_resource(EndpointEnableApi, "/workspaces/current/endpoints/enable") diff --git a/api/core/plugin/encrypt/__init__.py b/api/core/plugin/encrypt/__init__.py index 577e1bbace..81a5d033a0 100644 --- a/api/core/plugin/encrypt/__init__.py +++ b/api/core/plugin/encrypt/__init__.py @@ -22,8 +22,9 @@ class PluginEncrypter: "data": encrypter.decrypt(payload.data), } elif payload.opt == "clear": + encrypter.delete_tool_credentials_cache() return { - "data": encrypter.delete_tool_credentials_cache(), + "data": {}, } else: raise ValueError(f"Invalid opt: {payload.opt}") diff --git a/api/core/plugin/manager/endpoint.py b/api/core/plugin/manager/endpoint.py index 5d871e0925..d52b0b77fe 100644 --- a/api/core/plugin/manager/endpoint.py +++ b/api/core/plugin/manager/endpoint.py @@ -37,6 +37,17 @@ class PluginEndpointManager(BasePluginManager): params={"page": page, "page_size": page_size}, ) + def list_endpoints_for_single_plugin(self, tenant_id: str, user_id: str, plugin_id: str, page: int, page_size: int): + """ + List all endpoints for the given tenant, user and plugin. + """ + return self._request_with_plugin_daemon_response( + "GET", + f"plugin/{tenant_id}/endpoint/list/plugin", + list[EndpointEntity], + params={"plugin_id": plugin_id, "page": page, "page_size": page_size}, + ) + def list_plugin_endpoints(self, tenant_id: str, user_id: str, plugin_unique_identifier: str): """ List all endpoints for the given tenant, user and plugin. diff --git a/api/services/plugin/endpoint_service.py b/api/services/plugin/endpoint_service.py index bd75e818a2..35961345a8 100644 --- a/api/services/plugin/endpoint_service.py +++ b/api/services/plugin/endpoint_service.py @@ -21,6 +21,16 @@ class EndpointService: page_size=page_size, ) + @classmethod + def list_endpoints_for_single_plugin(cls, tenant_id: str, user_id: str, plugin_id: str, page: int, page_size: int): + return PluginEndpointManager().list_endpoints_for_single_plugin( + tenant_id=tenant_id, + user_id=user_id, + plugin_id=plugin_id, + page=page, + page_size=page_size, + ) + @classmethod def update_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict): return PluginEndpointManager().update_endpoint(