Skip to content

Commit

Permalink
Add calculate_sha256 management command to trigger (re)computation fo…
Browse files Browse the repository at this point in the history
…r a blob

Added ability to specify either blob id (where it applies) or asset id since
that is the id we typically know for which a blob lacks sha256.

Refs:
- #471
- #1578
  • Loading branch information
yarikoptic committed May 10, 2024
1 parent 22d819d commit f3b32c0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dandiapi/api/management/commands/calculate_sha256.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import djclick as click

from dandiapi.api.models import Asset
from dandiapi.api.tasks import calculate_sha256 as do_calculate_sha256


@click.command()
@click.option('--blob-id', 'blob_id', help='Blob ID')
@click.option('--asset-id', 'asset_id', help='Asset ID')
def calculate_sha256(asset_id: str | None = None, blob_id: str | None = None):
"""Trigger computation of sha256 for a blob
Either blob-id or asset-id should be provided.
"""
if not asset_id and not blob_id:
raise ValueError('Provide either asset_id or blob_id')

if asset_id and blob_id:
raise ValueError('Provide only asset_id or blob_id, not both')

if not blob_id:
assert asset_id
asset = Asset.objects.get(asset_id=asset_id)
blob_id = asset.blob_id

do_calculate_sha256(blob_id=blob_id)

0 comments on commit f3b32c0

Please sign in to comment.