diff options
Diffstat (limited to 'vnfsdk_pkgtools')
-rw-r--r-- | vnfsdk_pkgtools/packager/manifest.py | 8 | ||||
-rw-r--r-- | vnfsdk_pkgtools/packager/utils.py | 18 |
2 files changed, 18 insertions, 8 deletions
diff --git a/vnfsdk_pkgtools/packager/manifest.py b/vnfsdk_pkgtools/packager/manifest.py index d819a70..e5bceb0 100644 --- a/vnfsdk_pkgtools/packager/manifest.py +++ b/vnfsdk_pkgtools/packager/manifest.py @@ -116,11 +116,9 @@ class Manifest(object): if desc['Algorithm'] not in SUPPORTED_HASH_ALGO: raise ManifestException("Unsupported hash algorithm: %s" % desc['Algorithm']) # validate file digest hash - # TODO need to support remote file - if "://" not in desc['Source']: - hash = utils.cal_file_hash(self.root, desc['Source'], desc['Algorithm']) - if hash != desc['Hash']: - raise ManifestException("Mismatched hash for file %s" % desc['Source']) + hash = utils.cal_file_hash(self.root, desc['Source'], desc['Algorithm']) + if hash != desc['Hash']: + raise ManifestException("Mismatched hash for file %s" % desc['Source']) # nothing is wrong, let's store this self.digests[desc['Source']] = (desc['Algorithm'], desc['Hash']) elif key: diff --git a/vnfsdk_pkgtools/packager/utils.py b/vnfsdk_pkgtools/packager/utils.py index 78c7b0f..2d74943 100644 --- a/vnfsdk_pkgtools/packager/utils.py +++ b/vnfsdk_pkgtools/packager/utils.py @@ -14,7 +14,12 @@ # import hashlib +from io import BytesIO import os +import urlparse + +import requests + def _hash_value_for_file(f, hash_function, block_size=2**20): while True: @@ -27,7 +32,14 @@ def _hash_value_for_file(f, hash_function, block_size=2**20): def cal_file_hash(root, path, algo): - with open(os.path.join(root, path), 'rb') as fp: - h = hashlib.new(algo) + h = hashlib.new(algo) + if urlparse.urlparse(path).scheme: + r = requests.get(path) + if r.status_code != 200: + raise ValueError('Server at {0} returned a {1} status code' + .format(path, r.status_code)) + fp = BytesIO(r.content) return _hash_value_for_file(fp, h) - + else: + with open(os.path.join(root, path), 'rb') as fp: + return _hash_value_for_file(fp, h) |