summaryrefslogtreecommitdiff
path: root/keystoneclient/discover.py
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@redhat.com>2013-12-11 07:38:46 +1000
committerJamie Lennox <jamielennox@redhat.com>2014-02-03 13:42:53 +1000
commit1263bd7c3a8ccded3cef7c799a2f8c744fb79aa2 (patch)
treea7c5a2a16174e2233246984c8d98afd518361cb6 /keystoneclient/discover.py
parent456afa153d0fd831686a50c19cc195da2820a6dd (diff)
downloadpython-keystoneclient-1263bd7c3a8ccded3cef7c799a2f8c744fb79aa2.tar.gz
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
Diffstat (limited to 'keystoneclient/discover.py')
-rw-r--r--keystoneclient/discover.py67
1 files changed, 48 insertions, 19 deletions
diff --git a/keystoneclient/discover.py b/keystoneclient/discover.py
index e794321..3cbb5e0 100644
--- a/keystoneclient/discover.py
+++ b/keystoneclient/discover.py
@@ -17,7 +17,7 @@ import logging
import six
from keystoneclient import exceptions
-from keystoneclient import httpclient
+from keystoneclient import session as client_session
from keystoneclient.v2_0 import client as v2_client
from keystoneclient.v3 import client as v3_client
@@ -81,7 +81,7 @@ class _KeystoneVersion(object):
def __eq__(self, other):
return self.version == other.version and self.status == other.status
- def __call__(self, **kwargs):
+ def create_client(self, **kwargs):
if kwargs:
client_kwargs = self.client_kwargs.copy()
client_kwargs.update(kwargs)
@@ -89,6 +89,9 @@ class _KeystoneVersion(object):
client_kwargs = self.client_kwargs
return self.client_class(**client_kwargs)
+ def __call__(self, **kwargs):
+ return self.create_client(**kwargs)
+
@property
def _str_ver(self):
ver = ".".join([str(v) for v in self.version])
@@ -132,28 +135,35 @@ def _normalize_version_number(version):
raise TypeError("Invalid version specified: %s" % version)
-def available_versions(url, **kwargs):
+def available_versions(url, session=None, **kwargs):
headers = {'Accept': 'application/json'}
- client = httpclient.HTTPClient(**kwargs)
- resp, body_resp = client.request(url, 'GET', headers=headers)
+ if not session:
+ session = client_session.Session.construct(kwargs)
- # In the event of querying a root URL we will get back a list of
- # available versions.
- try:
- return body_resp['versions']['values']
- except (KeyError, TypeError):
- pass
+ resp = session.get(url, headers=headers)
- # Otherwise if we query an endpoint like /v2.0 then we will get back
- # just the one available version.
try:
- return [body_resp['version']]
- except (KeyError, TypeError):
+ body_resp = resp.json()
+ except ValueError:
pass
+ else:
+ # In the event of querying a root URL we will get back a list of
+ # available versions.
+ try:
+ return body_resp['versions']['values']
+ except (KeyError, TypeError):
+ pass
+
+ # Otherwise if we query an endpoint like /v2.0 then we will get back
+ # just the one available version.
+ try:
+ return [body_resp['version']]
+ except KeyError:
+ pass
raise exceptions.DiscoveryFailure("Invalid Response - Bad version"
- " data returned: %s" % body_resp)
+ " data returned: %s" % resp.text)
class Discover(object):
@@ -164,7 +174,7 @@ class Discover(object):
operates upon the data that was retrieved.
"""
- def __init__(self, **kwargs):
+ def __init__(self, session=None, **kwargs):
"""Construct a new discovery object.
The connection parameters associated with this method are the same
@@ -178,6 +188,9 @@ class Discover(object):
The initialization process also queries the server.
+ :param Session session: A session object that will be used for
+ communication. Clients will also be constructed
+ with this session.
:param string auth_url: Identity service endpoint for authorization.
(optional)
:param string endpoint: A user-supplied endpoint URL for the identity
@@ -185,26 +198,42 @@ class Discover(object):
:param string original_ip: The original IP of the requesting user
which will be sent to identity service in a
'Forwarded' header. (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
:param boolean debug: Enables debug logging of all request and
responses to the identity service.
default False (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
:param string cacert: Path to the Privacy Enhanced Mail (PEM) file
which contains the trusted authority X.509
certificates needed to established SSL connection
with the identity service. (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
:param string key: Path to the Privacy Enhanced Mail (PEM) file which
contains the unencrypted client private key needed
to established two-way SSL connection with the
identity service. (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
:param string cert: Path to the Privacy Enhanced Mail (PEM) file which
contains the corresponding X.509 client certificate
needed to established two-way SSL connection with
the identity service. (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
:param boolean insecure: Does not perform X.509 certificate validation
when establishing SSL connection with identity
service. default: False (optional)
+ DEPRECATED: use the session object. This is
+ ignored if a session is provided.
"""
+ if not session:
+ session = client_session.Session.construct(kwargs)
+ kwargs['session'] = session
+
url = kwargs.get('endpoint') or kwargs.get('auth_url')
if not url:
raise exceptions.DiscoveryFailure('Not enough information to '
@@ -212,7 +241,7 @@ class Discover(object):
'auth_url or endpoint')
self._client_kwargs = kwargs
- self._available_versions = available_versions(url, **kwargs)
+ self._available_versions = available_versions(url, session=session)
def _get_client_constructor_kwargs(self, kwargs_dict={}, **kwargs):
client_kwargs = self._client_kwargs.copy()
@@ -420,4 +449,4 @@ class Discover(object):
raise exceptions.VersionNotAvailable(msg)
- return chosen()
+ return chosen.create_client()