Fix function package downloading
Use function id as the default function package name for downloading. Change-Id: I4b7b6e837ca74dae079b11ace235e635990545d0 Story: 2002015 Task: 19655
This commit is contained in:
parent
40a89a3a8e
commit
e61e18c238
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@ -107,43 +106,44 @@ class FunctionsController(rest.RestController):
|
|||||||
This method can support HTTP request using either
|
This method can support HTTP request using either
|
||||||
'Accept:application/json' or no 'Accept' header.
|
'Accept:application/json' or no 'Accept' header.
|
||||||
"""
|
"""
|
||||||
LOG.info("Get function %s.", id)
|
ctx = context.get_ctx()
|
||||||
|
acl.enforce('function:get', ctx)
|
||||||
|
|
||||||
download = strutils.bool_from_string(
|
download = strutils.bool_from_string(
|
||||||
pecan.request.GET.get('download', False)
|
pecan.request.GET.get('download', False)
|
||||||
)
|
)
|
||||||
func_db = db_api.get_function(id)
|
func_db = db_api.get_function(id)
|
||||||
ctx = context.get_ctx()
|
|
||||||
|
|
||||||
if not download:
|
if not download:
|
||||||
|
LOG.info("Getting function %s.", id)
|
||||||
pecan.override_template('json')
|
pecan.override_template('json')
|
||||||
return resources.Function.from_db_obj(func_db).to_dict()
|
return resources.Function.from_db_obj(func_db).to_dict()
|
||||||
|
|
||||||
|
LOG.info("Downloading function %s", id)
|
||||||
|
source = func_db.code['source']
|
||||||
|
|
||||||
|
if source == constants.PACKAGE_FUNCTION:
|
||||||
|
f = self.storage_provider.retrieve(func_db.project_id, id,
|
||||||
|
func_db.code['md5sum'])
|
||||||
|
elif source == constants.SWIFT_FUNCTION:
|
||||||
|
container = func_db.code['swift']['container']
|
||||||
|
obj = func_db.code['swift']['object']
|
||||||
|
f = swift_util.download_object(container, obj)
|
||||||
else:
|
else:
|
||||||
LOG.info("Downloading function %s", id)
|
msg = 'Download image function is not allowed.'
|
||||||
source = func_db.code['source']
|
pecan.abort(
|
||||||
|
status_code=405,
|
||||||
if source == constants.PACKAGE_FUNCTION:
|
detail=msg,
|
||||||
f = self.storage_provider.retrieve(ctx.projectid, id,
|
headers={'Server-Error-Message': msg}
|
||||||
func_db.code['md5sum'])
|
|
||||||
elif source == constants.SWIFT_FUNCTION:
|
|
||||||
container = func_db.code['swift']['container']
|
|
||||||
obj = func_db.code['swift']['object']
|
|
||||||
f = swift_util.download_object(container, obj)
|
|
||||||
else:
|
|
||||||
msg = 'Download image function is not allowed.'
|
|
||||||
pecan.abort(
|
|
||||||
status_code=405,
|
|
||||||
detail=msg,
|
|
||||||
headers={'Server-Error-Message': msg}
|
|
||||||
)
|
|
||||||
|
|
||||||
pecan.response.app_iter = (f if isinstance(f, collections.Iterable)
|
|
||||||
else FileIter(f))
|
|
||||||
pecan.response.headers['Content-Type'] = 'application/zip'
|
|
||||||
pecan.response.headers['Content-Disposition'] = (
|
|
||||||
'attachment; filename="%s"' % os.path.basename(func_db.name)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pecan.response.app_iter = (f if isinstance(f, collections.Iterable)
|
||||||
|
else FileIter(f))
|
||||||
|
pecan.response.headers['Content-Type'] = 'application/zip'
|
||||||
|
pecan.response.headers['Content-Disposition'] = (
|
||||||
|
'attachment; filename="%s"' % id
|
||||||
|
)
|
||||||
|
|
||||||
@rest_utils.wrap_pecan_controller_exception
|
@rest_utils.wrap_pecan_controller_exception
|
||||||
@pecan.expose('json')
|
@pecan.expose('json')
|
||||||
def post(self, **kwargs):
|
def post(self, **kwargs):
|
||||||
|
@ -89,7 +89,7 @@ class FileSystemStorage(base.PackageStorage):
|
|||||||
LOG.debug(
|
LOG.debug(
|
||||||
'Getting package data, function: %s, version: %s, md5sum: %s, '
|
'Getting package data, function: %s, version: %s, md5sum: %s, '
|
||||||
'project: %s',
|
'project: %s',
|
||||||
function, md5sum, version, project_id
|
function, version, md5sum, project_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if version != 0:
|
if version != 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user