def automatically_enable_autorotate_with_destination():
    """
    This function automatically enables auto-rotation for unexpired certificates that are
    attached to a destination but do not have autorotate enabled.

    WARNING: This will overwrite the Auto-rotate toggle!
    """
    log_data = {
        "function": f"{__name__}.{sys._getframe().f_code.co_name}",
        "message": "Enabling auto-rotate for certificate"
    }
    no_authority_restrictions = current_app.config.get("ENABLE_AUTO_ROTATE_ALL_AUTHORITIES", False)
    permitted_authorities = current_app.config.get("ENABLE_AUTO_ROTATE_AUTHORITY", [])
    destination_plugin_name = current_app.config.get("ENABLE_AUTO_ROTATE_DESTINATION_TYPE", None)

    eligible_certs = get_all_certs_attached_to_destination_without_autorotate(plugin_name=destination_plugin_name)
    for cert in eligible_certs:

        if not no_authority_restrictions and cert.authority_id not in permitted_authorities:
            continue

        log_data["certificate"] = cert.name
        log_data["certificate_id"] = cert.id
        log_data["authority_id"] = cert.authority_id
        log_data["authority_name"] = authorities_get_by_id(cert.authority_id).name
        if cert.destinations:
            log_data["destination_names"] = ', '.join([d.label for d in cert.destinations])
        else:
            log_data["destination_names"] = "NONE"
        current_app.logger.info(log_data)
        metrics.send("automatically_enable_autorotate_with_destination",
                     "counter", 1,
                     metric_tags={"certificate": log_data["certificate"],
                                  "certificate_id": log_data["certificate_id"],
                                  "authority_id": log_data["authority_id"],
                                  "authority_name": log_data["authority_name"],
                                  "destination_names": log_data["destination_names"]
                                  })
        cert.rotation = True
        database.update(cert)

    This function automatically enables auto-rotation for unexpired certificates that are
    attached to a destination but do not have autorotate enabled.

    WARNING: This will overwrite the Auto-rotate toggle!
    
lemur/certificates/cli.py