def list_recent_valid_certs_issued_by_authority(authority_ids, days_since_issuance):
    """
    Find certificates issued by given authorities in last days_since_issuance number of days, that are still valid,
    not replaced, have auto-rotation ON.

    :param authority_ids: list of authority ids
    :param days_since_issuance: If not none, include certificates issued in only last days_since_issuance days
    :return: List of certificates matching the criteria
    """

    now = arrow.now().format("YYYY-MM-DD")
    query = database.session_query(Certificate)\
        .filter(Certificate.authority_id.in_(authority_ids))\
        .filter(Certificate.not_after >= now)\
        .filter(Certificate.rotation == true())\
        .filter(not_(Certificate.replaced.any()))

    if days_since_issuance:
        issuance_window = (
            arrow.now().shift(days=-days_since_issuance).format("YYYY-MM-DD")
        )
        query = query.filter(Certificate.date_created >= issuance_window)

    return query.all()

    Find certificates issued by given authorities in last days_since_issuance number of days, that are still valid,
    not replaced, have auto-rotation ON.

    :param authority_ids: list of authority ids
    :param days_since_issuance: If not none, include certificates issued in only last days_since_issuance days
    :return: List of certificates matching the criteria
    
lemur/certificates/service.py