@@ -101,7 +101,7 @@ def _vip_to_response(vip: Any) -> VipResponse:
101101 )
102102
103103
104- def _lookup_vip (svc , address : str , port : int , protocol : Protocol ):
104+ def _lookup_vip (svc : Any , address : str , port : int , protocol : Protocol ) -> Any :
105105 """Get a VIP or raise 404."""
106106 vip = svc .vip_manager .get_vip (address = address , port = port , protocol = protocol )
107107 if vip is None :
@@ -117,7 +117,7 @@ def _lookup_vip(svc, address: str, port: int, protocol: Protocol):
117117# ---------------------------------------------------------------------------
118118
119119
120- def get_service (request : Request ):
120+ def get_service (request : Request ) -> Any :
121121 """FastAPI dependency that returns the KatranService or raises 503."""
122122 service = request .app .state .service
123123 if service is None or not service .is_running :
@@ -136,7 +136,7 @@ def get_service(request: Request):
136136}
137137
138138
139- def _katran_error_handler (request : Request , exc : KatranError ) -> JSONResponse :
139+ def _katran_error_handler (request : Request , exc : Exception ) -> JSONResponse :
140140 for err_cls , status in _KATRAN_ERROR_STATUS .items ():
141141 if isinstance (exc , err_cls ):
142142 return JSONResponse (status_code = status , content = {"detail" : str (exc )})
@@ -148,7 +148,7 @@ def _katran_error_handler(request: Request, exc: KatranError) -> JSONResponse:
148148# ---------------------------------------------------------------------------
149149
150150
151- def create_app (service = None ) -> FastAPI :
151+ def create_app (service : Any = None ) -> FastAPI :
152152 """Create the FastAPI application."""
153153 app = FastAPI (title = "Katran Control Plane" , version = "0.1.0" )
154154 app .state .service = service
@@ -163,7 +163,7 @@ def create_app(service=None) -> FastAPI:
163163 registry = CollectorRegistry ()
164164 registry .register (KatranMetricsCollector (service ))
165165
166- def _metrics_handler ():
166+ def _metrics_handler () -> Response :
167167 try :
168168 output = generate_latest (registry )
169169 return Response (content = output , media_type = CONTENT_TYPE_LATEST )
@@ -184,7 +184,7 @@ def _metrics_handler():
184184 # --- Health -----------------------------------------------------------
185185
186186 @app .get ("/health" )
187- def health ():
187+ def health () -> dict [ str , str ] :
188188 svc = app .state .service
189189 if svc is None or not svc .is_running :
190190 raise HTTPException (status_code = 503 , detail = "Service not running" )
@@ -193,7 +193,7 @@ def health():
193193 # --- VIP endpoints ----------------------------------------------------
194194
195195 @app .post ("/api/v1/vips" , status_code = 201 , response_model = VipResponse )
196- def add_vip (req : AddVipRequest , svc = Depends (get_service )):
196+ def add_vip (req : AddVipRequest , svc : Any = Depends (get_service )) -> VipResponse :
197197 proto = _parse_protocol (req .protocol )
198198 vip = svc .vip_manager .add_vip (
199199 address = req .address ,
@@ -209,8 +209,8 @@ def get_vips(
209209 address : Optional [str ] = Query (None ),
210210 port : Optional [int ] = Query (None ),
211211 protocol : Optional [str ] = Query (None ),
212- svc = Depends (get_service ),
213- ):
212+ svc : Any = Depends (get_service ),
213+ ) -> Any :
214214 params = [address , port , protocol ]
215215 provided = sum (p is not None for p in params )
216216
@@ -224,8 +224,8 @@ def get_vips(
224224 detail = "Provide all of address, port, protocol — or none" ,
225225 )
226226
227- # Single VIP lookup
228- proto = _parse_protocol (protocol )
227+ # Single VIP lookup — all three are non-None at this point
228+ proto = _parse_protocol (protocol or "" )
229229 vip = svc .vip_manager .get_vip (address = address , port = port , protocol = proto )
230230 if vip is None :
231231 raise HTTPException (
@@ -235,7 +235,7 @@ def get_vips(
235235 return _vip_to_response (vip )
236236
237237 @app .post ("/api/v1/vips/remove" )
238- def remove_vip (req : VipId , svc = Depends (get_service )):
238+ def remove_vip (req : VipId , svc : Any = Depends (get_service )) -> dict [ str , str ] :
239239 proto = _parse_protocol (req .protocol )
240240 removed = svc .vip_manager .remove_vip (
241241 address = req .address ,
@@ -253,7 +253,7 @@ def remove_vip(req: VipId, svc=Depends(get_service)):
253253 # --- Backend endpoints ------------------------------------------------
254254
255255 @app .post ("/api/v1/backends/add" , status_code = 201 , response_model = RealResponse )
256- def add_backend (req : AddBackendRequest , svc = Depends (get_service )):
256+ def add_backend (req : AddBackendRequest , svc : Any = Depends (get_service )) -> RealResponse :
257257 proto = _parse_protocol (req .vip .protocol )
258258 vip = _lookup_vip (svc , req .vip .address , req .vip .port , proto )
259259 real = svc .real_manager .add_real (vip , address = req .address , weight = req .weight )
@@ -267,7 +267,7 @@ def add_backend(req: AddBackendRequest, svc=Depends(get_service)):
267267 return RealResponse (address = str (real .address ), weight = real .weight , index = real .index )
268268
269269 @app .post ("/api/v1/backends/remove" )
270- def remove_backend (req : BackendId , svc = Depends (get_service )):
270+ def remove_backend (req : BackendId , svc : Any = Depends (get_service )) -> dict [ str , str ] :
271271 proto = _parse_protocol (req .vip .protocol )
272272 vip = _lookup_vip (svc , req .vip .address , req .vip .port , proto )
273273 removed = svc .real_manager .remove_real (vip , address = req .address )
@@ -283,7 +283,7 @@ def remove_backend(req: BackendId, svc=Depends(get_service)):
283283 return {"status" : "removed" }
284284
285285 @app .post ("/api/v1/backends/drain" )
286- def drain_backend (req : BackendId , svc = Depends (get_service )):
286+ def drain_backend (req : BackendId , svc : Any = Depends (get_service )) -> dict [ str , str ] :
287287 proto = _parse_protocol (req .vip .protocol )
288288 vip = _lookup_vip (svc , req .vip .address , req .vip .port , proto )
289289 drained = svc .real_manager .drain_real (vip , address = req .address )
0 commit comments