Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
74032e1
Ability to configure different auth routes for instrument server and …
d-j-hatton May 29, 2025
c281170
Split token auth mechanisms for two different groups of endpoints
d-j-hatton May 29, 2025
606a957
Resolved merge conflicts with 'main' branch
tieneupin Jun 2, 2025
27a681a
Major refactor of 'murfey.server.api.auth', rearranging functions by …
tieneupin Jun 3, 2025
d5efb6f
Added documentation to instrument server-side token validation function
tieneupin Jun 3, 2025
02e8c19
Refactored 'murfey.server.api.file_manip' into 'file_io_instrument', …
tieneupin Jun 3, 2025
f7b4006
Added prefixes to the 'auth' and 'clem' routers
tieneupin Jun 3, 2025
2a8e75e
Updated route manifest with new URL paths
tieneupin Jun 4, 2025
c5956e8
Moved 'count_number_of_omves()' from 'session_info' router to 'sessio…
tieneupin Jun 4, 2025
5f66b8b
Fixed broken test; used 'url_path_for()' instead of hard-coding URL now
tieneupin Jun 5, 2025
7a9d83d
Attempt to fix broken test
tieneupin Jun 5, 2025
e8f57e4
Token generating URL was outdated; replaced with URL constructor; rep…
tieneupin Jun 5, 2025
96fce0c
Used FastAPI's 'APIKeyCookie' object for cookie authentication instea…
tieneupin Jun 5, 2025
fb19d6c
Typo in router name
tieneupin Jun 5, 2025
ceebff5
Adjusted logic in 'password' block of 'generate_token()' to avoid uni…
tieneupin Jun 5, 2025
0bfeafa
Added mock database to 'test_movie_count()', use 'mint_session_token(…
tieneupin Jun 5, 2025
3076af2
Rewrote 'test_movie_count' function to make use database set up in py…
tieneupin Jun 5, 2025
27748f0
Use Murfey database fixture and add entries to it
tieneupin Jun 5, 2025
89a0607
No need to re-do Session table entry
tieneupin Jun 5, 2025
00fe67f
Put the database and validation overrides in a test FastAPI client fi…
tieneupin Jun 5, 2025
7fae5d8
Database session gets reset every test, so the FastAPI test client th…
tieneupin Jun 5, 2025
2269269
Moved Murfey DB URL out of fixture and into a module-level variable
tieneupin Jun 5, 2025
e6c0f3c
Import 'murfey_db' only after mocks have been set
tieneupin Jun 5, 2025
c35cc74
Removed patch decorators from fixtures due to decorator conflict
tieneupin Jun 5, 2025
8cb679a
Move test_client startup into test function, as database state doesn'…
tieneupin Jun 5, 2025
de4a73a
Test funciton directly (ノಠ益ಠ)ノ彡┻━┻
tieneupin Jun 5, 2025
ff03dcb
Merge branch 'main' into auth-procedures
tieneupin Jun 5, 2025
1cdae65
Minor fixes to comments and redundant variables
tieneupin Jun 5, 2025
8f8b512
Add method to change visit end time in multigrid controller and all c…
d-j-hatton Jun 3, 2025
d775661
Fix datetime related problems
d-j-hatton Jun 3, 2025
afbc024
Endpoints to flush skipped files for an rsyncer
d-j-hatton Jun 3, 2025
1b30149
Merge main
d-j-hatton Jun 12, 2025
8d2aeed
Put typing back
d-j-hatton Jun 12, 2025
db36b95
Reset end time when flushing skipped files
d-j-hatton Jun 12, 2025
c755f5e
Update visit end time in database as well
tieneupin Jun 13, 2025
80d2ddd
Updated route manifest
tieneupin Jun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/murfey/client/multigrid_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
for p in self.rsync_processes.keys():
self._finalise_rsyncer(p)

def update_visit_time(self, new_end_time: datetime):
self.visit_end_time = new_end_time

Check warning on line 156 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L156

Added line #L156 was not covered by tests
for rp in self.rsync_processes.values():
rp._end_time = new_end_time

Check warning on line 158 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L158

Added line #L158 was not covered by tests

