Source plugin (#962)

* Ensuring that we have default options for source plugins.

* Handle duplicate serials. Serials are not unique across issuers.
This commit is contained in:
kevgliss 2017-10-06 08:49:05 -07:00 committed by GitHub
parent e0d2fb0de1
commit dc34652efd
2 changed files with 7 additions and 6 deletions

View File

@ -63,7 +63,7 @@ def get_by_serial(serial):
:param serial: :param serial:
:return: :return:
""" """
return database.get(Certificate, serial, field='serial') return Certificate.filter(Certificate.serial == serial).all()
def delete(cert_id): def delete(cert_id):

View File

@ -115,7 +115,7 @@ def sync_certificates(source, user):
for certificate in certificates: for certificate in certificates:
if certificate.get('name'): if certificate.get('name'):
exists = certificate_service.get_by_name(certificate['name']) exists = [certificate_service.get_by_name(certificate['name'])]
elif certificate.get('serial'): elif certificate.get('serial'):
exists = certificate_service.get_by_serial(certificate['serial']) exists = certificate_service.get_by_serial(certificate['serial'])
@ -134,10 +134,11 @@ def sync_certificates(source, user):
new += 1 new += 1
else: else:
if certificate.get('external_id'): for e in exists:
exists.external_id = certificate['external_id'] if certificate.get('external_id'):
certificate_update(exists, source) exists.external_id = certificate['external_id']
updated += 1 certificate_update(e, source)
updated += 1
assert len(certificates) == new + updated assert len(certificates) == new + updated