From fc957b63ffd94813cac4cc699565b67fb6e58900 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Fri, 3 Mar 2017 14:53:56 -0800 Subject: [PATCH] Source syncing tweaks. (#705) * Allow owner to be specified when syncing certs. * Ensuring non-endpoint plugins don't fail to complete syncing. * Adding in some additional error handling. --- lemur/certificates/schemas.py | 2 +- lemur/common/defaults.py | 2 +- lemur/common/validators.py | 3 ++- lemur/sources/service.py | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lemur/certificates/schemas.py b/lemur/certificates/schemas.py index cc037992..5a5e2985 100644 --- a/lemur/certificates/schemas.py +++ b/lemur/certificates/schemas.py @@ -205,7 +205,7 @@ class CertificateUploadInputSchema(CertificateCreationSchema): private_key = fields.String(validate=validators.private_key) body = fields.String(required=True, validate=validators.public_certificate) - chain = fields.String(validate=validators.public_certificate, missing=None) # TODO this could be multiple certificates + chain = fields.String(validate=validators.public_certificate, missing=None, allow_none=True) # TODO this could be multiple certificates destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True) notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True) diff --git a/lemur/common/defaults.py b/lemur/common/defaults.py index 764071e0..bdee6563 100644 --- a/lemur/common/defaults.py +++ b/lemur/common/defaults.py @@ -147,7 +147,7 @@ def domains(cert): for entry in entries: domains.append(entry) except Exception as e: - current_app.logger.warning("Failed to get SubjectAltName: {0}".format(e)) + pass return domains diff --git a/lemur/common/validators.py b/lemur/common/validators.py index ea107fc8..0c5c5266 100644 --- a/lemur/common/validators.py +++ b/lemur/common/validators.py @@ -20,7 +20,8 @@ def public_certificate(body): """ try: parse_certificate(body) - except Exception: + except Exception as e: + current_app.logger.exception(e) raise ValidationError('Public certificate presented is not valid.') diff --git a/lemur/sources/service.py b/lemur/sources/service.py index 12a3fdeb..23cccf43 100644 --- a/lemur/sources/service.py +++ b/lemur/sources/service.py @@ -67,7 +67,7 @@ def sync_endpoints(source): endpoints = s.get_endpoints(source.options) except NotImplementedError: current_app.logger.warning("Unable to sync endpoints for source {0} plugin has not implemented 'get_endpoints'".format(source.label)) - return + return new, updated for endpoint in endpoints: exists = endpoint_service.get_by_dnsname(endpoint['dnsname']) @@ -114,7 +114,9 @@ def sync_certificates(source, user): for certificate in certificates: exists = certificate_service.get_by_name(certificate['name']) - certificate['owner'] = user.email + if not certificate.get('owner'): + certificate['owner'] = user.email + certificate['creator'] = user if not exists: