From 33bb17779d71c387133562d6b74ac826ab4d9e37 Mon Sep 17 00:00:00 2001 From: sayali Date: Wed, 2 Dec 2020 18:07:36 -0800 Subject: [PATCH] Handle revoke not implemented and add comments --- lemur/certificates/views.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lemur/certificates/views.py b/lemur/certificates/views.py index da6c426b..c72702fe 100644 --- a/lemur/certificates/views.py +++ b/lemur/certificates/views.py @@ -1413,6 +1413,11 @@ class CertificateRevoke(AuthenticatedResource): Host: example.com Accept: application/json, text/javascript + { + "crlReason": "affiliationChanged", + "comments": "Additional details if any" + } + **Example response**: .. sourcecode:: http @@ -1422,12 +1427,13 @@ class CertificateRevoke(AuthenticatedResource): Content-Type: text/javascript { - 'id': 1 + "id": 1 } :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error - :statuscode 403: unauthenticated + :statuscode 403: unauthenticated or cert attached to LB + :statuscode 400: encountered error, more details in error message """ cert = service.get(certificate_id) @@ -1459,13 +1465,18 @@ class CertificateRevoke(AuthenticatedResource): 403, ) - error_message = service.revoke(cert, data) - log_service.create(g.current_user, "revoke_cert", certificate=cert) - - if error_message: - return dict(message=f"Certificate (id:{cert.id}) is revoked - {error_message}"), 400 - return dict(id=cert.id) + try: + error_message = service.revoke(cert, data) + log_service.create(g.current_user, "revoke_cert", certificate=cert) + if error_message: + return dict(message=f"Certificate (id:{cert.id}) is revoked - {error_message}"), 400 + return dict(id=cert.id) + except NotImplementedError as ne: + return dict(message=f"Revoke is not implemented for issuer of this certificate"), 400 + except Exception as e: + sentry.captureException() + return dict(message=f"Failed to revoke: {str(e)}"), 400 api.add_resource( CertificateRevoke,