endpoint.py 3.7 KB

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