From dc34652efda28a121967b571e53c72680ec2fa59 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Fri, 6 Oct 2017 08:49:05 -0700 Subject: [PATCH] Source plugin (#962) * Ensuring that we have default options for source plugins. * Handle duplicate serials. Serials are not unique across issuers. --- lemur/certificates/service.py | 2 +- lemur/sources/service.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py index b4b233f1..dc56876a 100644 --- a/lemur/certificates/service.py +++ b/lemur/certificates/service.py @@ -63,7 +63,7 @@ def get_by_serial(serial): :param serial: :return: """ - return database.get(Certificate, serial, field='serial') + return Certificate.filter(Certificate.serial == serial).all() def delete(cert_id): diff --git a/lemur/sources/service.py b/lemur/sources/service.py index 01121374..9d140049 100644 --- a/lemur/sources/service.py +++ b/lemur/sources/service.py @@ -115,7 +115,7 @@ def sync_certificates(source, user): for certificate in certificates: if certificate.get('name'): - exists = certificate_service.get_by_name(certificate['name']) + exists = [certificate_service.get_by_name(certificate['name'])] elif certificate.get('serial'): exists = certificate_service.get_by_serial(certificate['serial']) @@ -134,10 +134,11 @@ def sync_certificates(source, user): new += 1 else: - if certificate.get('external_id'): - exists.external_id = certificate['external_id'] - certificate_update(exists, source) - updated += 1 + for e in exists: + if certificate.get('external_id'): + exists.external_id = certificate['external_id'] + certificate_update(e, source) + updated += 1 assert len(certificates) == new + updated