diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2015-01-16 15:25:03 +1000 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2015-01-16 15:26:59 +1000 |
commit | 2322d30706361792ff7a306fa678334dce11fd31 (patch) | |
tree | a69f19855f66c3f230ea3cbc930987ee52f5778e | |
parent | 7a06f8632e638510bc00df4e96801ecd295aeb8e (diff) | |
download | python-troveclient-2322d30706361792ff7a306fa678334dce11fd31.tar.gz |
Pass all kwargs through to adapter
Part of the benefit of clients using the keystoneclient adapter to
manage the session object is that we can have a standard set of kwargs
that can be controlled from the adapter. This only works if the unknown
kwargs are passed through to the adapter.
Change-Id: I78f195ef739dbfe33a08f4dc1922b14ec77ae833
-rw-r--r-- | troveclient/client.py | 91 | ||||
-rw-r--r-- | troveclient/v1/client.py | 5 |
2 files changed, 47 insertions, 49 deletions
diff --git a/troveclient/client.py b/troveclient/client.py index 6ef6dbd..aec3212 100644 --- a/troveclient/client.py +++ b/troveclient/client.py @@ -427,19 +427,21 @@ class HTTPClient(TroveClientMixin): class SessionClient(adapter.LegacyJsonAdapter, TroveClientMixin): - def __init__(self, session, auth, service_type=None, service_name=None, - region_name=None, endpoint_type='publicURL', - database_service_name=None, endpoint_override=None): - self.endpoint_type = endpoint_type - self.database_service_name = database_service_name - self.endpoint_override = endpoint_override + def __init__(self, session, auth, **kwargs): + self.database_service_name = kwargs.pop('database_service_name', None) + super(SessionClient, self).__init__(session=session, auth=auth, - interface=endpoint_type, - service_type=service_type, - service_name=service_name, - region_name=region_name) - self.management_url = self._get_endpoint_url() + **kwargs) + + # FIXME(jamielennox): this is going to cause an authentication request + # on client init. This is different to how the other clients work. + endpoint = self.get_endpoint() + + if not endpoint: + raise exceptions.EndpointNotFound() + + self.management_url = endpoint.rstrip('/') def request(self, url, method, **kwargs): raise_exc = kwargs.pop('raise_exc', True) @@ -453,16 +455,6 @@ class SessionClient(adapter.LegacyJsonAdapter, TroveClientMixin): return resp, body - def _get_endpoint_url(self): - endpoint_url = self.session.get_endpoint( - self.auth, interface=self.endpoint_type, - service_type=self.service_type) - - if not endpoint_url: - raise exceptions.EndpointNotFound - - return endpoint_url.rstrip('/') - def _construct_http_client(username=None, password=None, project_id=None, auth_url=None, insecure=False, timeout=None, @@ -475,37 +467,42 @@ def _construct_http_client(username=None, password=None, project_id=None, auth_system='keystone', auth_plugin=None, cacert=None, bypass_url=None, tenant_id=None, session=None, - auth=None): + **kwargs): if session: + try: + kwargs.setdefault('interface', endpoint_type) + except KeyError: + pass + return SessionClient(session=session, - auth=auth, service_type=service_type, service_name=service_name, region_name=region_name, - endpoint_type=endpoint_type, - database_service_name=database_service_name) - - return HTTPClient(username, - password, - projectid=project_id, - auth_url=auth_url, - insecure=insecure, - timeout=timeout, - tenant_id=tenant_id, - proxy_token=proxy_token, - proxy_tenant_id=proxy_tenant_id, - region_name=region_name, - endpoint_type=endpoint_type, - service_type=service_type, - service_name=service_name, - database_service_name=database_service_name, - retries=retries, - http_log_debug=http_log_debug, - cacert=cacert, - bypass_url=bypass_url, - auth_system=auth_system, - auth_plugin=auth_plugin, - ) + database_service_name=database_service_name, + connect_retries=retries, + **kwargs) + else: + return HTTPClient(username, + password, + projectid=project_id, + auth_url=auth_url, + insecure=insecure, + timeout=timeout, + tenant_id=tenant_id, + proxy_token=proxy_token, + proxy_tenant_id=proxy_tenant_id, + region_name=region_name, + endpoint_type=endpoint_type, + service_type=service_type, + service_name=service_name, + database_service_name=database_service_name, + retries=retries, + http_log_debug=http_log_debug, + cacert=cacert, + bypass_url=bypass_url, + auth_system=auth_system, + auth_plugin=auth_plugin, + ) def get_version_map(): diff --git a/troveclient/v1/client.py b/troveclient/v1/client.py index 886b396..9429ee1 100644 --- a/troveclient/v1/client.py +++ b/troveclient/v1/client.py @@ -53,7 +53,7 @@ class Client(object): http_log_debug=False, cacert=None, bypass_url=None, auth_system='keystone', auth_plugin=None, session=None, - auth=None): + auth=None, **kwargs): # self.limits = limits.LimitsManager(self) # extensions @@ -115,7 +115,8 @@ class Client(object): auth_system=auth_system, auth_plugin=auth_plugin, session=session, - auth=auth) + auth=auth, + **kwargs) def authenticate(self): """Authenticate against the server. |