feat: endpoint management
parent
153dc5b3f3
commit
ea497f828f
@ -0,0 +1,9 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BasePluginEntity(BaseModel):
|
||||
id: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
@ -0,0 +1,11 @@
|
||||
from datetime import datetime
|
||||
|
||||
from core.plugin.entities.base import BasePluginEntity
|
||||
|
||||
|
||||
class EndpointEntity(BasePluginEntity):
|
||||
settings: dict
|
||||
hook_id: str
|
||||
tenant_id: str
|
||||
plugin_id: str
|
||||
expired_at: datetime
|
||||
@ -0,0 +1,10 @@
|
||||
from core.plugin.entities.base import BasePluginEntity
|
||||
|
||||
|
||||
class PluginEntity(BasePluginEntity):
|
||||
name: str
|
||||
plugin_id: str
|
||||
plugin_unique_identifier: str
|
||||
tenant_id: str
|
||||
endpoints_setups: int
|
||||
endpoints_active: int
|
||||
@ -1,5 +1,104 @@
|
||||
from core.plugin.entities.endpoint import EndpointEntity
|
||||
from core.plugin.manager.base import BasePluginManager
|
||||
|
||||
|
||||
class PluginEndpointManager(BasePluginManager):
|
||||
pass
|
||||
def create_endpoint(self, tenant_id: str, user_id: str, plugin_unique_identifier: str, settings: dict):
|
||||
"""
|
||||
Create an endpoint for the given plugin.
|
||||
|
||||
Errors will be raised if any error occurs.
|
||||
"""
|
||||
self._request_with_plugin_daemon_response(
|
||||
"POST",
|
||||
f"plugin/{tenant_id}/endpoint/setup",
|
||||
dict,
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data={
|
||||
"user_id": user_id,
|
||||
"plugin_unique_identifier": plugin_unique_identifier,
|
||||
"settings": settings,
|
||||
},
|
||||
)
|
||||
|
||||
def list_endpoints(self, tenant_id: str, user_id: str):
|
||||
"""
|
||||
List all endpoints for the given tenant and user.
|
||||
"""
|
||||
return self._request_with_plugin_daemon_response(
|
||||
"GET",
|
||||
f"plugin/{tenant_id}/endpoint/list",
|
||||
list[EndpointEntity],
|
||||
params={"page": 1, "page_size": 256},
|
||||
)
|
||||
|
||||
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.
|
||||
"""
|
||||
return self._request_with_plugin_daemon_response(
|
||||
"GET",
|
||||
f"plugin/{tenant_id}/endpoint/list/plugin",
|
||||
list[EndpointEntity],
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data={
|
||||
"plugin_unique_identifier": plugin_unique_identifier,
|
||||
},
|
||||
)
|
||||
|
||||
def update_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str, settings: dict):
|
||||
"""
|
||||
Update the settings of the given endpoint.
|
||||
"""
|
||||
self._request_with_plugin_daemon_response(
|
||||
"POST",
|
||||
f"plugin/{tenant_id}/endpoint/update",
|
||||
dict,
|
||||
data={
|
||||
"endpoint_id": endpoint_id,
|
||||
"settings": settings,
|
||||
},
|
||||
)
|
||||
|
||||
def delete_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
"""
|
||||
Delete the given endpoint.
|
||||
"""
|
||||
self._request_with_plugin_daemon_response(
|
||||
"DELETE",
|
||||
f"plugin/{tenant_id}/endpoint/remove",
|
||||
dict,
|
||||
data={
|
||||
"endpoint_id": endpoint_id,
|
||||
},
|
||||
)
|
||||
|
||||
def enable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
"""
|
||||
Enable the given endpoint.
|
||||
"""
|
||||
self._request_with_plugin_daemon_response(
|
||||
"POST",
|
||||
f"plugin/{tenant_id}/endpoint/enable",
|
||||
dict,
|
||||
data={
|
||||
"endpoint_id": endpoint_id,
|
||||
},
|
||||
)
|
||||
|
||||
def disable_endpoint(self, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
"""
|
||||
Disable the given endpoint.
|
||||
"""
|
||||
self._request_with_plugin_daemon_response(
|
||||
"POST",
|
||||
f"plugin/{tenant_id}/endpoint/disable",
|
||||
dict,
|
||||
data={
|
||||
"endpoint_id": endpoint_id,
|
||||
},
|
||||
)
|
||||
|
||||
@ -1,2 +1,52 @@
|
||||
from core.plugin.manager.endpoint import PluginEndpointManager
|
||||
|
||||
|
||||
class EndpointService:
|
||||
pass
|
||||
@classmethod
|
||||
def create_endpoint(cls, tenant_id: str, user_id: str, plugin_unique_identifier: str, settings: dict):
|
||||
return PluginEndpointManager().create_endpoint(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
plugin_unique_identifier=plugin_unique_identifier,
|
||||
settings=settings,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def list_endpoints(cls, tenant_id: str, user_id: str):
|
||||
return PluginEndpointManager().list_endpoints(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def update_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str, settings: dict):
|
||||
return PluginEndpointManager().update_endpoint(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
endpoint_id=endpoint_id,
|
||||
settings=settings,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def delete_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
return PluginEndpointManager().delete_endpoint(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
endpoint_id=endpoint_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def enable_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
return PluginEndpointManager().enable_endpoint(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
endpoint_id=endpoint_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def disable_endpoint(cls, tenant_id: str, user_id: str, endpoint_id: str):
|
||||
return PluginEndpointManager().disable_endpoint(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
endpoint_id=endpoint_id,
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue