Skip to content

Commit 4fa20de

Browse files
committed
Re-use instrument session regex
1 parent 004d28d commit 4fa20de

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/blueapi/service/authorization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import re
32
from collections.abc import Mapping
43
from contextlib import AbstractAsyncContextManager, aclosing, nullcontext
54
from typing import Annotated, Any, Self, cast
@@ -11,9 +10,9 @@
1110
from blueapi.config import OIDCConfig, OpaConfig, ServiceAccount
1211
from blueapi.service.authentication import TiledAuth, unchecked_bearer_token
1312
from blueapi.service.model import TaskRequest
13+
from blueapi.utils import INSTRUMENT_SESSION_RE
1414

1515
LOGGER = logging.getLogger(__name__)
16-
INSTRUMENT_SESSION_RE = re.compile(r"^[a-z]{2}(?P<proposal>\d+)-(?P<visit>\d+)$")
1716

1817

1918
class OpaClient:

src/blueapi/utils/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from collections.abc import Callable
23
from functools import wraps
34
from typing import ParamSpec, TypeVar
@@ -31,6 +32,8 @@
3132
Args = ParamSpec("Args")
3233
Return = TypeVar("Return")
3334

35+
INSTRUMENT_SESSION_RE = re.compile(r"^[a-z]{2}(?P<proposal>\d+)-(?P<visit>\d+)$")
36+
3437

3538
def deprecated(alternative):
3639
from warnings import warn

src/blueapi/utils/serialization.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import json
2-
import re
32
from typing import Any
43

54
from pydantic import BaseModel
65

6+
from blueapi import utils
7+
78

89
def serialize(obj: Any) -> Any:
910
"""
@@ -28,13 +29,8 @@ def serialize(obj: Any) -> Any:
2829
return obj
2930

3031

31-
_INSTRUMENT_SESSION_AUTHZ_REGEX: re.Pattern = re.compile(
32-
r"^[a-zA-Z]{2}(?P<proposal>\d+)-(?P<visit>\d+)$"
33-
)
34-
35-
3632
def access_blob(instrument_session: str, beamline: str) -> str:
37-
m = _INSTRUMENT_SESSION_AUTHZ_REGEX.match(instrument_session)
33+
m = utils.INSTRUMENT_SESSION_RE.match(instrument_session)
3834
if m is None:
3935
raise ValueError(
4036
"Unable to extract proposal and visit from "

0 commit comments

Comments
 (0)