Strip version from service catalog endpoint
This client includes the API version in the URL directly where the former practice was to include it in the service catalog endpoint. This change removes the version from the last component of the SC endpoint (if present) for transition purposes. Note that this does not generalize to the other APIs where the version is not the last component of the SC endpoint. Change-Id: Ie04c38d80b17a171482e195aa1c633b6b6974042
This commit is contained in:
parent
d3185dd3b4
commit
e2936766f7
@ -19,6 +19,7 @@ Command-line interface to the OpenStack Images API.
|
||||
|
||||
import argparse
|
||||
import httplib2
|
||||
import re
|
||||
import sys
|
||||
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
@ -120,6 +121,21 @@ class OpenStackImagesShell(object):
|
||||
subparser.add_argument(*args, **kwargs)
|
||||
subparser.set_defaults(func=callback)
|
||||
|
||||
# TODO(dtroyer): move this into the common client support?
|
||||
# Compatibility check to remove API version as the trailing component
|
||||
# in a service endpoint; also removes a trailing '/'
|
||||
def _strip_version(self, endpoint):
|
||||
"""Strip a version from the last component of an endpoint if present"""
|
||||
|
||||
# Get rid of trailing '/' if present
|
||||
if endpoint.endswith('/'):
|
||||
endpoint = endpoint[:-1]
|
||||
url_bits = endpoint.split('/')
|
||||
# regex to match 'v1' or 'v2.0' etc
|
||||
if re.match('v\d+\.?\d*', url_bits[-1]):
|
||||
endpoint = '/'.join(url_bits[:-1])
|
||||
return endpoint
|
||||
|
||||
def _authenticate(self, **kwargs):
|
||||
"""Get an endpoint and auth token from Keystone.
|
||||
|
||||
@ -136,6 +152,7 @@ class OpenStackImagesShell(object):
|
||||
auth_url=kwargs.get('auth_url'))
|
||||
endpoint = _ksclient.service_catalog.url_for(service_type='image',
|
||||
endpoint_type='publicURL')
|
||||
endpoint = self._strip_version(endpoint)
|
||||
return (endpoint, _ksclient.auth_token)
|
||||
|
||||
def main(self, argv):
|
||||
|
Loading…
x
Reference in New Issue
Block a user