Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
af61be2
Get 'feedback_queue' from security config or transport object instead…
tieneupin Feb 13, 2025
dce6d93
Sanitised 'session_id' object in log
tieneupin Feb 13, 2025
f90f4ad
Added draft unit test for 'process_raw_lifs' workflow
tieneupin Feb 13, 2025
166d142
Removed leftover 'pass'
tieneupin Feb 13, 2025
d593a56
Added unit test for 'process_raw_tiffs' workflow
tieneupin Feb 13, 2025
fb4f5e9
Missed creating a directory level
tieneupin Feb 13, 2025
64cb692
Forgot to do the same for the metadata file
tieneupin Feb 13, 2025
eea1674
Added unit test for 'align_and_merge' workflow
tieneupin Feb 13, 2025
0da2cb4
Patched function placed in wrong order
tieneupin Feb 13, 2025
9b4a6ac
'.return_value' might not be neded when mocking class attribute
tieneupin Feb 13, 2025
6994141
Wrong job name
tieneupin Feb 13, 2025
639a8fd
Merged recent changes from 'main' branch
tieneupin Feb 18, 2025
28ceb5e
Added logic to retry database refreshes and file path validation to a…
tieneupin Feb 18, 2025
33b3478
Added logs to empty 'except:' blocks
tieneupin Feb 19, 2025
b2d4a1e
More verbose logging for errors in CLEM API endpoints; sanitised vari…
tieneupin Feb 19, 2025
d50f929
Fixed incorrect canonical representation in boostrap API logs
tieneupin Feb 19, 2025
2d2eb40
Removed database refresh instances from CLEM workflows, as they seem …
tieneupin Feb 20, 2025
d85d913
Removed checks from 'validate_and_sanitise' functions for whether a P…
tieneupin Feb 20, 2025
5acdbff
Use full rsync basepath when validating files
tieneupin Feb 20, 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
4 changes: 2 additions & 2 deletions src/murfey/server/api/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@

# Validate environment
if any(system in env[0] and environment in env[1] for env in valid_envs) is False:
raise ValueError(f"{system!r}/{environment!r} is not a valid msys2 environment")
raise ValueError(f"'{system}/{environment}' is not a valid msys2 environment")

Check warning on line 542 in src/murfey/server/api/bootstrap.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/bootstrap.py#L542

Added line #L542 was not covered by tests

# Validate package name
# MSYS2 package names contain:
Expand Down Expand Up @@ -593,7 +593,7 @@
else:
raise HTTPException(status_code=response.status_code)
else:
raise ValueError(f"{package} is not a valid package name")
raise ValueError(f"{package!r} is not a valid package name")

Check warning on line 596 in src/murfey/server/api/bootstrap.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/bootstrap.py#L596

Added line #L596 was not covered by tests


@pypi.get("/", response_class=Response)
Expand Down
172 changes: 141 additions & 31 deletions src/murfey/server/api/clem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from murfey.server import _transport_object
from murfey.server.murfey_db import murfey_db
from murfey.util import sanitise
from murfey.util.config import get_machine_config
from murfey.util.db import (
CLEMImageMetadata,
Expand Down Expand Up @@ -77,7 +78,7 @@
machine_config = get_machine_config(instrument_name=instrument_name)[
instrument_name
]
base_path = machine_config.rsync_basepath.as_posix()
rsync_basepath = machine_config.rsync_basepath.resolve()

Check warning on line 81 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L81

Added line #L81 was not covered by tests

# Check that full file path doesn't contain unallowed characters
# Currently allows only:
Expand All @@ -90,13 +91,9 @@
raise ValueError(f"Unallowed characters present in {file}")

# Check that it's not accessing somehwere it's not allowed
if not str(full_path).startswith(str(base_path)):
if not str(full_path).startswith(str(rsync_basepath)):
raise ValueError(f"{file} points to a directory that is not permitted")

# Check that it's a file, not a directory
if full_path.is_file() is False:
raise ValueError(f"{file} is not a file")

# Check that it is of a permitted file type
if f"{full_path.suffix}" not in valid_file_types:
raise ValueError(f"{full_path.suffix} is not a permitted file format")
Expand Down Expand Up @@ -184,7 +181,7 @@
)
db.add(db_entry)
db.commit()
db.refresh(db_entry)

except Exception:
raise Exception

Expand Down Expand Up @@ -215,7 +212,11 @@
file_path=lif_file,
)
except Exception:
logger.error(traceback.format_exc())
logger.error(

Check warning on line 215 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L215

Added line #L215 was not covered by tests
"Exception encountered while registering "
f"LIF file {sanitise(str(lif_file))!r}: \n"
f"{traceback.format_exc()}"
)
return False

