def get_postgres_user(users, host, port, database):
    """
    For a list of host/port/database/user combinations, return the username that matches the
    host, port, database and user.

    :param users: list containing a sequence of AT LEAST (host, port, database, username)
    :param host: The hostname to match
    :param port: The port to match
    :param database: The database to match
    :return: A username or None
    """
    for user in users:
        if user[0].lower() == host.lower() and user[1].lower() == port.lower(
            ) and user[2].lower() == database.lower():
            return user[3]
    return None
