Skip to content

Commit d3b87d7

Browse files
author
Dean Troyer
committed
Add version url config workaround
This subclasses KSC's generic Password plugin to allow version discovery with default Keystone configurations that leave admin_endpoint and public_endpoint at the default values (http://localhost:xxxx). This patch copies the scheme and netloc from the original auth_url into the URL returned from version discovery if the returned netloc begins with 'localhost'. Due to the specific nature of this review, the Keystone team is not inclned to include it in keystoneclient so it is addressed here. Closes-bug: #1410364 Change-Id: I877fe74d86aab3a63122a07b77d1302a007f5b30
1 parent 6b196d1 commit d3b87d7

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
@@ -72,7 +74,7 @@ def select_auth_plugin(options):
7274
auth_plugin_name = 'v2password'
7375
else:
7476
# let keystoneclient figure it out itself
75-
auth_plugin_name = 'password'
77+
auth_plugin_name = 'osc_password'
7678
elif options.os_token:
7779
if options.os_identity_api_version == '3':
7880
auth_plugin_name = 'v3token'
@@ -230,3 +232,45 @@ def get_options(self):
230232
])
231233

232234
return options
235+
236+
237+
class OSCGenericPassword(ksc_password.Password):
238+
"""Auth plugin hack to work around broken Keystone configurations
239+
240+
The default Keystone configuration uses http://localhost:xxxx in
241+
admin_endpoint and public_endpoint and are returned in the links.href
242+
attribute by the version routes. Deployments that do not set these
243+
are unusable with newer keystoneclient version discovery.
244+
245+
"""
246+
247+
def create_plugin(self, session, version, url, raw_status=None):
248+
"""Handle default Keystone endpoint configuration
249+
250+
Build the actual API endpoint from the scheme, host and port of the
251+
original auth URL and the rest from the returned version URL.
252+
"""
253+
254+
ver_u = urlparse.urlparse(url)
255+
256+
# Only hack this if it is the default setting
257+
if ver_u.netloc.startswith('localhost'):
258+
auth_u = urlparse.urlparse(self.auth_url)
259+
# from original auth_url: scheme, netloc
260+
# from api_url: path, query (basically, the rest)
261+
url = urlparse.urlunparse((
262+
auth_u.scheme,
263+
auth_u.netloc,
264+
ver_u.path,
265+
ver_u.params,
266+
ver_u.query,
267+
ver_u.fragment,
268+
))
269+
LOG.debug('Version URL updated: %s' % url)
270+
271+
return super(OSCGenericPassword, self).create_plugin(
272+
session=session,
273+
version=version,
274+
url=url,
275+
raw_status=raw_status,
276+
)

‎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)