endpoint.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. "endpoint_id": endpoint_id,
  57. "settings": settings,
  58. },
  59. )
  60. def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  61. """
  62. Delete the given endpoint.
  63. """
  64. self._request_with_plugin_daemon_response(
  65. "DELETE",
  66. f"plugin/{tenant_id}/endpoint/remove",
  67. dict,
  68. data={
  69. "endpoint_id": endpoint_id,
  70. },
  71. )
  72. def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  73. """
  74. Enable the given endpoint.
  75. """
  76. self._request_with_plugin_daemon_response(
  77. "POST",
  78. f"plugin/{tenant_id}/endpoint/enable",
  79. dict,
  80. data={
  81. "endpoint_id": endpoint_id,
  82. },
  83. )
  84. def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
  85. """
  86. Disable the given endpoint.
  87. """
  88. self._request_with_plugin_daemon_response(
  89. "POST",
  90. f"plugin/{tenant_id}/endpoint/disable",
  91. dict,
  92. data={
  93. "endpoint_id": endpoint_id,
  94. },
  95. )