capturing no such entity exception.

This commit is contained in:
Hossein Shafagh 2019-10-18 10:17:58 -07:00
parent 8aea257e6a
commit 1768aad9e2
2 changed files with 12 additions and 9 deletions

View File

@ -10,7 +10,7 @@ import botocore
from retrying import retry from retrying import retry
from lemur.extensions import metrics from lemur.extensions import metrics, sentry
from lemur.plugins.lemur_aws.sts import sts_client from lemur.plugins.lemur_aws.sts import sts_client
@ -122,9 +122,11 @@ def get_certificate(name, **kwargs):
""" """
client = kwargs.pop("client") client = kwargs.pop("client")
metrics.send("get_certificate", "counter", 1, metric_tags={"name": name}) metrics.send("get_certificate", "counter", 1, metric_tags={"name": name})
return client.get_server_certificate(ServerCertificateName=name)[ try:
"ServerCertificate" return client.get_server_certificate(ServerCertificateName=name)["ServerCertificate"]
] except client.exceptions.NoSuchEntityException:
sentry.captureException()
return None
@sts_client("iam") @sts_client("iam")

View File

@ -280,11 +280,12 @@ class AWSSourcePlugin(SourcePlugin):
certificate_name = certificate_name.split('/')[1] certificate_name = certificate_name.split('/')[1]
try: try:
cert = iam.get_certificate(certificate_name, account_number=account_number) cert = iam.get_certificate(certificate_name, account_number=account_number)
return dict( if cert:
body=cert["CertificateBody"], return dict(
chain=cert.get("CertificateChain"), body=cert["CertificateBody"],
name=cert["ServerCertificateMetadata"]["ServerCertificateName"], chain=cert.get("CertificateChain"),
) name=cert["ServerCertificateMetadata"]["ServerCertificateName"],
)
except ClientError: except ClientError:
current_app.logger.warning( current_app.logger.warning(
"get_elb_certificate_failed: Unable to get certificate for {0}".format(certificate_name)) "get_elb_certificate_failed: Unable to get certificate for {0}".format(certificate_name))