11import logging
22import time
33from contextlib import contextmanager
4- from typing import Any , Dict , Generator , Tuple
4+ from typing import Any , Callable , Dict , Generator , Tuple , TypeVar , cast
55
66from flask import Flask , Response , jsonify , request
7+ from flask .typing import ResponseReturnValue
78
89from app .telemetry import setup as telemetry_setup
910
1011app = Flask (__name__ )
1112telemetry_setup (app , service_name = "keep-app" )
1213
14+ F = TypeVar ("F" , bound = Callable [..., ResponseReturnValue ])
15+
16+
17+ def route (rule : str , ** options : Any ) -> Callable [[F ], F ]:
18+ return cast (Callable [[F ], F ], app .route (rule , ** options ))
19+
1320
1421@contextmanager
1522def record_route_metrics (route : str ) -> Generator [None , None , None ]:
@@ -24,13 +31,13 @@ def record_route_metrics(route: str) -> Generator[None, None, None]:
2431 )
2532
2633
27- @app . route ("/health" )
34+ @route ("/health" )
2835def health () -> Dict [str , str ]:
2936 with record_route_metrics ("health" ):
3037 return {"status" : "ok" }
3138
3239
33- @app . route ("/" )
40+ @route ("/" )
3441def index () -> str :
3542 with record_route_metrics ("index" ):
3643 cert_subject = request .headers .get ("X-Client-Subject" , "unknown" ) or "unknown"
@@ -44,7 +51,7 @@ def index() -> str:
4451 )
4552
4653
47- @app . route ("/step-up" , methods = ["POST" ])
54+ @route ("/step-up" , methods = ["POST" ])
4855def step_up () -> Tuple [Response , int ]:
4956 with record_route_metrics ("step_up" ):
5057 return jsonify ({"status" : "step-up required" }), 202
0 commit comments