Skip to content

Commit 9a38128

Browse files
committed
Move instrument requirement into OpaClient init
1 parent a0def5f commit 9a38128

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
@@ -37,9 +37,11 @@ async def _call_opa(self, endpoint: str, data: Mapping[str, Any]) -> bool:
3737

3838
@classmethod
3939
def for_config(
40-
cls, instrument: str, config: OpaConfig | None
40+
cls, instrument: str | None, config: OpaConfig | None
4141
) -> AbstractAsyncContextManager[Self | None]:
4242
if config:
43+
if not instrument:
44+
raise ValueError("Instrument name is required for OPA client")
4345
return aclosing(cls(instrument, config))
4446
LOGGER.info("No OPA config provided - not creating OpaClient")
4547
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)