Add package check for package name length

Now upload and modify package, do not check the name length, but the
package name in db models name length is 80, So we should check the
package name length.

Change-Id: Idd14793267b5adc49ff980db4f737a6eb0bcad1a
Closes-bug: #1535522
This commit is contained in:
zhurong 2016-01-19 04:41:51 +00:00
parent 4ea7f88aca
commit 124e23bea1
1 changed files with 9 additions and 1 deletions

View File

@ -165,7 +165,11 @@ class Controller(object):
if 'is_public' in change['path']:
if change['value'] is True and not pkg_to_update.is_public:
policy.check('publicize_package', req.context)
break
if 'name' in change['path']:
if len(change['value']) > 80:
msg = _('Package name should be 80 characters maximum')
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
package = db_api.package_update(package_id, body, req.context)
return package.to_dict()
@ -239,6 +243,10 @@ class Controller(object):
for k, v in six.iteritems(PKG_PARAMS_MAP):
if hasattr(pkg_to_upload, k):
package_meta[v] = getattr(pkg_to_upload, k)
if len(package_meta['name']) > 80:
msg = _('Package name should be 80 characters maximum')
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
try:
package = db_api.package_upload(
package_meta, req.context.tenant)