Skip to content

Commit

Permalink
Keypair bugfixes.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gabrielhurley committed Dec 9, 2011
1 parent 9e84bae commit 75bff69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions horizon/horizon/dashboards/nova/keypairs/forms.py
Expand Up @@ -24,6 +24,7 @@
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
Expand Down Expand Up @@ -53,17 +54,22 @@ def handle(self, request, data):

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:
LOG.info('Creating keypair "%s"' % data['name'])
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")
Expand Down
Expand Up @@ -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>
Expand Up @@ -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>');
Expand Down

0 comments on commit 75bff69

Please sign in to comment.