Skip to content

Commit 8ebfe05

Browse files
committed
Move instrument requirement into OpaClient init
1 parent 540af0d commit 8ebfe05

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/blueapi/service/authorization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ async def _call_opa(self, endpoint, data: Mapping[str, Any]) -> bool:
4343

4444
@classmethod
4545
def for_config(
46-
cls, instrument: str, config: OpaConfig | None
46+
cls, instrument: str | None, config: OpaConfig | None
4747
) -> AbstractAsyncContextManager[Self | None]:
4848
if config:
49+
if not instrument:
50+
raise ValueError("Instrument name is required for OPA client")
4951
return aclosing(cls(instrument, config))
5052
LOGGER.info("No OPA config provided - not creating OpaClient")
5153
return nullcontext()

src/blueapi/service/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ def teardown_runner():
9494
def lifespan(config: ApplicationConfig):
9595
@asynccontextmanager
9696
async def inner(app: FastAPI):
97-
if not (meta := config.env.metadata):
98-
raise ValueError("Instrument name is required in metadata")
99-
97+
meta = config.env.metadata
10098
setup_runner(config)
101-
async with OpaClient.for_config(meta.instrument, config.opa) as opa:
99+
async with OpaClient.for_config(meta and meta.instrument, config.opa) as opa:
102100
app.state.authz = opa
103101
yield
104102
teardown_runner()

0 commit comments

Comments
 (0)