diff --git a/nmdc_runtime/api/core/util.py b/nmdc_runtime/api/core/util.py index 48d15ed1..ff3bcb4a 100644 --- a/nmdc_runtime/api/core/util.py +++ b/nmdc_runtime/api/core/util.py @@ -28,10 +28,13 @@ def hash_from_str(s: str, algo="sha256") -> str: return getattr(hashlib, algo)(s.encode("utf-8")).hexdigest() -def sha256hash_from_file(file_path: str): +def sha256hash_from_file(file_path: str, timestamp: str): # https://stackoverflow.com/a/55542529 h = hashlib.sha256() + timestamp_bytes = timestamp.encode('utf-8') + h.update(timestamp_bytes) + with open(file_path, "rb") as file: while True: # Reading is buffered, so we can read smaller chunks. diff --git a/nmdc_runtime/api/endpoints/util.py b/nmdc_runtime/api/endpoints/util.py index fd473682..35c63a5a 100644 --- a/nmdc_runtime/api/endpoints/util.py +++ b/nmdc_runtime/api/endpoints/util.py @@ -442,6 +442,7 @@ def persist_content_and_get_drs_object( ), "access_methods": [{"access_id": drs_id}], }, + timestamp= datetime.now(tz=ZoneInfo('America/Los_Angeles')).isoformat(timespec='minutes') ) ) self_uri = f"drs://{HOSTNAME_EXTERNAL}/{drs_id}" diff --git a/nmdc_runtime/util.py b/nmdc_runtime/util.py index 23e94dd1..475a98d4 100644 --- a/nmdc_runtime/util.py +++ b/nmdc_runtime/util.py @@ -82,7 +82,7 @@ def put_object(filepath, url, mime_type=None): return requests.put(url, data=f, headers={"Content-Type": mime_type}) -def drs_metadata_for(filepath, base=None): +def drs_metadata_for(filepath, base=None, timestamp=None): """given file path, get drs metadata required: size, created_time, and at least one checksum. @@ -96,7 +96,7 @@ def drs_metadata_for(filepath, base=None): ) if "checksums" not in base: base["checksums"] = [ - {"type": "sha256", "checksum": sha256hash_from_file(filepath)} + {"type": "sha256", "checksum": sha256hash_from_file(filepath, timestamp)} ] if "mime_type" not in base: base["mime_type"] = mimetypes.guess_type(filepath)[0]