Keypair bugfixes.

Corrects keypair name validation and prevents illegal characters in
header name. Fixes bug 900528.

Fixes location of "refresh this page" message insertion to match
other messages.

Ensures that deletion of keypairs gets a confirmation dialog box.

Change-Id: I99d70dd21c840320ef3fc6a246d283cef5b7a64a
This commit is contained in:
Gabriel Hurley
2011-12-09 12:26:08 -08:00
parent 9e84bae97a
commit 75bff6914d
3 changed files with 11 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ from django import http
from django import shortcuts
from django.contrib import messages
from django.core import validators
from django.template.defaultfilters import slugify
from django.utils.http import urlquote
from django.utils.translation import ugettext as _
from novaclient import exceptions as novaclient_exceptions
@@ -53,8 +54,12 @@ class DeleteKeypair(forms.SelfHandlingForm):
class CreateKeypair(forms.SelfHandlingForm):
name = forms.CharField(max_length="20", label=_("Keypair Name"),
validators=[validators.RegexValidator('\w+')])
name = forms.CharField(max_length="20",
label=_("Keypair Name"),
validators=[validators.validate_slug],
error_messages={'invalid': _('Keypair names may '
'only contain letters, numbers, underscores '
'and hyphens.')})
def handle(self, request, data):
try:
@@ -62,8 +67,9 @@ class CreateKeypair(forms.SelfHandlingForm):
keypair = api.keypair_create(request, data['name'])
response = http.HttpResponse(mimetype='application/binary')
response['Content-Disposition'] = \
'attachment; filename=%s.pem' % keypair.name
'attachment; filename=%s.pem' % slugify(keypair.name)
response.write(keypair.private_key)
response['Content-Length'] = str(len(response.content))
return response
except novaclient_exceptions.ClientException, e:
LOG.exception("ClientException in CreateKeyPair")

View File

@@ -5,5 +5,5 @@
{{hidden}}
{% endfor %}
<input name="keypair_id" type="hidden" value="{{keypair.name}}" />
<input id="delete_{{keypair.name}}" class="btn small danger" title="Keypair: {{keypair.name}}" type="submit" value="{% trans "Delete"%}" />
<input id="delete_{{keypair.name}}" class="btn small danger delete" title="Keypair: {{keypair.name}}" type="submit" value="{% trans "Delete"%}" />
</form>

View File

@@ -127,7 +127,7 @@ $(function(){
$(document).on("submit", ".modal #create_keypair_form", function(e){
var $this = $(this);
$this.closest(".modal").modal("hide");
$('#main_content').prepend('<div class="alert-message info">'
$('#main_content .page-header').after('<div class="alert-message info">'
+ '<p><strong>Info: </strong>The data on this page may have changed, '
+ '<a href=".">click here to refresh it</a>.</p>'
+ '</div>');