-
Notifications
You must be signed in to change notification settings - Fork 7
ENH: Add logic for refreshing sessions and handling RMS sessions separately #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,43 +10,30 @@ | |
| ProjectSession, | ||
| Session, | ||
| SessionNotFoundError, | ||
| session_manager, | ||
| destroy_fmu_session_if_expired, | ||
| get_fmu_session, | ||
| ) | ||
|
|
||
|
|
||
| async def get_session( | ||
| async def destroy_session_if_expired( | ||
| fmu_settings_session: Annotated[str | None, Cookie()] = None, | ||
| ) -> Session: | ||
| """Gets a session from the session manager.""" | ||
| if not fmu_settings_session: | ||
| raise HTTPException( | ||
| status_code=401, | ||
| detail="No active session found", | ||
| headers={ | ||
| HttpHeader.WWW_AUTHENTICATE_KEY: HttpHeader.WWW_AUTHENTICATE_COOKIE | ||
| }, | ||
| ) | ||
| try: | ||
| return await session_manager.get_session(fmu_settings_session) | ||
| except SessionNotFoundError as e: | ||
| raise HTTPException( | ||
| status_code=401, | ||
| detail="Invalid or expired session", | ||
| headers={ | ||
| HttpHeader.WWW_AUTHENTICATE_KEY: HttpHeader.WWW_AUTHENTICATE_COOKIE | ||
| }, | ||
| ) from e | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=f"Session error: {e}") from e | ||
| ) -> None: | ||
| """Destroys a session from the session manager if it has expired.""" | ||
| return ( | ||
| await destroy_fmu_session_if_expired(fmu_settings_session) | ||
| if fmu_settings_session | ||
| else None | ||
| ) | ||
|
|
||
|
|
||
| SessionDep = Annotated[Session, Depends(get_session)] | ||
| DestroySessionIfExpiredDep = Annotated[None, Depends(destroy_session_if_expired)] | ||
|
|
||
|
|
||
| async def get_session_no_extend( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these |
||
| async def get_session( | ||
| expired_session_dep: DestroySessionIfExpiredDep, | ||
| fmu_settings_session: Annotated[str | None, Cookie()] = None, | ||
| ) -> Session: | ||
| """Gets a session from the session manager without extending expiration.""" | ||
| """Gets an active session from the session manager.""" | ||
| if not fmu_settings_session: | ||
| raise HTTPException( | ||
| status_code=401, | ||
|
|
@@ -56,13 +43,11 @@ async def get_session_no_extend( | |
| }, | ||
| ) | ||
| try: | ||
| return await session_manager.get_session( | ||
| fmu_settings_session, extend_expiration=False | ||
| ) | ||
| return await get_fmu_session(fmu_settings_session) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The functionality for removing/destroying sessions where kindoff hidden inside the |
||
| except SessionNotFoundError as e: | ||
| raise HTTPException( | ||
| status_code=401, | ||
| detail="Invalid or expired session", | ||
| detail="No active session found", | ||
| headers={ | ||
| HttpHeader.WWW_AUTHENTICATE_KEY: HttpHeader.WWW_AUTHENTICATE_COOKIE | ||
| }, | ||
|
|
@@ -71,14 +56,14 @@ async def get_session_no_extend( | |
| raise HTTPException(status_code=500, detail=f"Session error: {e}") from e | ||
|
|
||
|
|
||
| SessionNoExtendDep = Annotated[Session, Depends(get_session_no_extend)] | ||
| SessionDep = Annotated[Session, Depends(get_session)] | ||
|
|
||
|
|
||
| async def get_project_session( | ||
| session: SessionDep, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather inject the depedency then call the |
||
| fmu_settings_session: str | None = Cookie(None), | ||
GibranAlfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> ProjectSession: | ||
| """Gets a session with an FMU Project opened from the session manager.""" | ||
| session = await get_session(fmu_settings_session) | ||
| if not isinstance(session, ProjectSession): | ||
| raise HTTPException( | ||
| status_code=401, | ||
|
|
@@ -96,30 +81,6 @@ async def get_project_session( | |
| ProjectSessionDep = Annotated[ProjectSession, Depends(get_project_session)] | ||
|
|
||
|
|
||
| async def get_project_session_no_extend( | ||
| fmu_settings_session: str | None = Cookie(None), | ||
| ) -> ProjectSession: | ||
| """Gets a session with an FMU Project opened from the session manager.""" | ||
| session = await get_session_no_extend(fmu_settings_session) | ||
| if not isinstance(session, ProjectSession): | ||
| raise HTTPException( | ||
| status_code=401, | ||
| detail="No FMU project directory open", | ||
| ) | ||
|
|
||
| if not session.project_fmu_directory.path.exists(): | ||
| raise HTTPException( | ||
| status_code=404, | ||
| detail="Project .fmu directory not found. It may have been deleted.", | ||
| ) | ||
| return session | ||
|
|
||
|
|
||
| ProjectSessionNoExtendDep = Annotated[ | ||
| ProjectSession, Depends(get_project_session_no_extend) | ||
| ] | ||
|
|
||
|
|
||
| async def ensure_smda_session(session: Session) -> None: | ||
| """Raises exceptions if a session is not SMDA-query capable.""" | ||
| if ( | ||
|
|
@@ -140,19 +101,19 @@ async def ensure_smda_session(session: Session) -> None: | |
|
|
||
|
|
||
| async def get_smda_session( | ||
| session: SessionDep, | ||
| fmu_settings_session: str | None = Cookie(None), | ||
GibranAlfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> Session: | ||
| """Gets a session capable of querying SMDA from the session manager.""" | ||
| session = await get_session(fmu_settings_session) | ||
| await ensure_smda_session(session) | ||
| return session | ||
|
|
||
|
|
||
| async def get_project_smda_session( | ||
| session: ProjectSessionDep, | ||
| fmu_settings_session: str | None = Cookie(None), | ||
GibranAlfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> ProjectSession: | ||
| """Returns a project .fmu session that is SMDA-querying capable.""" | ||
| session = await get_project_session(fmu_settings_session) | ||
| await ensure_smda_session(session) | ||
| return session | ||
|
|
||
|
|
@@ -167,17 +128,7 @@ async def get_session_service( | |
| return SessionService(session) | ||
|
|
||
|
|
||
| async def get_session_service_no_extend( | ||
| session: SessionNoExtendDep, | ||
| ) -> SessionService: | ||
| """Returns a SessionService instance without extending session expiration.""" | ||
| return SessionService(session) | ||
|
|
||
|
|
||
| SessionServiceDep = Annotated[SessionService, Depends(get_session_service)] | ||
| SessionServiceNoExtendDep = Annotated[ | ||
| SessionService, Depends(get_session_service_no_extend) | ||
| ] | ||
|
|
||
|
|
||
| async def get_project_session_service( | ||
|
|
@@ -187,16 +138,6 @@ async def get_project_session_service( | |
| return SessionService(session) | ||
|
|
||
|
|
||
| async def get_project_session_service_no_extend( | ||
| session: ProjectSessionNoExtendDep, | ||
| ) -> SessionService: | ||
| """Returns a SessionService for a project session without extending expiration.""" | ||
| return SessionService(session) | ||
|
|
||
|
|
||
| ProjectSessionServiceDep = Annotated[ | ||
| SessionService, Depends(get_project_session_service) | ||
| ] | ||
| ProjectSessionServiceNoExtendDep = Annotated[ | ||
| SessionService, Depends(get_project_session_service_no_extend) | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,5 +17,8 @@ class SessionResponse(BaseResponseModel): | |
| expires_at: datetime | ||
| """Timestamp when the session will expire.""" | ||
|
|
||
| rms_expires_at: datetime | None | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to also return this to the client so that it can keep track of when the RMS session will expire. |
||
| """Timestamp when the rms session will expire.""" | ||
GibranAlfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| last_accessed: datetime | ||
| """Timestamp when the session was last accessed.""" | ||
Uh oh!
There was an error while loading. Please reload this page.