@classmethod
def get_latest_valid(cls, hosts):
    """ Retrieve valid certificates by fqdn. """
    certs = cls.list({'status': 'valid', 'items_per_page': 500})
    possible = None
    if not isinstance(hosts, (tuple, list)):
        hosts = [hosts]
    for cert in certs:
        cert_hosts = set([cert['cn']] + cert['altnames'])
        if len(set(hosts) - cert_hosts) == 0:
            if possible and possible['date_end'] < cert['date_end'
                ] or not possible:
                possible = cert
    return possible
