Skip to content

Commit 519abea

Browse files
authored
Merge pull request #85 from podaac/develop
Develop release to Main (1.10.1)
2 parents 2fbe9d4 + 9105adf commit 519abea

5 files changed

+61
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55

6+
## [1.10.1]
7+
### Fixed
8+
- Support for SHA-256 and SHA-512 checksums
9+
610
## [1.10.0]
711
### Changed
812
- Changed minimum supported python version to 3.7, down from 3.8.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "podaac-data-subscriber"
3-
version = "1.10.0"
3+
version = "1.10.1"
44
description = "PO.DAAC Data Subscriber Command Line Tool"
55
authors = ["PO.DAAC <[email protected]>"]
66
readme = "README.md"

subscriber/podaac_access.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import tenacity
2222
from datetime import datetime
2323

24-
__version__ = "1.10.0"
24+
__version__ = "1.10.1"
2525
extensions = [".nc", ".h5", ".zip", ".tar.gz"]
2626
edl = "urs.earthdata.nasa.gov"
2727
cmr = "cmr.earthdata.nasa.gov"
@@ -428,7 +428,8 @@ def make_checksum(file_path, algorithm):
428428
"""
429429
# Based on https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file#answer-3431838
430430
# with modification to handle multiple algorithms
431-
hash_alg = getattr(hashlib, algorithm.lower())()
431+
hashlib_algorithm_name = algorithm.lower().replace("-", "")
432+
hash_alg = hashlib.new(hashlib_algorithm_name)
432433

433434
with open(file_path, 'rb') as f:
434435
for chunk in iter(lambda: f.read(4096), b""):

tests/test_downloader_regression.py

+21
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,24 @@ def test_downloader_MUR():
4747
assert t2 != os.path.getmtime('./MUR25-JPL-L4-GLOB-v04.2/2020/01/02/20200102090000-JPL-L4_GHRSST-SSTfnd-MUR25-GLOB-v02.0-fv04.2.nc')
4848

4949
shutil.rmtree('./MUR25-JPL-L4-GLOB-v04.2')
50+
51+
52+
@pytest.mark.regression
53+
def test_downloader_GRACE_with_SHA_512(tmpdir):
54+
# start with empty directory
55+
directory_str = str(tmpdir)
56+
assert len( os.listdir(directory_str) ) == 0
57+
58+
# run the command once -> should download the file. Note the modified time for the file
59+
args = create_downloader_args(f"-c GRACEFO_L2_CSR_MONTHLY_0060 -sd 2020-01-01T00:00:00Z -ed 2020-01-02T00:00:01Z -d {str(tmpdir)} --limit 1 --verbose -e 00".split())
60+
pdd.run(args)
61+
assert len( os.listdir(directory_str) ) > 0
62+
filename = directory_str + "/" + os.listdir(directory_str)[0]
63+
modified_time_1 = os.path.getmtime(filename)
64+
print( modified_time_1 )
65+
66+
# run the command again -> should not redownload the file. The modified time for the file should not change
67+
pdd.run(args)
68+
modified_time_2 = os.path.getmtime(filename)
69+
print( modified_time_2 )
70+
assert modified_time_1 == modified_time_2

tests/test_subscriber_matching_checksums.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_checksum_does_match__positive_match_sha512(tmpdir):
3535
checksums = {
3636
"tmp.nc": {
3737
"Value": "439de7997fe599d7af6d108534cae418ac95f70f614e3c2fda7a26b03e599211ffbfc85eede5dd933aa7a3c5cfe87d6b3de30ab2d9b4fd45162a5e22b71fffe8",
38-
"Algorithm": "SHA512"
38+
"Algorithm": "SHA-512"
3939
}
4040
}
4141

@@ -50,7 +50,37 @@ def test_checksum_does_match__negative_match_sha512(tmpdir):
5050
checksums = {
5151
"tmp.nc": {
5252
"Value": "439de7997fe599d7af6d108534cae418ac95f70f614e3c2fda7a26b03e599211ffbfc85eede5dd933aa7a3c5cfe87d6b3de30ab2d9b4fd45162a5e22b71fffe8",
53-
"Algorithm": "SHA512"
53+
"Algorithm": "SHA-512"
54+
}
55+
}
56+
57+
with open(output_path, 'w') as f:
58+
f.write("This is a different temporary test file")
59+
60+
assert not checksum_does_match(output_path, checksums)
61+
62+
63+
def test_checksum_does_match__positive_match_sha256(tmpdir):
64+
output_path = str(tmpdir) + '/tmp.nc'
65+
checksums = {
66+
"tmp.nc": {
67+
"Value": "020b00190141a585d214454e3c1c676eaaab12f10c2cb0bf266a0bdb47a78609",
68+
"Algorithm": "SHA-256"
69+
}
70+
}
71+
72+
with open(output_path, 'w') as f:
73+
f.write("This is a temporary test file")
74+
75+
assert checksum_does_match(output_path, checksums)
76+
77+
78+
def test_checksum_does_match__negative_match_sha256(tmpdir):
79+
output_path = str(tmpdir) + '/tmp.nc'
80+
checksums = {
81+
"tmp.nc": {
82+
"Value": "020b00190141a585d214454e3c1c676eaaab12f10c2cb0bf266a0bdb47a78609",
83+
"Algorithm": "SHA-256"
5484
}
5585
}
5686

0 commit comments

Comments
 (0)