26 Commits

Author SHA1 Message Date
Jenkins
b333d66da8 Merge "Allow session to return an error response object" 2014-04-17 02:35:04 +00:00
Jamie Lennox
ce92f37f0b Rename HTTPError -> HttpError
With the move to the apiclient exceptions from oslo the basic HTTP error
class was renamed. This was not reflected in all places in the code.

It was also not picked up by the tests because the apiclient tests
weren't running due to a missing __init__.py file. Because this should
be backwards compatible it was added to the list in exceptions, the
check that this is available is in the (now running) apiclient tests.

Blueprint: common-client-library-2
Change-Id: I307c1083f29e3207cc86aa938043270e5c32b4bb
2014-04-15 09:38:20 +10:00
Jamie Lennox
4f1d25e489 Allow session to return an error response object
Typically we want to have exceptions thrown when dealing with requests
that return an HTTP error. However when looking at integrating the
session object with other clients it becomes apparent that the exception
handling is sufficiently different that it is best for now to let the
existing error handling work.

Add an option to return the failed request rather than raise an
exception so existing clients can do there own error handling.

Blueprint: session-propagation
DocImpact: New session parameter.
Change-Id: I63ea034e7c6eaaf42d4329526a902677a8dd709d
2014-04-14 09:38:14 +10:00
Jenkins
61322a3fee Merge "Allow passing auth plugin as a parameter" 2014-04-08 21:29:33 +00:00
Jamie Lennox
71e6486a3e Allow passing auth plugin as a parameter
This further separates the concept of session and auth plugin so that
the session can be a completely standalone transport layer.

This is similar to how requests handles things. You can install an auth
plugin on the session object and then everything that works through the
session will be authenticated or you can specify the auth plugin per
request and only authenticate that request.

Change-Id: If4ed5af831cc35e259d9f963062261819f08a9d5
2014-04-08 16:18:06 +10:00
Andrey Kurilin
61544f01d4 Reuse module exceptions from Oslo
The exception module in oslo common code and in keystoneclient are similar.
In case of unification openstack clients, we should use modules from Oslo.

Changes of this patch:
- imported exceptions from common code instead of `apiclient.exception`
- added aliases for exceptions which was renamed
(reason: backwards compatibility)
- moved exceptions `EmptyCatalog` from `apiclient.exception` to `exceptions`
- cleaned `apiclient.exception` from duplicated exceptions
- `apiclient.__init__` and `apiclient.exceptions` are kept and labeled as
'deprecated'(reason: backwards compatibility)

bp common-client-library-2

Change-Id: Iedf4e5d753d4278d81751ba0f55fdef3566b56de
2014-04-01 08:26:47 +03:00
Jenkins
93b08d8f01 Merge "Handle URLs via the session and auth_plugins" 2014-03-25 20:03:40 +00:00
Jamie Lennox
b07fbb91c6 Handle URLs via the session and auth_plugins
In the future clients will simply pass the service they expect to talk
to and the path. This will prevent every service trying to get their own
base urls from the service catalog individually.

This can later be extended to have the auth plugin actually contact the
URL from the service catalog which will let us have unversioned
endpoints in the catalog handled from a single location.

Change-Id: I80f0b5b1dbb45565fec09d1cb2c0552cfb9a72f5
blueprint: auth-plugin-endpoints
2014-03-25 12:32:23 -05:00
Jamie Lennox
0788f53fa1 Start using positional decorator
Apply the positional decorator to functions. It has been added as I
think best practice would dictate, though in some places it has been
added in a way that doesn't break existing tests.

Closes-Bug: #1295881
Change-Id: I4f7ddbede4cba4ab79d144ad1f9dc83ea76f204a
2014-03-25 14:28:23 +10:00
Jamie Lennox
6d1f907061 Don't use a connection pool unless provided
To prevent left over TCP connections from keystoneclient not correctly
cleaning up we shouldn't use a connection pool. This is not ideal but it
was a relatively new addition so shouldn't affect performance.

When we are able to find a long term solution to keystoneclient's other
problems we can move back to using a connection pool.

Change-Id: I45678ef89b88eea90ea04de1e3170f584b51fd8f
Closes-Bug: #1282089
2014-03-21 16:59:09 +10:00
Jamie Lennox
96b8e81b1d Create V2 Auth Plugins
Extract the authentication code from a v2 client and move it to a series
of auth plugins. Auth plugins each represent one method of
authenticating with a server and there is a factory method on the base
class to select the appropriate plugin from a group of arguments.

When a v2 client wants to do authentication it will create
a new v2 auth plugin, do the authentication and then take that result
for the client to use.

Change-Id: I4dd7474643ed5c2a3204ea2ec56029f926010c2c
blueprint: auth-plugins
2014-02-21 12:31:35 +10:00
Jenkins
ef69e08078 Merge "Remove vim header" 2014-02-13 03:43:31 +00:00
Jenkins
5b3342d570 Merge "Fix debug curl commands for included data" 2014-02-12 06:48:29 +00:00
Jenkins
c1adff769e Merge "Add back --insecure option to CURL debug" 2014-02-12 06:40:29 +00:00
Eric Guo
d6d0d66374 Remove vim header
We don't need vim modelines in each source file, it can be set in
user's vimrc.

