Commit 622b88b4 by Scott Duckworth

populate key name from comment if it exists

parent dbc86dcb
from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from sshkey.util import sshkey_fingerprint
from sshkey.util import sshkey_fingerprint, sshkey_re
class UserKey(models.Model):
user = models.ForeignKey(User, db_index=True)
name = models.CharField(max_length=50)
name = models.CharField(max_length=50, blank=True)
key = models.TextField(max_length=2000)
fingerprint = models.CharField(max_length=47, blank=True, db_index=True)
......@@ -28,6 +28,12 @@ class UserKey(models.Model):
self.fingerprint = sshkey_fingerprint(self.key)
except Exception, e:
raise ValidationError('Not a valid SSH key: ' + str(e))
if not
m = sshkey_re.match(self.key)
comment ='comment')
if not comment:
raise ValidationError('Name or key comment required') = comment
def validate_unique(self, exclude=None):
if is None:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment