Skip to content

Commit ae957b1

Browse files
author
Dean Troyer
committed
Use Keystone client session.Session
This replaces the restapi requests wrapper with the one from Keystone client so we can take advantage of the auth plugins. As a first step only the v2 and v3 token and password plugins are supported. This maintainis no changes to the command options or environment variables. The next steps will include reworking the other API client interfaces to fully utilize the single auth session. Blueprint: ksc-session-auth Change-Id: I47ec63291e4c3cf36c8061299a4764f60b36ab89
1 parent 3317e0a commit ae957b1

10 files changed

Lines changed: 102 additions & 742 deletions

File tree

‎openstackclient/common/clientmanager.py‎

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import pkg_resources
2020
import sys
2121

22-
from openstackclient.common import restapi
22+
from keystoneclient.auth.identity import v2 as v2_auth
23+
from keystoneclient.auth.identity import v3 as v3_auth
24+
from keystoneclient import session
2325
from openstackclient.identity import client as identity_client
2426

2527

@@ -80,24 +82,68 @@ def __init__(self, token=None, url=None, auth_url=None,
8082
self._cacert = verify
8183
self._insecure = False
8284

83-
self.session = restapi.RESTApi(
84-
verify=verify,
85-
debug=True,
86-
)
85+
ver_prefix = identity_client.AUTH_VERSIONS[
86+
self._api_version[identity_client.API_NAME]
87+
]
8788

8889
# Get logging from root logger
8990
root_logger = logging.getLogger('')
9091
LOG.setLevel(root_logger.getEffectiveLevel())
91-
restapi_logger = logging.getLogger('restapi')
92-
restapi_logger.setLevel(root_logger.getEffectiveLevel())
9392

94-
self.auth_ref = None
93+
# NOTE(dtroyer): These plugins are hard-coded for the first step
94+
# in using the new Keystone auth plugins.
95+
96+
if self._url:
97+
LOG.debug('Using token auth %s', ver_prefix)
98+
if ver_prefix == 'v2':
99+
self.auth = v2_auth.Token(
100+
auth_url=url,
101+
token=token,
102+
)
103+
else:
104+
self.auth = v3_auth.Token(
105+
auth_url=url,
106+
token=token,
107+
)
108+
else:
109+
LOG.debug('Using password auth %s', ver_prefix)
110+
if ver_prefix == 'v2':
111+
self.auth = v2_auth.Password(
112+
auth_url=auth_url,
113+
username=username,
114+
password=password,
115+
trust_id=trust_id,
116+
tenant_id=project_id,
117+
tenant_name=project_name,
118+
)
119+
else:
120+
self.auth = v3_auth.Password(
121+
auth_url=auth_url,
122+
username=username,
123+
password=password,
124+
trust_id=trust_id,
125+
user_domain_id=user_domain_id,
126+
user_domain_name=user_domain_name,
127+
domain_id=domain_id,
128+
domain_name=domain_name,
129+
project_id=project_id,
130+
project_name=project_name,
131+
project_domain_id=project_domain_id,
132+
project_domain_name=project_domain_name,
133+
)
134+
135+
self.session = session.Session(
136+
auth=self.auth,
137+
verify=verify,
138+
)
95139

140+
self.auth_ref = None
96141
if not self._url:
142+
# Trigger the auth call
143+
self.auth_ref = self.session.auth.get_auth_ref(self.session)
97144
# Populate other password flow attributes
98-
self.auth_ref = self.identity.auth_ref
99-
self._token = self.identity.auth_token
100-
self._service_catalog = self.identity.service_catalog
145+
self._token = self.session.auth.get_token(self.session)
146+
self._service_catalog = self.auth_ref.service_catalog
101147

102148
return
103149

0 commit comments

Comments
 (0)