import re


def _patch_heroku(name, aliases):
    """
    Heroku will resolve its host to a name which fails SSL validation. Find a
    preferable name from the aliases.
    """
    if name.endswith('.route.herokuapp.com'):
        matches = filter(re.compile(r'[^.]*\.herokuapp\.com').match, aliases)
        name = next(matches, name)
    return name