Skip to content

Commit

Permalink
fix(dependency): seperate tar unpack from global fetch function
Browse files Browse the repository at this point in the history
This will make it easier to handle packages sourced/read from other locations
  • Loading branch information
AntoineDao committed Jun 2, 2020
1 parent 9b78c69 commit 882bedf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions queenbee/recipe/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,16 @@ def fetch(self, verifydigest: bool = True) -> Tuple[bytes, str]:

filebytes = BytesIO(res.read())

tar = tarfile.open(fileobj=filebytes)
return self.unpack_tar(
tar_file=filebytes,
verify_digest=verifydigest,
digest=self.digest
)

@staticmethod
def unpack_tar(tar_file: BytesIO, verify_digest: bool = True, digest: str = None):

tar = tarfile.open(fileobj=tar_file)

file_bytes = None
readme_string = None
Expand All @@ -165,11 +174,11 @@ def fetch(self, verifydigest: bool = True) -> Tuple[bytes, str]:
if member.name == 'resource.json':
file_bytes = tar.extractfile(member).read()

if verifydigest:
assert hashlib.sha256(file_bytes).hexdigest() == self.digest, \
if verify_digest:
assert hashlib.sha256(file_bytes).hexdigest() == digest, \
ValueError(
f'Hash of resource.json file is different from the one'
f' expected from the index Expected {self.digest} and got'
f' expected from the index Expected {digest} and got'
f' {hashlib.sha256(file_bytes).hexdigest()}'
)
break
Expand All @@ -187,4 +196,4 @@ def fetch(self, verifydigest: bool = True) -> Tuple[bytes, str]:



return file_bytes, self.digest, readme_string, license_string
return file_bytes, digest, readme_string, license_string

0 comments on commit 882bedf

Please sign in to comment.