endpoint.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from core.plugin.entities.endpoint import EndpointEntity
  2. from core.plugin.manager.base import BasePluginManager
  3. class PluginEndpointManager(BasePluginManager):
  4. def create_endpoint(self, tenant_id: str, user_id: str, plugin_unique_identifier: str, name: str, settings: dict):
  5. """
  6. Create an endpoint for the given plugin.
  7. Errors will be raised if any error occurs.
  8. """
  9. self._request_with_plugin_daemon_response(
  10. "POST",
  11. f"plugin/{tenant_id}/endpoint/setup",
  12. dict,
  13. headers={
  14. "Content-Type": "application/json",
  15. },
  16. data={
  17. "user_id": user_id,
  18. "plugin_unique_identifier": plugin_unique_identifier,
  19. "settings": settings,
  20. "name": name,
  21. },
  22. )
  23. def list_endpoints(self, tenant_id: str, user_id: str):
  24. """
  25. List all endpoints for the given tenant and user.
  26. """
  27. return self._request_with_plugin_daemon_response(
  28. "GET",
  29. f"plugin/{tenant_id}/endpoint/list",
  30. list[EndpointEntity],
  31. params={"page": 1, "page_size": 256},
  32. )
  33. def list_plugin_endpoints(self, tenant_id: str, user_id: str, plugin_unique_identifier: str):
  34. """
  35. List all endpoints for the given tenant, user and plugin.
  36. """
  37. return self._request_with_plugin_daemon_response(
  38. "GET",
  39. f"plugin/{tenant_id}/endpoint/list/plugin",
  40. list[EndpointEntity],
  41. headers={
  42. "Content-Type": "application/json",
  43. },
  44. data={
  45. "plugin_unique_identifier": plugin_unique_identifier,
  46. },
  47. )
  48. def update_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str, name: str, settings: dict):
  49. """
  50. Update the settings of the given endpoint.
  51. """
  52. self._request_with_plugin_daemon_response(
  53. "POST",
  54. f"plugin/{tenant_id}/endpoint/update",
  55. dict,
  56. data={
  57. "user_id": user_id,
  58. "endpoint_id": endpoint_id,
  59. "name": name,
  60. "settings": settings,
  61. },
  62. )
  63. def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  64. """
  65. Delete the given endpoint.
  66. """
  67. self._request_with_plugin_daemon_response(
  68. "DELETE",
  69. f"plugin/{tenant_id}/endpoint/remove",
  70. dict,
  71. data={
  72. "endpoint_id": endpoint_id,
  73. },
  74. )
  75. def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  76. """
  77. Enable the given endpoint.
  78. """
  79. self._request_with_plugin_daemon_response(
  80. "POST",
  81. f"plugin/{tenant_id}/endpoint/enable",
  82. dict,
  83. data={
  84. "endpoint_id": endpoint_id,
  85. },
  86. )
  87. def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  88. """
  89. Disable the given endpoint.
  90. """
  91. self._request_with_plugin_daemon_response(
  92. "POST",
  93. f"plugin/{tenant_id}/endpoint/disable",
  94. dict,
  95. data={
  96. "endpoint_id": endpoint_id,
  97. },
  98. )