|
19 | 19 | from typing import List, Optional, Union |
20 | 20 | from uuid import UUID |
21 | 21 |
|
22 | | -from fastapi import APIRouter, Depends, Header, Query, status |
| 22 | +from fastapi import APIRouter, Body, Depends, Header, Query, status |
23 | 23 | from sqlalchemy.orm import Session |
24 | 24 | from typing_extensions import Annotated |
25 | 25 |
|
26 | 26 | from budapp.commons import logging |
27 | 27 | from budapp.commons.dependencies import ( |
28 | 28 | get_current_active_user, |
| 29 | + get_current_active_user_or_internal, |
29 | 30 | get_session, |
30 | 31 | parse_ordering_fields, |
31 | 32 | ) |
32 | 33 | from budapp.commons.exceptions import ClientException |
33 | 34 | from budapp.user_ops.schemas import User |
34 | 35 |
|
35 | 36 | from ..commons.constants import PermissionEnum |
36 | | -from ..commons.permission_handler import require_permissions |
| 37 | +from ..commons.permission_handler import require_permissions, require_permissions_or_internal |
37 | 38 | from ..commons.schemas import ErrorResponse, SuccessResponse |
38 | 39 | from ..workflow_ops.schemas import RetrieveWorkflowDataResponse |
39 | 40 | from ..workflow_ops.services import WorkflowService |
|
46 | 47 | DeleteWorkerRequest, |
47 | 48 | DeploymentPricingResponse, |
48 | 49 | DeploymentSettingsResponse, |
| 50 | + EndpointDeleteResponse, |
49 | 51 | EndpointFilter, |
50 | 52 | EndpointPaginatedResponse, |
51 | 53 | ModelClusterDetailResponse, |
@@ -146,28 +148,37 @@ async def list_all_endpoints( |
146 | 148 | "description": "Invalid request parameters", |
147 | 149 | }, |
148 | 150 | status.HTTP_200_OK: { |
149 | | - "model": SuccessResponse, |
| 151 | + "model": EndpointDeleteResponse, |
150 | 152 | "description": "Successfully executed delete endpoint workflow", |
151 | 153 | }, |
152 | 154 | }, |
153 | 155 | description="Delete an endpoint by ID", |
154 | 156 | ) |
155 | | -@require_permissions(permissions=[PermissionEnum.ENDPOINT_MANAGE]) |
| 157 | +@require_permissions_or_internal(permissions=[PermissionEnum.ENDPOINT_MANAGE]) |
156 | 158 | async def delete_endpoint( |
157 | | - current_user: Annotated[User, Depends(get_current_active_user)], |
| 159 | + current_user: Annotated[User, Depends(get_current_active_user_or_internal)], |
158 | 160 | session: Annotated[Session, Depends(get_session)], |
159 | 161 | endpoint_id: UUID, |
160 | 162 | x_resource_type: Annotated[Optional[str], Header()] = None, |
161 | 163 | x_entity_id: Annotated[Optional[str], Header()] = None, |
162 | | -) -> Union[SuccessResponse, ErrorResponse]: |
163 | | - """Delete a endpoint by its ID.""" |
| 164 | + callback_topic: Annotated[Optional[str], Body(embed=True)] = None, |
| 165 | +) -> Union[EndpointDeleteResponse, ErrorResponse]: |
| 166 | + """Delete a endpoint by its ID. |
| 167 | +
|
| 168 | + Args: |
| 169 | + callback_topic: Optional Dapr pub/sub topic for budpipeline integration. |
| 170 | + If provided, completion events will be published to this topic. |
| 171 | + """ |
164 | 172 | try: |
165 | | - db_workflow = await EndpointService(session).delete_endpoint(endpoint_id, current_user.id) |
| 173 | + db_workflow = await EndpointService(session).delete_endpoint( |
| 174 | + endpoint_id, current_user.id, callback_topic=callback_topic |
| 175 | + ) |
166 | 176 | logger.debug(f"Endpoint deleting initiated with workflow id: {db_workflow.id}") |
167 | | - return SuccessResponse( |
| 177 | + return EndpointDeleteResponse( |
168 | 178 | message="Deployment deleting initiated successfully", |
169 | 179 | code=status.HTTP_200_OK, |
170 | 180 | object="endpoint.delete", |
| 181 | + workflow_id=db_workflow.id, |
171 | 182 | ) |
172 | 183 | except ClientException as e: |
173 | 184 | logger.exception(f"Failed to delete endpoint: {e}") |
@@ -1018,10 +1029,10 @@ async def update_deployment_settings( |
1018 | 1029 | }, |
1019 | 1030 | description="Get autoscale configuration for an endpoint", |
1020 | 1031 | ) |
1021 | | -@require_permissions(permissions=[PermissionEnum.ENDPOINT_VIEW]) |
| 1032 | +@require_permissions_or_internal(permissions=[PermissionEnum.ENDPOINT_VIEW]) |
1022 | 1033 | async def get_autoscale_config( |
1023 | 1034 | endpoint_id: UUID, |
1024 | | - current_user: Annotated[User, Depends(get_current_active_user)], |
| 1035 | + current_user: Annotated[User, Depends(get_current_active_user_or_internal)], |
1025 | 1036 | session: Annotated[Session, Depends(get_session)], |
1026 | 1037 | x_resource_type: Annotated[Optional[str], Header()] = None, |
1027 | 1038 | x_entity_id: Annotated[Optional[str], Header()] = None, |
@@ -1065,11 +1076,11 @@ async def get_autoscale_config( |
1065 | 1076 | }, |
1066 | 1077 | description="Update autoscale configuration for an endpoint", |
1067 | 1078 | ) |
1068 | | -@require_permissions(permissions=[PermissionEnum.ENDPOINT_MANAGE]) |
| 1079 | +@require_permissions_or_internal(permissions=[PermissionEnum.ENDPOINT_MANAGE]) |
1069 | 1080 | async def update_autoscale_config( |
1070 | 1081 | endpoint_id: UUID, |
1071 | 1082 | request: UpdateAutoscaleRequest, |
1072 | | - current_user: Annotated[User, Depends(get_current_active_user)], |
| 1083 | + current_user: Annotated[User, Depends(get_current_active_user_or_internal)], |
1073 | 1084 | session: Annotated[Session, Depends(get_session)], |
1074 | 1085 | x_resource_type: Annotated[Optional[str], Header()] = None, |
1075 | 1086 | x_entity_id: Annotated[Optional[str], Header()] = None, |
|
0 commit comments