endpoint.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, 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. },
  21. )
  22. def list_endpoints(self, tenant_id: str, user_id: str):
  23. """
  24. List all endpoints for the given tenant and user.
  25. """
  26. return self._request_with_plugin_daemon_response(
  27. "GET",
  28. f"plugin/{tenant_id}/endpoint/list",
  29. list[EndpointEntity],
  30. params={"page": 1, "page_size": 256},
  31. )
  32. def list_plugin_endpoints(self, tenant_id: str, user_id: str, plugin_unique_identifier: str):
  33. """
  34. List all endpoints for the given tenant, user and plugin.
  35. """
  36. return self._request_with_plugin_daemon_response(
  37. "GET",
  38. f"plugin/{tenant_id}/endpoint/list/plugin",
  39. list[EndpointEntity],
  40. headers={
  41. "Content-Type": "application/json",
  42. },
  43. data={
  44. "plugin_unique_identifier": plugin_unique_identifier,
  45. },
  46. )
  47. def update_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str, settings: dict):
  48. """
  49. Update the settings of the given endpoint.
  50. """
  51. self._request_with_plugin_daemon_response(
  52. "POST",
  53. f"plugin/{tenant_id}/endpoint/update",
  54. dict,
  55. data={
  56. "user_id": user_id,
  57. "endpoint_id": endpoint_id,
  58. "settings": settings,
  59. },
  60. )
  61. def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  62. """
  63. Delete the given endpoint.
  64. """
  65. self._request_with_plugin_daemon_response(
  66. "DELETE",
  67. f"plugin/{tenant_id}/endpoint/remove",
  68. dict,
  69. data={
  70. "endpoint_id": endpoint_id,
  71. },
  72. )
  73. def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  74. """
  75. Enable the given endpoint.
  76. """
  77. self._request_with_plugin_daemon_response(
  78. "POST",
  79. f"plugin/{tenant_id}/endpoint/enable",
  80. dict,
  81. data={
  82. "endpoint_id": endpoint_id,
  83. },
  84. )
  85. def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  86. """
  87. Disable the given endpoint.
  88. """
  89. self._request_with_plugin_daemon_response(
  90. "POST",
  91. f"plugin/{tenant_id}/endpoint/disable",
  92. dict,
  93. data={
  94. "endpoint_id": endpoint_id,
  95. },
  96. )