Change-Id: Ic7a61430a0a320ce6b0c4518d9f5d988e35f8aae
Closes-Bug: #1229324
2014-02-08 22:22:08 +08:00
Jamie Lennox
96267731ec Create Authentication Plugins
Provides the framework for creating authentication plugins and using
them from a session object.

To allow this system to co-exist with the original client there is a bit
of a hack. The client object itself is now also an authentication
plugin, that supports the original client pattern. If a client is
created without a session object then that session object uses the
client as it's authentication plugin.

Change-Id: I682c8dcd3705148aaa804a91f4ed48a5b74bdc12
blueprint: auth-plugins
2014-02-04 14:29:15 +10:00
Jamie Lennox
06e3420dca Fix debug curl commands for included data
Include the submitted data in the curl debug statement.
Initially fixed in: https://review.openstack.org/#/c/53501

Change-Id: I4e3e9e4799a508666fb37fafe864eea25b676836
Closes-Bug: #1249891
2014-02-04 02:05:30 +00:00
Jamie Lennox
d4edb09639 Add back --insecure option to CURL debug
This was added in review: https://review.openstack.org/#/c/53500 but
lost in the conversion to using session. Add it back again.

Change-Id: Ia063eb018d3a7da706a02d60df63bfa1be21d147
Related-Bug: #1249891
2014-02-04 12:04:20 +10:00
Jamie Lennox
1263bd7c3a Provide a conversion function for creating session
Session.construct will create a session based upon the kwargs that used
to be passed to a client __init__ function. This will allow clients an
easy path to providing compatibility with deprecated arguments.

Make use of the function throughout discovery. Discovery was initially
released prior to the session object being completed and was therefore
handled with the same arguments as a client. Instead we should use a
session object so use the conversion function to convert those kwargs
into a session object if one is not provided.

Change-Id: I8dc1e0810ea6ebc6ea648ec37d7881825c566676
2014-02-03 13:42:53 +10:00
Eric Guo
252b6e423d Adjust import items according to hacking import rule
This patch adjust import items and add missing blank lines acording
to http://docs.openstack.org/developer/hacking/#imports
{{stdlib imports in human alphabetical order}}
\n
{{third-party lib imports in human alphabetical order}}
\n
{{project imports in human alphabetical order}}
\n
\n
{{begin your code}}

hacking project also enforce some checks for import group.
Let make the change in keytoneclient

Change-Id: Ic83bd5ee426905588f4a2d555851a9a01fc69f02
2014-01-17 23:21:38 +08:00
Jenkins
5fe86af4fa Merge "Saner debug log message generation" 2014-01-15 18:38:25 +00:00
Jamie Lennox
e2a5c2a829 Saner debug log message generation
For some reason building the debug log would include spaces in the
message elements and join on the empty string. It makes much more sense
to just build the list and join on the space.

Change-Id: Idd82787b87518c56122d0b13551f84529306337c
2014-01-09 01:11:42 +00:00
Jamie Lennox
165da791af Controllable redirect handling
The requests library handles redirects as a browser would, which has the problem
that forwarding a POST will convert it to a GET. This is not necessarily
intuitive for an API. Handle all redirection manually and provide some
control over how far redirection can go.

Closes-Bug: 1267286
Change-Id: I24596a9c39cc29db28a66c3053ef3954b33abf90
2014-01-09 10:20:08 +10:00
Jamie Lennox
6728bf3ccb Move redirect handling to session
Particularly 305 is expected to be handled by the tests so we need to
handle this centrally if we want to have session and non-session clients
to work the same way.

Change-Id: Id4ec35ddd8b8304d24df9e6cd2ab995d123ef125
2013-12-20 03:51:50 +00:00
Jamie Lennox
a8adb476f7 Remove debug specific handling
I think debug handling was initially done this way for CLI handling
where we wanted to make sure only the correct information was printed to
the console. However as logging.basicConfig sets up a stream handler on
the root logging object I can't see any purpose to the debug handling in
the actual HTTPClient. Further than this it is completely wrong that a
client library is messing with it's logging level, this should be handled
by an application.

The debug flag is maintained and deprecated in HTTPClient and removed
from the session object. There has been no release since the addition of
session so there is no problem with compatibility.

Change-Id: Ib00f3d93d099ed1a9dd25f17121610a7289f0061
2013-12-20 13:48:06 +10:00
Jamie Lennox
2c5dcf9bf1 Extract a base Session object
A wrapper around a number of connection variables. This will be extended
later with principals such as Kerberos authentication and http sessions.

The intent is that this session object will become the basis for all
other client library communications in OpenStack (as keystone wants to
control things like authentication for everybody).

Change-Id: I8ee728c49d554659d7057ebf17d0f8ceea4d7d8e
Part of: blueprint auth-plugins
2013-11-28 09:20:43 +10:00