Skip to content

Commit

Permalink
externaldata: Error cleanly when source is missing required checksum
Browse files Browse the repository at this point in the history
See #421
  • Loading branch information
bbhtt committed May 26, 2024
1 parent 6bef8dd commit 3c1c12f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/externaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ def from_source(
if not source.get("url"):
raise SourceUnsupported('Data is not external: no "url" property')

if (
source.get("type") == ExternalBase.Type.EXTRA_DATA
and "sha256" not in source.keys()
):
raise SourceLoadError("Extra data is missing SHA256 checksum")

if source.get("type") in (
ExternalBase.Type.FILE,
ExternalBase.Type.ARCHIVE,
):
if not any(k in source.keys() for k in ("md5", "sha1", "sha256", "sha512")):
raise SourceLoadError("Data is missing checksum")

# FIXME: https://github.com/python/mypy/issues/9282
return super().from_source(source_path, source, module) # type: ignore

Expand Down

0 comments on commit 3c1c12f

Please sign in to comment.