1919
2020from murfey .server import sanitise
2121from murfey .server .murfey_db import murfey_db , url
22- from murfey .util .config import get_machine_config , get_security_config
22+ from murfey .util .config import get_global_config , get_machine_config
2323from murfey .util .db import MurfeyUser as User
2424from murfey .util .db import Session as MurfeySession
2525
@@ -63,19 +63,19 @@ async def __call__(self, request: Request):
6363
6464
6565# Set up variables used for authentication
66- security_config = get_security_config ()
66+ global_config = get_global_config ()
6767machine_config = get_machine_config ()
6868auth_url = (
6969 machine_config [os .getenv ("BEAMLINE" , "" )].auth_url
7070 if machine_config .get (os .getenv ("BEAMLINE" , "" ))
7171 else ""
7272)
73- ALGORITHM = security_config .auth_algorithm or "HS256"
74- SECRET_KEY = security_config .auth_key or secrets .token_hex (32 )
75- if security_config .auth_type == "password" :
73+ ALGORITHM = global_config .auth_algorithm or "HS256"
74+ SECRET_KEY = global_config .auth_key or secrets .token_hex (32 )
75+ if global_config .auth_type == "password" :
7676 oauth2_scheme = OAuth2PasswordBearer (tokenUrl = "token" )
7777else :
78- oauth2_scheme = CookieScheme (cookie_key = security_config .cookie_key )
78+ oauth2_scheme = CookieScheme (cookie_key = global_config .cookie_key )
7979pwd_context = CryptContext (schemes = ["bcrypt" ], deprecated = "auto" )
8080
8181instrument_server_tokens : Dict [float , dict ] = {}
@@ -96,7 +96,7 @@ def hash_password(password: str) -> str:
9696
9797# Set up database engine
9898try :
99- _url = url (security_config )
99+ _url = url (global_config )
100100 engine = create_engine (_url )
101101except Exception :
102102 engine = None
@@ -114,7 +114,7 @@ def validate_user(username: str, password: str) -> bool:
114114def validate_visit (visit_name : str , token : str ) -> bool :
115115 if validators := entry_points ().select (
116116 group = "murfey.auth.session_validation" ,
117- name = security_config .auth_type ,
117+ name = global_config .auth_type ,
118118 ):
119119 return validators [0 ].load ()(visit_name , token )
120120 return True
@@ -166,12 +166,12 @@ async def validate_token(token: Annotated[str, Depends(oauth2_scheme)]):
166166 if auth_url :
167167 headers = (
168168 {}
169- if security_config .auth_type == "cookie"
169+ if global_config .auth_type == "cookie"
170170 else {"Authorization" : f"Bearer { token } " }
171171 )
172172 cookies = (
173- {security_config .cookie_key : token }
174- if security_config .auth_type == "cookie"
173+ {global_config .cookie_key : token }
174+ if global_config .auth_type == "cookie"
175175 else {}
176176 )
177177 async with aiohttp .ClientSession (cookies = cookies ) as session :
@@ -186,7 +186,7 @@ async def validate_token(token: Annotated[str, Depends(oauth2_scheme)]):
186186 else :
187187 if validators := entry_points ().select (
188188 group = "murfey.auth.token_validation" ,
189- name = security_config .auth_type ,
189+ name = global_config .auth_type ,
190190 ):
191191 validators [0 ].load ()(token )
192192 else :
@@ -290,8 +290,8 @@ async def mint_session_token(session_id: MurfeySessionID, db=murfey_db):
290290 db .exec (select (MurfeySession ).where (MurfeySession .id == session_id )).one ().visit
291291 )
292292 expiry_time = None
293- if security_config .session_token_timeout :
294- expiry_time = time .time () + security_config .session_token_timeout
293+ if global_config .session_token_timeout :
294+ expiry_time = time .time () + global_config .session_token_timeout
295295 token = create_access_token (
296296 {
297297 "session" : session_id ,
0 commit comments