def prepare_request(auth_opts=None, data=None, **kwargs):
    """Prepares a request

    This method takes care of authentication
    and all other steps in the preparation chain.

    The request returned by this call is ready to
    be sent to the server.

    :param auth_opts: Auth parameters
    :type auth_opts: `dict`
    :param data: Optional data to send along with the
        request. If data is not None, it'll be serialized.
    :type data: Any primitive type that is json-serializable.
    :param kwargs: Anything accepted by `Request`

    :returns: A `Request` instance ready to be sent.
    :rtype: `Request`
    """

    req = Request(**kwargs)
    auth_backend = auth.get_backend(**(auth_opts or {}))
    # TODO(flaper87): Do something smarter
    # to get the api_version.
    req = auth_backend.authenticate(1, req)
    req.headers['X-Project-Id'] = auth_opts.get('options',
                                                {}).get('os_project_id')

    if data is not None:
        req.content = json.dumps(data)
    return req
Пример #2
0
    def setUp(self):
        super(TestKeystoneAuth, self).setUp()

        if not ksclient:
            self.skipTest('Keystone client is not installed')

        self.auth = auth.get_backend(backend='keystone', options=self.conf)
Пример #3
0
def prepare_request(auth_opts=None, data=None, **kwargs):
    """Prepares a request

    This method takes care of authentication
    and all other steps in the preparation chain.

    The request returned by this call is ready to
    be sent to the server.

    :param auth_opts: Auth parameters
    :type auth_opts: `dict`
    :param data: Optional data to send along with the
        request. If data is not None, it'll be serialized.
    :type data: Any primitive type that is json-serializable.
    :param kwargs: Anything accepted by `Request`

    :returns: A `Request` instance ready to be sent.
    :rtype: `Request`
    """

    req = Request(**kwargs)
    auth_backend = auth.get_backend(**(auth_opts or {}))
    # TODO(flaper87): Do something smarter
    # to get the api_version.
    req = auth_backend.authenticate(1, req)

    req.headers['X-Project-Id'] = auth_opts.get('options',
                                                {}).get('os_project_id')

    if data is not None:
        req.content = json.dumps(data)
    return req
Пример #4
0
    def setUp(self):
        super(TestKeystoneAuth, self).setUp()

        if not ksclient:
            self.skipTest('Keystone client is not installed')

        self.auth = auth.get_backend(backend='keystone',
                                     options=self.conf)
Пример #5
0
def prepare_request(auth_opts=None, data=None, **kwargs):
    """Prepares a request

    This method takes care of authentication
    and all other steps in the preparation chain.

    The request returned by this call is ready to
    be sent to the server.

    :param auth_opts: Auth parameters
    :type auth_opts: `dict`
    :param data: Optional data to send along with the
        request. If data is not None, it'll be serialized.
    :type data: Any primitive type that is json-serializable.
    :param kwargs: Anything accepted by `Request`

    :returns: A `Request` instance ready to be sent.
    :rtype: `Request`
    """

    req = Request(**kwargs)
    auth_backend = auth.get_backend(**(auth_opts or {}))
    req = auth_backend.authenticate(kwargs.get('api'), req)

    option = auth_opts.get('options', {})
    # TODO(wangxiyuan): To keep backwards compatibility, we leave
    # "os_project_id" here. Remove it in the next release.
    project_id = option.get('os_project_id', option.get('project_id'))

    # Let's add project id header, only if it will have non-empty value.
    if project_id:
        req.headers['X-Project-Id'] = project_id

    # In case of noauth backend and no specified project id, the default
    # project id will be added as header.
    if ('X-Project-Id' not in req.headers and
            auth_opts.get("backend") == "noauth"):
        req.headers['X-Project-Id'] = "fake_project_id_for_noauth"

    if data is not None:
        req.content = json.dumps(data)
    return req
Пример #6
0
def prepare_request(auth_opts=None, data=None, **kwargs):
    """Prepares a request

    This method takes care of authentication
    and all other steps in the preparation chain.

    The request returned by this call is ready to
    be sent to the server.

    :param auth_opts: Auth parameters
    :type auth_opts: `dict`
    :param data: Optional data to send along with the
        request. If data is not None, it'll be serialized.
    :type data: Any primitive type that is json-serializable.
    :param kwargs: Anything accepted by `Request`

    :returns: A `Request` instance ready to be sent.
    :rtype: `Request`
    """

    req = Request(**kwargs)
    auth_backend = auth.get_backend(**(auth_opts or {}))
    req = auth_backend.authenticate(kwargs.get('api'), req)

    option = auth_opts.get('options', {})
    # TODO(wangxiyuan): To keep backwards compatibility, we leave
    # "os_project_id" here. Remove it in the next release.
    project_id = option.get('os_project_id', option.get('project_id'))

    # Let's add project id header, only if it will have non-empty value.
    if project_id:
        req.headers['X-Project-Id'] = project_id

    # In case of noauth backend and no specified project id, the default
    # project id will be added as header.
    if ('X-Project-Id' not in req.headers
            and auth_opts.get("backend") == "noauth"):
        req.headers['X-Project-Id'] = "fake_project_id_for_noauth"

    if data is not None:
        req.content = json.dumps(data)
    return req
Пример #7
0
    def setUp(self):
        super(TestKeystoneAuth, self).setUp()

        self.auth = auth.get_backend(options=self.conf)
    def setUp(self):
        super(TestKeystoneAuth, self).setUp()

        self.auth = auth.get_backend(options=self.conf)
Пример #9
0
 def test_get_non_existing_backend(self):
     try:
         auth.get_backend('not_existing')
         self.fail("Test failed")
     except KeyError:
         pass
Пример #10
0
 def test_get_backend(self):
     try:
         auth.get_backend(options=self.conf)
     except KeyError:
         self.fail("Test failed")
Пример #11
0
 def test_get_non_existing_backend(self):
     try:
         auth.get_backend('not_existing')
         self.fail("Test failed")
     except KeyError:
         pass
Пример #12
0
 def test_get_backend(self):
     try:
         auth.get_backend(options=self.conf)
     except KeyError:
         self.fail("Test failed")