Skip to content

Commit 1db4ee4

Browse files
Remove the need for an ispyb environment variable (#435)
* Turned file path fields in Security BaseModel to Optional[Path] * 'murfey_db_credentials' and 'rabbitmq_credentials' are mandatory Path fields --------- Co-authored-by: Eu Pin Tien <[email protected]>
1 parent 65049b0 commit 1db4ee4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/murfey/server/ispyb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import datetime
44
import logging
5-
import os
65
from typing import Callable, List, Literal, Optional
76

87
import ispyb
@@ -31,9 +30,11 @@
3130
url,
3231
)
3332

33+
from murfey.util.config import get_security_config
3434
from murfey.util.models import FoilHoleParameters, GridSquareParameters, Sample, Visit
3535

3636
log = logging.getLogger("murfey.server.ispyb")
37+
security_config = get_security_config()
3738

3839
try:
3940
Session = sqlalchemy.orm.sessionmaker(
@@ -60,7 +61,11 @@ def __init__(self, transport_type: Literal["PikaTransport"]):
6061
self.transport = workflows.transport.lookup(transport_type)()
6162
self.transport.connect()
6263
self.feedback_queue = ""
63-
self.ispyb = ispyb.open() if os.getenv("ISPYB_CREDENTIALS") else None
64+
self.ispyb = (
65+
ispyb.open(credentials=security_config.ispyb_credentials)
66+
if security_config.ispyb_credentials
67+
else None
68+
)
6469
self._connection_callback: Callable | None = None
6570

6671
def reconnect(self):

src/murfey/util/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def from_file(config_file_path: Path, instrument: str = "") -> Dict[str, Machine
8282

8383

8484
class Security(BaseModel):
85-
rabbitmq_credentials: str
86-
murfey_db_credentials: str
85+
murfey_db_credentials: Path
8786
crypto_key: str
8887
auth_key: str = ""
8988
auth_algorithm: str = ""
@@ -93,9 +92,11 @@ class Security(BaseModel):
9392
session_token_timeout: Optional[int] = None
9493
auth_type: Literal["password", "cookie"] = "password"
9594
cookie_key: str = ""
95+
rabbitmq_credentials: Path
9696
feedback_queue: str = "murfey_feedback"
9797
graylog_host: str = ""
9898
graylog_port: Optional[int] = None
99+
ispyb_credentials: Optional[Path] = None
99100

100101
@validator("graylog_port")
101102
def check_port_present_if_host_is(

0 commit comments

Comments
 (0)