2025-03-26 23:19:57 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import quart
|
|
|
|
|
|
|
|
|
|
from .. import group
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@group.group_class('pipelines', '/api/v1/pipelines')
|
|
|
|
|
class PipelinesRouterGroup(group.RouterGroup):
|
|
|
|
|
async def initialize(self) -> None:
|
|
|
|
|
@self.route('', methods=['GET', 'POST'])
|
|
|
|
|
async def _() -> str:
|
|
|
|
|
if quart.request.method == 'GET':
|
2025-05-10 18:04:58 +08:00
|
|
|
return self.success(data={'pipelines': await self.ap.pipeline_service.get_pipelines()})
|
2025-03-26 23:19:57 +08:00
|
|
|
elif quart.request.method == 'POST':
|
|
|
|
|
json_data = await quart.request.json
|
|
|
|
|
|
2025-05-10 18:04:58 +08:00
|
|
|
pipeline_uuid = await self.ap.pipeline_service.create_pipeline(json_data)
|
2025-03-26 23:19:57 +08:00
|
|
|
|
2025-04-29 17:24:07 +08:00
|
|
|
return self.success(data={'uuid': pipeline_uuid})
|
2025-03-26 23:19:57 +08:00
|
|
|
|
|
|
|
|
@self.route('/_/metadata', methods=['GET'])
|
|
|
|
|
async def _() -> str:
|
2025-05-10 18:04:58 +08:00
|
|
|
return self.success(data={'configs': await self.ap.pipeline_service.get_pipeline_metadata()})
|
2025-03-26 23:19:57 +08:00
|
|
|
|
2025-03-27 00:47:54 +08:00
|
|
|
@self.route('/<pipeline_uuid>', methods=['GET', 'PUT', 'DELETE'])
|
2025-03-26 23:19:57 +08:00
|
|
|
async def _(pipeline_uuid: str) -> str:
|
|
|
|
|
if quart.request.method == 'GET':
|
|
|
|
|
pipeline = await self.ap.pipeline_service.get_pipeline(pipeline_uuid)
|
2025-04-29 17:24:07 +08:00
|
|
|
|
2025-03-26 23:19:57 +08:00
|
|
|
if pipeline is None:
|
|
|
|
|
return self.http_status(404, -1, 'pipeline not found')
|
|
|
|
|
|
2025-04-29 17:24:07 +08:00
|
|
|
return self.success(data={'pipeline': pipeline})
|
2025-03-27 00:47:54 +08:00
|
|
|
elif quart.request.method == 'PUT':
|
|
|
|
|
json_data = await quart.request.json
|
|
|
|
|
|
|
|
|
|
await self.ap.pipeline_service.update_pipeline(pipeline_uuid, json_data)
|
|
|
|
|
|
|
|
|
|
return self.success()
|
2025-03-26 23:19:57 +08:00
|
|
|
elif quart.request.method == 'DELETE':
|
|
|
|
|
await self.ap.pipeline_service.delete_pipeline(pipeline_uuid)
|
|
|
|
|
|
|
|
|
|
return self.success()
|