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,6 +280,7 @@ 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)
if cert:
return dict( return dict(
body=cert["CertificateBody"], body=cert["CertificateBody"],
chain=cert.get("CertificateChain"), chain=cert.get("CertificateChain"),