# Add metadata information if provided
Expand All @@ -224,7 +225,11 @@
master_metadata = validate_and_sanitise(master_metadata, session_id, db)
clem_lif_file.master_metadata = str(master_metadata)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 228 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L228

Added line #L228 was not covered by tests
"Unable to add master metadata information to database entry for "
f"LIF file {sanitise(str(lif_file))!r}: \n"
f"{traceback.format_exc()}"
)

# Register child metadata if provided
for metadata in child_metadata:
Expand All @@ -238,7 +243,12 @@
# Append to database entry
clem_lif_file.child_metadata.append(metadata_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 246 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L246

Added line #L246 was not covered by tests
"Unable to register "
f"metadata file {sanitise(str(metadata))!r} in association with "
f"LIF file {sanitise(str(lif_file))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Register child image series if provided
Expand All @@ -253,7 +263,12 @@
# Append to database entry
clem_lif_file.child_series.append(series_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 266 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L266

Added line #L266 was not covered by tests
"Unable to register "
f"metadata file {sanitise(series)!r} in association with "
f"LIF file {sanitise(str(lif_file))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Register child image stacks if provided
Expand All @@ -268,7 +283,12 @@
# Append to database entry
clem_lif_file.child_stacks.append(stack_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 286 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L286

Added line #L286 was not covered by tests
"Unable to register "
f"image stack {sanitise(str(stack))!r} in association with "
f"LIF file {sanitise(str(lif_file))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Commit to database
Expand Down Expand Up @@ -296,7 +316,11 @@
file_path=tiff_file,
)
except Exception:
logger.error(traceback.format_exc())
logger.error(

Check warning on line 319 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L319

Added line #L319 was not covered by tests
"Exception encountered while registering "
f"TIFF file {sanitise(str(tiff_file))!r}: \n"
f"{traceback.format_exc()}"
)
return False

# Add metadata if provided
Expand All @@ -311,7 +335,12 @@
# Link database entries
clem_tiff_file.associated_metadata = metadata_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 338 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L338

Added line #L338 was not covered by tests
"Unable to register "
f"metadata file {sanitise(str(associated_metadata))!r} in association with "
f"TIFF file {sanitise(str(tiff_file))!r}: \n"
f"{traceback.format_exc()}"
)

# Add series information if provided
if associated_series is not None:
Expand All @@ -325,7 +354,12 @@
# Link database entries
clem_tiff_file.child_series = series_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 357 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L357

Added line #L357 was not covered by tests
"Unable to register "
f"CLEM series {sanitise(associated_series)!r} in association with "
f"TIFF file {sanitise(str(tiff_file))!r}: \n"
f"{traceback.format_exc()}"
)

# Add image stack information if provided
if associated_stack is not None:
Expand All @@ -339,7 +373,11 @@
# Link database entries
clem_tiff_file.child_stack = stack_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 376 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L376

Added line #L376 was not covered by tests
"Unable to register "
f"image stack {sanitise(str(associated_stack))!r} in association with "
f"{traceback.format_exc()}"
)

# Commit to database
db.add(clem_tiff_file)
Expand Down Expand Up @@ -368,7 +406,11 @@
file_path=metadata_file,
)
except Exception:
logger.error(traceback.format_exc())
logger.error(

Check warning on line 409 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L409

Added line #L409 was not covered by tests
"Exception encountered while registering"
f"metadata file {sanitise(str(metadata_file))!r}"
f"{traceback.format_exc()}"
)
return False

# Register a parent LIF file if provided
Expand All @@ -383,7 +425,12 @@
# Link database entries
clem_metadata.parent_lif = lif_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 428 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L428

Added line #L428 was not covered by tests
"Unable to register "
f"LIF file {sanitise(str(parent_lif))!r} in association with "
f"metadata file {sanitise(str(metadata_file))!r}: \n"
f"{traceback.format_exc()}"
)

# Register associated TIFF files if provided
for tiff in associated_tiffs:
Expand All @@ -397,7 +444,12 @@
# Append entry
clem_metadata.associated_tiffs.append(tiff_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 447 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L447

Added line #L447 was not covered by tests
"Unable to register "
f"TIFF file {sanitise(str(tiff))!r} in association with "
f"metadata file {sanitise(str(metadata_file))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Register associated image series if provided
Expand All @@ -414,7 +466,12 @@
db.add(series_db_entry)
db.commit()
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 469 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L469

Added line #L469 was not covered by tests
"Unable to register "
f"CLEM series {sanitise(associated_series)!r} in association with "
f"metadata file {sanitise(str(metadata_file))!r}: \n"
f"{traceback.format_exc()}"
)

