diff --git a/lemur/plugins/lemur_entrust/plugin.py b/lemur/plugins/lemur_entrust/plugin.py index d1f4a301..b1ba723d 100644 --- a/lemur/plugins/lemur_entrust/plugin.py +++ b/lemur/plugins/lemur_entrust/plugin.py @@ -3,10 +3,8 @@ import arrow import requests import json from lemur.plugins import lemur_entrust as ENTRUST -from OpenSSL import crypto from flask import current_app -from lemur.extensions import metrics, sentry - +from lemur.extensions import metrics def log_status_code(r, *args, **kwargs): @@ -20,6 +18,7 @@ def log_status_code(r, *args, **kwargs): """ metrics.send("ENTRUST_status_code_{}".format(r.status_code), "counter", 1) + def process_options(options): """ Processes and maps the incoming issuer options to fields/options that @@ -28,13 +27,13 @@ def process_options(options): :param options: :return: dict of valid entrust options """ - # if there is a config variable ENTRUST_PRODUCT_ + # if there is a config variable ENTRUST_PRODUCT_ # take the value as Cert product-type # else default to "STANDARD_SSL" authority = options.get("authority").name.upper() product_type = current_app.config.get("ENTRUST_PRODUCT_{0}".format(authority), "STANDARD_SSL") expiry_date = arrow.utcnow().shift(years=1, days=+10).format('YYYY-MM-DD') - + tracking_data = { "requesterName": current_app.config.get("ENTRUST_NAME"), "requesterEmail": current_app.config.get("ENTRUST_EMAIL"), @@ -44,12 +43,13 @@ def process_options(options): data = { "signingAlg": "SHA-2", "eku": "SERVER_AND_CLIENT_AUTH", - "certType": product_type, - "certExpiryDate" : expiry_date, + "certType": product_type, + "certExpiryDate": expiry_date, "tracking": tracking_data } return data + class EntrustIssuerPlugin(IssuerPlugin): title = "ENTRUST" slug = "entrust-issuer" @@ -67,7 +67,7 @@ class EntrustIssuerPlugin(IssuerPlugin): user = current_app.config.get("ENTRUST_API_USER") passw = current_app.config.get("ENTRUST_API_PASS") self.session.cert = (cert_file_path, key_file_path) - self.session.auth = (user,passw) + self.session.auth = (user, passw) self.session.hooks = dict(response=log_status_code) # self.session.config['keep_alive'] = False super(EntrustIssuerPlugin, self).__init__(*args, **kwargs) @@ -93,13 +93,12 @@ class EntrustIssuerPlugin(IssuerPlugin): "Entrust-Request Data (id: {1}) : {0}".format(data, current_req) ) - try: - response = self.session.post(url, json=data, timeout=(15, 40)) + response = self.session.post(url, json=data, timeout=(15, 40)) except requests.exceptions.Timeout: - raise Exception("Timeout Error while posting to ENTRUST (ID: {0})".format(current_req)) + raise Exception("Timeout Error while posting to ENTRUST (ID: {0})".format(current_req)) except requests.exceptions.RequestException as e: - raise Exception("Error while posting to ENTRUST (ID: {1}): {0}".format(e,current_req)) + raise Exception("Error while posting to ENTRUST (ID: {1}): {0}".format(e, current_req)) current_app.logger.info( "After Post and Errorhandling (ID: {1}) : {0}".format(response.status_code, current_req) @@ -107,7 +106,7 @@ class EntrustIssuerPlugin(IssuerPlugin): response_dict = json.loads(response.content) if response.status_code != 201: - raise Exception("Error with ENTRUST (ID: {1}): {0}".format(response_dict['errors'], current_req)) + raise Exception("Error with ENTRUST (ID: {1}): {0}".format(response_dict['errors'], current_req)) current_app.logger.info("Response: {0}, {1} ".format(response.status_code, response_dict)) external_id = response_dict['trackingId'] cert = response_dict['endEntityCert'] @@ -116,7 +115,7 @@ class EntrustIssuerPlugin(IssuerPlugin): "Received Chain: {0}".format(chain) ) - return cert, chain, external_id + return cert, chain, external_id @staticmethod def create_authority(options): @@ -132,8 +131,7 @@ class EntrustIssuerPlugin(IssuerPlugin): entrust_issuing = current_app.config.get("ENTRUST_ISSUING") role = {"username": "", "password": "", "name": "entrust"} current_app.logger.info("Creating Auth: {0} {1}".format(options, entrust_issuing)) - return entrust_root, "" , [role] - + return entrust_root, "", [role] def revoke_certificate(self, certificate, comments): raise NotImplementedError("Not implemented\n", self, certificate, comments) @@ -164,9 +162,9 @@ class EntrustSourcePlugin(SourcePlugin): ] def get_certificates(self, options, **kwargs): - #Not needed for ENTRUST - raise NotImplementedError("Not implemented\n", self, options, **kwargs) + # Not needed for ENTRUST + raise NotImplementedError("Not implemented\n", self, options, **kwargs + def get_endpoints(self, options, **kwargs): # There are no endpoints in ENTRUST raise NotImplementedError("Not implemented\n", self, options, **kwargs) -