diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-05-11 21:56:39 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-05-11 21:56:39 +0000 |
| commit | 0768a6adb71b7a7004b4b5dc4e111bf786e30362 (patch) | |
| tree | cf358607c8b58f8f9e70f8e1ff126d89d7e7a880 /nova/api | |
| parent | a07fddf525c74884d5934703206a3564fb8070e2 (diff) | |
| parent | e064a4ea750a6237dabf03202b1dcb6fa435c7f6 (diff) | |
| download | nova-0768a6adb71b7a7004b4b5dc4e111bf786e30362.tar.gz nova-0768a6adb71b7a7004b4b5dc4e111bf786e30362.tar.xz nova-0768a6adb71b7a7004b4b5dc4e111bf786e30362.zip | |
Merge "Added img metadata validation. Fixes bug 962117."
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 15 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/admin_actions.py | 2 | ||||
| -rw-r--r-- | nova/api/openstack/compute/image_metadata.py | 8 | ||||
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 2 |
4 files changed, 21 insertions, 6 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 0d419f205..01787712a 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -269,7 +269,7 @@ def get_version_from_href(href): return '2' -def check_img_metadata_quota_limit(context, metadata): +def check_img_metadata_properties_quota(context, metadata): if metadata is None: return num_metadata = len(metadata) @@ -279,6 +279,19 @@ def check_img_metadata_quota_limit(context, metadata): raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl, headers={'Retry-After': 0}) + # check the key length. + if isinstance(metadata, dict): + for key, value in metadata.iteritems(): + if len(key) == 0: + expl = _("Image metadata key cannot be blank") + raise webob.exc.HTTPBadRequest(explanation=expl) + if len(key) > 255: + expl = _("Image metadata key too long") + raise webob.exc.HTTPBadRequest(explanation=expl) + else: + expl = _("Invalid image metadata") + raise webob.exc.HTTPBadRequest(explanation=expl) + def dict_to_query_str(params): # TODO(throughnothing): we should just use urllib.urlencode instead of this diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py index f7908f758..f9e661062 100644 --- a/nova/api/openstack/compute/contrib/admin_actions.py +++ b/nova/api/openstack/compute/contrib/admin_actions.py @@ -231,7 +231,7 @@ class AdminActionsController(wsgi.Controller): props = {} metadata = entity.get('metadata', {}) - common.check_img_metadata_quota_limit(context, metadata) + common.check_img_metadata_properties_quota(context, metadata) try: props.update(metadata) except ValueError: diff --git a/nova/api/openstack/compute/image_metadata.py b/nova/api/openstack/compute/image_metadata.py index d79692f22..145e0395e 100644 --- a/nova/api/openstack/compute/image_metadata.py +++ b/nova/api/openstack/compute/image_metadata.py @@ -64,7 +64,8 @@ class Controller(object): if 'metadata' in body: for key, value in body['metadata'].iteritems(): image['properties'][key] = value - common.check_img_metadata_quota_limit(context, image['properties']) + common.check_img_metadata_properties_quota(context, + image['properties']) self.image_service.update(context, image_id, image, None) return dict(metadata=image['properties']) @@ -88,7 +89,8 @@ class Controller(object): image = self._get_image(context, image_id) image['properties'][id] = meta[id] - common.check_img_metadata_quota_limit(context, image['properties']) + common.check_img_metadata_properties_quota(context, + image['properties']) self.image_service.update(context, image_id, image, None) return dict(meta=meta) @@ -98,7 +100,7 @@ class Controller(object): context = req.environ['nova.context'] image = self._get_image(context, image_id) metadata = body.get('metadata', {}) - common.check_img_metadata_quota_limit(context, metadata) + common.check_img_metadata_properties_quota(context, metadata) image['properties'] = metadata self.image_service.update(context, image_id, image, None) return dict(metadata=metadata) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 635123fff..9aa637cc9 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1093,7 +1093,7 @@ class Controller(wsgi.Controller): props = {} metadata = entity.get('metadata', {}) - common.check_img_metadata_quota_limit(context, metadata) + common.check_img_metadata_properties_quota(context, metadata) try: props.update(metadata) except ValueError: |
