We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9a9b9b8 commit f12bd2aCopy full SHA for f12bd2a
1 file changed
src/blueapi/service/main.py
@@ -40,6 +40,7 @@
40
from blueapi.worker import TrackableTask, WorkerState
41
from blueapi.worker.event import TaskStatusEnum
42
43
+from .authorization import OpaClient
44
from .model import (
45
DeviceModel,
46
DeviceResponse,
@@ -93,8 +94,13 @@ def teardown_runner():
93
94
def lifespan(config: ApplicationConfig):
95
@asynccontextmanager
96
async def inner(app: FastAPI):
97
+ if not (meta := config.env.metadata):
98
+ raise ValueError("Instrument name is required in metadata")
99
+
100
setup_runner(config)
- yield
101
+ async with OpaClient.for_config(meta.instrument, config.opa) as opa:
102
+ app.state.authz = opa
103
+ yield
104
teardown_runner()
105
106
return inner
0 commit comments