def get_eligible_authority_certificates():
    """
    Finds all certificate authority certificates that are eligible for certificate expiration notification.
    Returns the set of all eligible CA certificates, grouped by owner and interval, with a list of applicable certs.
    :return:
    """
    certificates = defaultdict(dict)
    all_certs = get_expiring_authority_certificates()
    now = arrow.utcnow()

    # group by owner
    for owner, owner_certs in groupby(sorted(all_certs, key=lambda x: x.owner), lambda x: x.owner):
        # group by expiration interval
        for interval, interval_certs in groupby(sorted(owner_certs, key=lambda x: (x.not_after - now).days),
                                                lambda x: (x.not_after - now).days):
            certificates[owner][interval] = list(interval_certs)

    return certificates

    Finds all certificate authority certificates that are eligible for certificate expiration notification.
    Returns the set of all eligible CA certificates, grouped by owner and interval, with a list of applicable certs.
    :return:
    
lemur/notifications/messaging.py