def create_or_patch( request: Request, project: str, endpoint_id: str, model_endpoint: ModelEndpoint, auth_verifier: mlrun.api.api.deps.AuthVerifier = Depends( mlrun.api.api.deps.AuthVerifier), db_session: Session = Depends(mlrun.api.api.deps.get_db_session), ) -> Response: """ Either create or updates the kv record of a given ModelEndpoint object """ access_key = get_access_key(request.headers) if project != model_endpoint.metadata.project: raise MLRunConflictError( f"Can't store endpoint of project {model_endpoint.metadata.project} into project {project}" ) if endpoint_id != model_endpoint.metadata.uid: raise MLRunConflictError( f"Mismatch between endpoint_id {endpoint_id} and ModelEndpoint.metadata.uid {model_endpoint.metadata.uid}." f"\nMake sure the supplied function_uri, and model are configured as intended" ) ModelEndpoints.create_or_patch( db_session=db_session, access_key=access_key, model_endpoint=model_endpoint, leader_session=auth_verifier.auth_info.session, ) return Response(status_code=HTTPStatus.NO_CONTENT.value)
async def create_or_patch(request: Request, project: str, endpoint_id: str, model_endpoint: ModelEndpoint) -> Response: """ Either create or updates the kv record of a given ModelEndpoint object """ access_key = get_access_key(request.headers) if project != model_endpoint.metadata.project: raise MLRunConflictError( f"Can't store endpoint of project {model_endpoint.metadata.project} into project {project}" ) if endpoint_id != model_endpoint.metadata.uid: raise MLRunConflictError( f"Mismatch between endpoint_id {endpoint_id} and ModelEndpoint.metadata.uid {model_endpoint.metadata.uid}." f"\nMake sure the supplied function_uri, and model are configured as intended" ) await ModelEndpoints.create_or_patch(access_key=access_key, model_endpoint=model_endpoint) return Response(status_code=HTTPStatus.NO_CONTENT.value)
def create_or_patch( project: str, endpoint_id: str, model_endpoint: ModelEndpoint, auth_info: mlrun.api.schemas.AuthInfo = Depends( mlrun.api.api.deps.authenticate_request), db_session: Session = Depends(mlrun.api.api.deps.get_db_session), ) -> Response: """ Either create or updates the kv record of a given ModelEndpoint object """ mlrun.api.utils.auth.verifier.AuthVerifier( ).query_project_resource_permissions( mlrun.api.schemas.AuthorizationResourceTypes.model_endpoint, project, endpoint_id, mlrun.api.schemas.AuthorizationAction.store, auth_info, ) # get_access_key will validate the needed auth (which is used later) exists in the request mlrun.api.crud.ModelEndpoints().get_access_key(auth_info) if project != model_endpoint.metadata.project: raise MLRunConflictError( f"Can't store endpoint of project {model_endpoint.metadata.project} into project {project}" ) if endpoint_id != model_endpoint.metadata.uid: raise MLRunConflictError( f"Mismatch between endpoint_id {endpoint_id} and ModelEndpoint.metadata.uid {model_endpoint.metadata.uid}." f"\nMake sure the supplied function_uri, and model are configured as intended" ) # Since the endpoint records are created automatically, at point of serving function deployment, we need to use # V3IO_ACCESS_KEY here mlrun.api.crud.ModelEndpoints().create_or_patch( db_session=db_session, access_key=os.environ.get("V3IO_ACCESS_KEY"), model_endpoint=model_endpoint, auth_info=auth_info, ) return Response(status_code=HTTPStatus.NO_CONTENT.value)
def verify_endpoint(project, endpoint_id): endpoint_id_project, _ = endpoint_id.split(".") if endpoint_id_project != project: raise MLRunConflictError( f"project: {project} and endpoint_id: {endpoint_id} missmatch." )