import requests


def generic_request(method, url, **kwargs):
    """An alias for requests.request with handling of keystone authentication tokens.

    :param method: The HTTP method of the request
    :param url: The url to request
    :param **kwargs: The keyword arguments defined below as well
        as any additional arguments to be passed to the
        requests.request call
    :return: A request for the given url

    :Keyword Arguments:
        * token:
            A token to be put into the X-Auth-Token header of the request
    """

    auth_token = kwargs.pop('token', None)
    if auth_token:
        headers = kwargs.pop('headers', {})
        headers['X-Auth-Token'] = auth_token
        kwargs['headers'] = headers

    return requests.request(method, url, **kwargs)