Add download hook

Change-Id: I46644ced4e2aaf64392be70133538b0a48478772
This commit is contained in:
Mike Fedosin 2017-06-17 16:26:06 +03:00
parent eb1d518c21
commit d9915469ab
2 changed files with 22 additions and 4 deletions

View File

@ -399,7 +399,7 @@ class Engine(object):
blob_name = "%s[%s]" % (field_name, blob_key)\
if blob_key else field_name
# check if property is downloadable
# check if field is downloadable
if blob_key is None and not af.is_blob(field_name):
msg = _("%s is not a blob") % field_name
raise exception.BadRequest(msg)
@ -440,4 +440,17 @@ class Engine(object):
data = store_api.load_from_store(uri=blob['url'], context=context)
meta['size'] = blob.get('size')
meta['content_type'] = blob.get('content_type')
return data, meta
path = None
try:
try:
# call download hook first
data, path = af.validate_download(
context, af, field_name, data)
except Exception as e:
raise exception.BadRequest(message=str(e))
return data, meta
finally:
if path:
os.remove(path)

View File

@ -619,7 +619,7 @@ class BaseArtifact(base.VersionedObject):
:param context: user context
:param af: artifact object targeted for deletion
"""
cls.validate_deletion(context, af)
cls.validate_delete(context, af)
# marking artifact as deleted
cls.db_api.update(context, af.id, {'status': cls.STATUS.DELETED})
@ -829,13 +829,18 @@ class BaseArtifact(base.VersionedObject):
"""Validation hook for uploading."""
return fd, None
@classmethod
def validate_download(cls, context, af, field_name, fd):
"""Validation hook for downloading."""
return fd, None
@classmethod
def validate_publish(cls, context, af):
"""Validation hook for publishing."""
pass
@classmethod
def validate_deletion(cls, context, af):
def validate_delete(cls, context, af):
"""Validation hook for deletion."""
pass