Skip to content

Commit c9c28dc

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add version url config workaround"
2 parents ab24728 + d3b87d7 commit c9c28dc

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎openstackclient/api/auth.py‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
import argparse
1717
import logging
1818

19+
from six.moves.urllib import parse as urlparse
1920
import stevedore
2021

2122
from oslo.config import cfg
2223

2324
from keystoneclient.auth import base
25+
from keystoneclient.auth.identity.generic import password as ksc_password
2426

2527
from openstackclient.common import exceptions as exc
2628
from openstackclient.common import utils
@@ -73,7 +75,7 @@ def select_auth_plugin(options):
7375
auth_plugin_name = 'v2password'
7476
else:
7577
# let keystoneclient figure it out itself
76-
auth_plugin_name = 'password'
78+
auth_plugin_name = 'osc_password'
7779
elif options.os_token:
7880
if options.os_identity_api_version == '3':
7981
auth_plugin_name = 'v3token'
@@ -250,3 +252,45 @@ def get_options(self):
250252
])
251253

252254
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+
)

‎setup.cfg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ console_scripts =
2929

3030
keystoneclient.auth.plugin =
3131
token_endpoint = openstackclient.api.auth:TokenEndpoint
32+
osc_password = openstackclient.api.auth:OSCGenericPassword
3233

3334
openstack.cli =
3435
command_list = openstackclient.common.module:ListCommand

0 commit comments

Comments
 (0)