diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-29 20:54:03 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-29 20:54:03 +0000 |
| commit | 0e5b7f5f4dfc73beddce322e470622522d5c1d0e (patch) | |
| tree | 7c1dffcd1f54ba3d0139a2bd12d524fdd6619b49 /nova/api | |
| parent | 99233ace206a2c74bfccebc5739e1553c4adcefe (diff) | |
| parent | c8b0a9a3be7ca276d91d470a629fdd0209812993 (diff) | |
Merge "Ensures that keypair names are only AlphaNumeric."
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/keypairs.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py index 0e8a4bb06..5f6f56e15 100644 --- a/nova/api/openstack/compute/contrib/keypairs.py +++ b/nova/api/openstack/compute/contrib/keypairs.py @@ -17,6 +17,8 @@ """ Keypair management extension""" +import string + import webob import webob.exc @@ -61,6 +63,13 @@ class KeypairController(object): 'public_key': public_key, 'fingerprint': fingerprint} + def _validate_keypair_name(self, value): + safechars = "_-" + string.digits + string.ascii_letters + clean_value = "".join(x for x in value if x in safechars) + if clean_value != value: + msg = _("Keypair name contains unsafe characters") + raise webob.exc.HTTPBadRequest(explanation=msg) + @wsgi.serializers(xml=KeypairTemplate) def create(self, req, body): """ @@ -80,6 +89,7 @@ class KeypairController(object): authorize(context) params = body['keypair'] name = params['name'] + self._validate_keypair_name(name) if not 0 < len(name) < 256: msg = _('Keypair name must be between 1 and 255 characters long') |
