Fixing destination upload. (#347)

* Fixing an issue where uploaded certificates would have a name of 'None'

* Clarifying comment.

* Improving order.
This commit is contained in:
kevgliss 2016-06-03 18:45:58 -07:00
parent 5e987fa8b6
commit d9cc4980e8
2 changed files with 13 additions and 14 deletions

View File

@ -75,6 +75,19 @@ class Certificate(db.Model):
def __init__(self, **kwargs):
cert = defaults.parse_certificate(kwargs['body'])
self.issuer = defaults.issuer(cert)
self.cn = defaults.common_name(cert)
self.san = defaults.san(cert)
self.not_before = defaults.not_before(cert)
self.not_after = defaults.not_after(cert)
# when destinations are appended they require a valid name.
if kwargs.get('name'):
self.name = kwargs['name']
else:
self.name = get_or_increase_name(defaults.certificate_name(self.cn, self.issuer, self.not_before, self.not_after, self.san))
self.owner = kwargs['owner']
self.body = kwargs['body']
self.private_key = kwargs.get('private_key')
@ -86,13 +99,7 @@ class Certificate(db.Model):
self.replaces = kwargs.get('replacements', [])
self.signing_algorithm = defaults.signing_algorithm(cert)
self.bits = defaults.bitstrength(cert)
self.issuer = defaults.issuer(cert)
self.serial = defaults.serial(cert)
self.cn = defaults.common_name(cert)
self.san = defaults.san(cert)
self.not_before = defaults.not_before(cert)
self.not_after = defaults.not_after(cert)
self.name = get_or_increase_name(defaults.certificate_name(self.cn, self.issuer, self.not_before, self.not_after, self.san))
for domain in defaults.domains(cert):
self.domains.append(Domain(name=domain))

View File

@ -186,10 +186,6 @@ def upload(**kwargs):
cert = Certificate(**kwargs)
# we override the generated name if one is provided
if kwargs.get('name'):
cert.name = kwargs['name']
cert = database.create(cert)
g.user.certificates.append(cert)
@ -216,10 +212,6 @@ def create(**kwargs):
cert = Certificate(**kwargs)
# we override the generated name if one is provided
if kwargs.get('name'):
cert.name = kwargs['name']
g.user.certificates.append(cert)
cert.authority = kwargs['authority']
database.commit()