Skip to content

Commit f12bd2a

Browse files
committed
Create OpaClient as part of server lifecycle
1 parent 9a9b9b8 commit f12bd2a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/blueapi/service/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from blueapi.worker import TrackableTask, WorkerState
4141
from blueapi.worker.event import TaskStatusEnum
4242

43+
from .authorization import OpaClient
4344
from .model import (
4445
DeviceModel,
4546
DeviceResponse,
@@ -93,8 +94,13 @@ def teardown_runner():
9394
def lifespan(config: ApplicationConfig):
9495
@asynccontextmanager
9596
async def inner(app: FastAPI):
97+
if not (meta := config.env.metadata):
98+
raise ValueError("Instrument name is required in metadata")
99+
96100
setup_runner(config)
97-
yield
101+
async with OpaClient.for_config(meta.instrument, config.opa) as opa:
102+
app.state.authz = opa
103+
yield
98104
teardown_runner()
99105

100106
return inner

0 commit comments

Comments
 (0)