def get_user(ks_admin, username):
    """Fetch a user from Keystone by username.

    The user is fetched from the domain of the user the Keystone client is
    scoped to, which is typically the 'default' domain, but can be changed
    by passing a different client.

    Args:
        ks_admin (keystone.Client): the Keystone client, which must have admin
            privileges to perform the lookup.
        username (str): the username to lookup

    Returns:
        keystone.User: the Keystone user found for the username, or None
    """
    domain_id = ks_admin.user_domain_id
    return next(iter(
        ks_admin.users.list(name=username, domain=domain_id)), None)