|
16 | 16 | import argparse |
17 | 17 | import logging |
18 | 18 |
|
| 19 | +from six.moves.urllib import parse as urlparse |
19 | 20 | import stevedore |
20 | 21 |
|
21 | 22 | from oslo.config import cfg |
22 | 23 |
|
23 | 24 | from keystoneclient.auth import base |
| 25 | +from keystoneclient.auth.identity.generic import password as ksc_password |
24 | 26 |
|
25 | 27 | from openstackclient.common import exceptions as exc |
26 | 28 | from openstackclient.common import utils |
@@ -73,7 +75,7 @@ def select_auth_plugin(options): |
73 | 75 | auth_plugin_name = 'v2password' |
74 | 76 | else: |
75 | 77 | # let keystoneclient figure it out itself |
76 | | - auth_plugin_name = 'password' |
| 78 | + auth_plugin_name = 'osc_password' |
77 | 79 | elif options.os_token: |
78 | 80 | if options.os_identity_api_version == '3': |
79 | 81 | auth_plugin_name = 'v3token' |
@@ -250,3 +252,45 @@ def get_options(self): |
250 | 252 | ]) |
251 | 253 |
|
252 | 254 | return options |
| 255 | + |
| 256 | + |
| 257 | +class OSCGenericPassword(ksc_password.Password): |
| 258 | + """Auth plugin hack to work around broken Keystone configurations |
| 259 | +
|
| 260 | + The default Keystone configuration uses http://localhost:xxxx in |
| 261 | + admin_endpoint and public_endpoint and are returned in the links.href |
| 262 | + attribute by the version routes. Deployments that do not set these |
| 263 | + are unusable with newer keystoneclient version discovery. |
| 264 | +
|
| 265 | + """ |
| 266 | + |
| 267 | + def create_plugin(self, session, version, url, raw_status=None): |
| 268 | + """Handle default Keystone endpoint configuration |
| 269 | +
|
| 270 | + Build the actual API endpoint from the scheme, host and port of the |
| 271 | + original auth URL and the rest from the returned version URL. |
| 272 | + """ |
| 273 | + |
| 274 | + ver_u = urlparse.urlparse(url) |
| 275 | + |
| 276 | + # Only hack this if it is the default setting |
| 277 | + if ver_u.netloc.startswith('localhost'): |
| 278 | + auth_u = urlparse.urlparse(self.auth_url) |
| 279 | + # from original auth_url: scheme, netloc |
| 280 | + # from api_url: path, query (basically, the rest) |
| 281 | + url = urlparse.urlunparse(( |
| 282 | + auth_u.scheme, |
| 283 | + auth_u.netloc, |
| 284 | + ver_u.path, |
| 285 | + ver_u.params, |
| 286 | + ver_u.query, |
| 287 | + ver_u.fragment, |
| 288 | + )) |
| 289 | + LOG.debug('Version URL updated: %s' % url) |
| 290 | + |
| 291 | + return super(OSCGenericPassword, self).create_plugin( |
| 292 | + session=session, |
| 293 | + version=version, |
| 294 | + url=url, |
| 295 | + raw_status=raw_status, |
| 296 | + ) |
0 commit comments