55import tempfile
66import zipfile
77from collections import Counter
8- from hashlib import sha256
98from pathlib import Path
109from types import TracebackType
1110from typing import Any , Literal
5857from cognite_toolkit ._cdf_tk .exceptions import ToolkitError , ToolkitRequiredValueError , ToolkitValueError
5958from cognite_toolkit ._cdf_tk .hints import verify_module_directory
6059from cognite_toolkit ._cdf_tk .tk_warnings import MediumSeverityWarning
61- from cognite_toolkit ._cdf_tk .tk_warnings .other import HighSeverityWarning
6260from cognite_toolkit ._cdf_tk .utils import humanize_collection , read_yaml_file
6361from cognite_toolkit ._cdf_tk .utils .file import safe_read , safe_rmtree , safe_write , yaml_safe_dump
6462from cognite_toolkit ._cdf_tk .utils .modules import module_directory_from_path
@@ -290,6 +288,8 @@ def init(
290288 library_url : str | None = None ,
291289 library_checksum : str | None = None ,
292290 ) -> None :
291+ _ = library_checksum
292+
293293 if not organization_dir :
294294 organization_dir = ModulesCommand ._prompt_organization_dir ()
295295
@@ -298,11 +298,7 @@ def init(
298298 # Determine which library to use (if any)
299299 library : Library | None = None
300300 if library_url :
301- if not library_checksum :
302- raise ToolkitRequiredValueError (
303- "The '--library-checksum' is required when '--library-url' is provided."
304- )
305- library = Library (url = library_url , checksum = library_checksum )
301+ library = Library (url = library_url )
306302 elif not (organization_dir / CDFToml .file_name ).exists ():
307303 # Load default library from resources when cdf.toml doesn't exist
308304 default_cdf_toml = CDFToml .load (cwd = RESOURCES_PATH , use_singleton = False )
@@ -887,7 +883,6 @@ def _get_available_packages(self, user_library: Library | None = None) -> tuple[
887883 )
888884 file_path = self ._temp_download_dir / filename
889885 self ._download (library .url , file_path )
890- self ._validate_checksum (library .checksum , file_path )
891886 self ._unpack (file_path )
892887 packages = Packages ().load (file_path .parent )
893888 if packages .warnings :
@@ -996,40 +991,6 @@ def _download(self, url: str, file_path: Path) -> None:
996991 except requests .exceptions .RequestException as e :
997992 raise ToolkitError (f"Error downloading file from { url } : { e } " ) from e
998993
999- def _validate_checksum (self , checksum : str , file_path : Path ) -> None :
1000- """
1001- Compares the checksum of the downloaded file with the expected checksum.
1002- """
1003-
1004- if checksum .lower ().startswith ("sha256:" ):
1005- checksum = checksum [7 :]
1006- else :
1007- raise ToolkitValueError (f"Unsupported checksum format: { checksum } . Expected 'sha256:' prefix" )
1008-
1009- chunk_size : int = 8192
1010- sha256_hash = sha256 ()
1011- try :
1012- with open (file_path , "rb" ) as f :
1013- # Read the file in chunks to handle large files efficiently
1014- for chunk in iter (lambda : f .read (chunk_size ), b"" ):
1015- sha256_hash .update (chunk )
1016- calculated = sha256_hash .hexdigest ()
1017- except OSError as e :
1018- raise ToolkitError (f"Failed to calculate checksum for { file_path } : { e } " ) from e
1019- except Exception as e :
1020- raise ToolkitError (f"Unexpected error during checksum calculation for { file_path } : { e } " ) from e
1021-
1022- if calculated != checksum :
1023- self .warn (
1024- HighSeverityWarning (
1025- f"The provided checksum sha256:{ checksum } does not match downloaded file hash sha256:{ calculated } .\n "
1026- "Please verify the checksum with the source and update cdf.toml if needed.\n "
1027- "This may indicate that the package content has changed."
1028- )
1029- )
1030- else :
1031- print ("[green]✓ Checksum verified[/green]" )
1032-
1033994 def _unpack (self , file_path : Path ) -> None :
1034995 """
1035996 Unzips the downloaded file to the specified output path.
0 commit comments