# Register associated image stacks if provided
for stack in associated_stacks:
Expand All @@ -427,7 +484,12 @@
)
clem_metadata.associated_stacks.append(stack_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 487 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L487

Added line #L487 was not covered by tests
"Unable to register "
f"image stack {sanitise(str(stack))!r} in association with "
f"metadata file {sanitise(str(metadata_file))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Commit to database
Expand Down Expand Up @@ -456,7 +518,11 @@
series_name=series_name,
)
except Exception:
logger.error(traceback.format_exc())
logger.error(

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

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L521

Added line #L521 was not covered by tests
"Exception encountered while registering "
f"CLEM series {sanitise(series_name)!r}: \n"
f"{traceback.format_exc()}"
)
return False

# Register parent LIF file if provided
Expand All @@ -471,7 +537,12 @@
# Link entries
clem_image_series.parent_lif = lif_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 540 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L540

Added line #L540 was not covered by tests
"Unable to register "
f"LIF file {sanitise(str(parent_lif))!r} in association with "
f"CLEM series {sanitise(series_name)!r}: \n"
f"{traceback.format_exc()}"
)

# Register parent TIFFs if provided
for tiff in parent_tiffs:
Expand All @@ -485,7 +556,12 @@
# Append entry
clem_image_series.parent_tiffs.append(tiff_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 559 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L559

Added line #L559 was not covered by tests
"Unable to register "
f"TIFF file {sanitise(str(tiff))!r} in association with "
f"CLEM series {sanitise(series_name)!r}: \n"
f"{traceback.format_exc()}"
)
continue # Try next item in loop

# Register associated metadata if provided
Expand All @@ -500,7 +576,12 @@
# Link entries
clem_image_series.associated_metadata = metadata_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 579 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L579

Added line #L579 was not covered by tests
"Unable to register "
f"metadata file {sanitise(str(associated_metadata))!r} in association with "
f"CLEM series {sanitise(series_name)!r}: \n"
f"{traceback.format_exc()}"
)

# Register child image stacks if provided
for stack in child_stacks:
Expand All @@ -514,7 +595,12 @@
# Append entry
clem_image_series.child_stacks.append(stack_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 598 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L598

Added line #L598 was not covered by tests
"Unable to register "
f"image stack {sanitise(str(stack))!r} in association with "
f"CLEM series {sanitise(series_name)!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Register
Expand Down Expand Up @@ -544,7 +630,11 @@
file_path=image_stack,
)
except Exception:
logger.error(traceback.format_exc())
logger.error(

Check warning on line 633 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L633

Added line #L633 was not covered by tests
"Exception encountered while registering "
f"image stack {sanitise(str(image_stack))!r}: \n"
f"{traceback.format_exc()}"
)
return False

# Register channel name if provided
Expand All @@ -562,7 +652,12 @@
)
clem_image_stack.parent_lif = lif_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 655 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L655

Added line #L655 was not covered by tests
"Unable to register "
f"LIF file {sanitise(str(parent_lif))!r} in association with "
f"image stack {sanitise(str(image_stack))!r}: \n"
f"{traceback.format_exc()}"
)

# Register parent TIFF files if provided
for tiff in parent_tiffs:
Expand All @@ -576,7 +671,12 @@
# Append entry
clem_image_stack.parent_tiffs.append(tiff_db_entry)
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 674 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L674

Added line #L674 was not covered by tests
"Unable to register "
f"TIFF file {sanitise(str(tiff))!r} in association with "
f"image stack {sanitise(str(image_stack))!r}: \n"
f"{traceback.format_exc()}"
)
continue

# Register associated metadata if provided
Expand All @@ -591,7 +691,12 @@
# Link entries
clem_image_stack.associated_metadata = metadata_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 694 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L694

Added line #L694 was not covered by tests
"Unable to register "
f"metadata file {sanitise(str(associated_metadata))!r} in association with "
f"image stack {sanitise(str(image_stack))!r}: \n"
f"{traceback.format_exc()}"
)

# Register parent series if provided
if parent_series is not None:
Expand All @@ -605,7 +710,12 @@
# Link entries
clem_image_stack.parent_series = series_db_entry
except Exception:
logger.warning(traceback.format_exc())
logger.warning(

Check warning on line 713 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L713

Added line #L713 was not covered by tests
"Unable to register "
f"CLEM series {sanitise(parent_series)!r} in association with "
f"image stack {sanitise(str(image_stack))!r}: \n"
f"{traceback.format_exc()}"
)

# Register updates to entry
db.add(clem_image_stack)
Expand Down
Loading
Loading