def _start_rsyncer_multigrid(
self,
source: Path,
Expand Down
2 changes: 2 additions & 0 deletions src/murfey/client/rsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@
self.queue.put(absolute_path)

def flush_skipped(self):
self._end_time = datetime.now()

Check warning on line 223 in src/murfey/client/rsync.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/rsync.py#L223

Added line #L223 was not covered by tests
for f in self._skipped_files:
self.queue.put(f)
self._skipped_files = []

Check warning on line 226 in src/murfey/client/rsync.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/rsync.py#L226

Added line #L226 was not covered by tests

def _process(self):
logger.info("RSync thread starting")
Expand Down
13 changes: 13 additions & 0 deletions src/murfey/instrument_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
watchers[label].request_stop()


@router.post("/sessions/{session_id}/multigrid_controller/visit_end_time")
def update_multigrid_controller_visit_end_time(
session_id: MurfeySessionID, end_time: datetime
):
controllers[session_id].update_visit_time(end_time)

Check warning on line 221 in src/murfey/instrument_server/api.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/api.py#L221

Added line #L221 was not covered by tests


class RsyncerSource(BaseModel):
source: Path
label: str
Expand Down Expand Up @@ -261,6 +268,12 @@
return {"success": True}


@router.post("/sessions/{session_id}/flush_skipped_rsyncer")
def flush_skipped_rsyncer(session_id: MurfeySessionID, rsyncer_source: RsyncerSource):
controllers[session_id].rsync_processes[rsyncer_source.source].flush_skipped()
return {"success": True}

Check warning on line 274 in src/murfey/instrument_server/api.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/instrument_server/api.py#L273-L274

Added lines #L273 - L274 were not covered by tests


class ObserverInfo(BaseModel):
source: str
num_files_transferred: int
Expand Down
61 changes: 60 additions & 1 deletion src/murfey/server/api/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import datetime
import logging
import urllib
from pathlib import Path
from typing import Annotated, List, Optional

Expand Down Expand Up @@ -126,7 +127,7 @@
str(k): v for k, v in watcher_spec.destination_overrides.items()
},
"rsync_restarts": watcher_spec.rsync_restarts,
"visit_end_time": session.visit_end_time,
"visit_end_time": str(session.visit_end_time),
},
headers={
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
Expand Down Expand Up @@ -396,6 +397,36 @@
return data


@router.post("/sessions/{session_id}/multigrid_controller/visit_end_time")
async def update_visit_end_time(
session_id: MurfeySessionID, end_time: datetime.datetime, db=murfey_db
):
# Load data for session
session_entry = db.exec(select(Session).where(Session.id == session_id)).one()
instrument_name = session_entry.instrument_name

Check warning on line 406 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L405-L406

Added lines #L405 - L406 were not covered by tests

# Update visit end time in database
session_entry.visit_end_time = end_time
db.add(session_entry)
db.commit()

Check warning on line 411 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L409-L411

Added lines #L409 - L411 were not covered by tests

# Update the multigrid controller
data = {}
machine_config = get_machine_config(instrument_name=instrument_name)[

Check warning on line 415 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L414-L415

Added lines #L414 - L415 were not covered by tests
instrument_name
]
if machine_config.instrument_server_url:
async with aiohttp.ClientSession() as clientsession:
async with clientsession.post(

Check warning on line 420 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L419-L420

Added lines #L419 - L420 were not covered by tests
f"{machine_config.instrument_server_url}{url_path_for('api.router', 'update_multigrid_controller_visit_end_time', session_id=session_id)}?end_time={urllib.parse.quote(end_time.isoformat())}",
headers={
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
},
) as resp:
data = await resp.json()
return data

Check warning on line 427 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L426-L427

Added lines #L426 - L427 were not covered by tests


@router.post("/sessions/{session_id}/abandon_session")
async def abandon_session(session_id: MurfeySessionID, db=murfey_db):
data = {}
Expand Down Expand Up @@ -473,6 +504,34 @@
return data


@router.post("/sessions/{session_id}/flush_skipped_rsyncer")
async def flush_skipped_rsyncer(
session_id: MurfeySessionID, rsyncer_source: RsyncerSource, db=murfey_db
):
data = {}
instrument_name = (

Check warning on line 512 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L511-L512

Added lines #L511 - L512 were not covered by tests
db.exec(select(Session).where(Session.id == session_id)).one().instrument_name
)
machine_config = get_machine_config(instrument_name=instrument_name)[

Check warning on line 515 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L515

Added line #L515 was not covered by tests
instrument_name
]
if isinstance(session_id, int):
if machine_config.instrument_server_url:
async with aiohttp.ClientSession() as clientsession:
async with clientsession.post(

Check warning on line 521 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L520-L521

Added lines #L520 - L521 were not covered by tests
f"{machine_config.instrument_server_url}{url_path_for('api.router', 'flush_skipped_rsyncer', session_id=session_id)}",
json={
"label": session_id,
"source": str(secure_path(Path(rsyncer_source.source))),
},
headers={
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
},
) as resp:
data = await resp.json()
return data

Check warning on line 532 in src/murfey/server/api/instrument.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/instrument.py#L531-L532

Added lines #L531 - L532 were not covered by tests


class RSyncerInfo(BaseModel):
source: str
num_files_transferred: int
Expand Down
25 changes: 20 additions & 5 deletions src/murfey/util/route_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ murfey.instrument_server.api.router:
type: str
methods:
- DELETE
- path: /sessions/{session_id}/multigrid_controller/visit_end_time
function: update_multigrid_controller_visit_end_time
path_params: []
methods:
- POST
- path: /sessions/{session_id}/stop_rsyncer
function: stop_rsyncer
path_params: []
Expand Down Expand Up @@ -68,6 +73,11 @@ murfey.instrument_server.api.router:
path_params: []
methods:
- POST
- path: /sessions/{session_id}/flush_skipped_rsyncer
function: flush_skipped_rsyncer
path_params: []
methods:
- POST
- path: /sessions/{session_id}/rsyncer_info
function: get_rsyncer_info
path_params: []
Expand Down Expand Up @@ -535,6 +545,11 @@ murfey.server.api.instrument.router:
path_params: []
methods:
- POST
- path: /instrument_server/sessions/{session_id}/multigrid_controller/visit_end_time
function: update_visit_end_time
path_params: []
methods:
- POST
- path: /instrument_server/sessions/{session_id}/abandon_session
function: abandon_session
path_params: []
Expand All @@ -550,6 +565,11 @@ murfey.server.api.instrument.router:
path_params: []
methods:
- POST
- path: /instrument_server/sessions/{session_id}/flush_skipped_rsyncer
function: flush_skipped_rsyncer
path_params: []
methods:
- POST
- path: /instrument_server/instruments/{instrument_name}/sessions/{session_id}/rsyncer_info
function: get_rsyncer_info
path_params:
Expand Down Expand Up @@ -821,11 +841,6 @@ murfey.server.api.session_info.correlative_router:
methods:
- GET
murfey.server.api.session_info.router:
- path: /session_info/
function: root
path_params: []
methods:
- GET
- path: /session_info/health/
function: health_check
path_params: []
Expand Down