diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..6bd9f176 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# These owners will be the default owners for everything in the repo. +* @hosseinsh @csine-nflx @charhate @jtschladen diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py index b4f88923..986a8e31 100644 --- a/lemur/certificates/service.py +++ b/lemur/certificates/service.py @@ -679,7 +679,16 @@ def stats(**kwargs): :param kwargs: :return: """ - if kwargs.get("metric") == "not_after": + + # Verify requested metric + allow_list = ["bits", "issuer", "not_after", "signing_algorithm"] + req_metric = kwargs.get("metric") + if req_metric not in allow_list: + raise Exception( + f"Stats not available for requested metric: {req_metric}" + ) + + if req_metric == "not_after": start = arrow.utcnow() end = start.shift(weeks=+32) items = ( @@ -691,7 +700,7 @@ def stats(**kwargs): ) else: - attr = getattr(Certificate, kwargs.get("metric")) + attr = getattr(Certificate, req_metric) query = database.db.session.query(attr, func.count(attr)) items = query.group_by(attr).all() diff --git a/lemur/certificates/views.py b/lemur/certificates/views.py index 99775332..941eba0f 100644 --- a/lemur/certificates/views.py +++ b/lemur/certificates/views.py @@ -635,7 +635,12 @@ class CertificatesStats(AuthenticatedResource): args = self.reqparse.parse_args() - items = service.stats(**args) + try: + items = service.stats(**args) + except Exception as e: + sentry.captureException() + return dict(message=f"Failed to retrieve stats: {str(e)}"), 400 + return dict(items=items, total=len(items)) diff --git a/lemur/destinations/views.py b/lemur/destinations/views.py index 6de6f74f..2c89da76 100644 --- a/lemur/destinations/views.py +++ b/lemur/destinations/views.py @@ -425,7 +425,7 @@ class CertificateDestinations(AuthenticatedResource): class DestinationsStats(AuthenticatedResource): - """ Defines the 'certificates' stats endpoint """ + """ Defines the 'destinations' stats endpoint """ def __init__(self): self.reqparse = reqparse.RequestParser()