Fix keystone version selection

The client currently only accepts '3.0' which directly conflicts with
other clients (like OSC). It is not currently possible to export
OS_IDENTITY_API_VERSION and have it work properly for both clients.

In addition, the way it is written now "DEFAULT" is not really a
proper default, as 2.0 is the fallback. This change resolves that
inconsistency.

Closes-bug: #1496597
Change-Id: I0d829e46fc251eb7762912c7f89f79cb267e6abe
This commit is contained in:
Adam Harwell 2015-09-04 04:11:48 -07:00
parent 5455c28853
commit 424f2ac071
4 changed files with 20 additions and 9 deletions

View File

@ -109,7 +109,7 @@ The command line client is self-documenting. Use the --help flag to access the u
--no-auth, -N Do not use authentication.
--os-identity-api-version <identity-api-version>
Specify Identity API version to use. Defaults to
env[OS_IDENTITY_API_VERSION] or 3.0.
env[OS_IDENTITY_API_VERSION] or 3.
--os-auth-url <auth-url>, -A <auth-url>
Defaults to env[OS_AUTH_URL].
@ -180,4 +180,4 @@ The command line client is self-documenting. Use the --help flag to access the u
* Bugs: http://bugs.launchpad.net/python-barbicanclient
.. [1] Documentation in this link is currently incomplete. Please use the
`devstack setup. <http://docs.openstack.org/developer/barbican/setup/devstack.html>`__
`devstack setup. <http://docs.openstack.org/developer/barbican/setup/devstack.html>`__

View File

@ -34,7 +34,9 @@ from barbicanclient import client
from barbicanclient import version
_DEFAULT_IDENTITY_API_VERSION = '3.0'
_DEFAULT_IDENTITY_API_VERSION = '3'
_IDENTITY_API_VERSION_2 = ['2', '2.0']
_IDENTITY_API_VERSION_3 = ['3']
class Barbican(app.App):
@ -125,10 +127,19 @@ class Barbican(app.App):
kwargs = self.build_kwargs_based_on_version(args, api_version)
kwargs.update(kwargs_dict)
if not api_version or api_version == _DEFAULT_IDENTITY_API_VERSION:
method = v3.Token if auth_type == 'token' else v3.Password
else:
if api_version in _IDENTITY_API_VERSION_2:
method = v2.Token if auth_type == 'token' else v2.Password
else:
if not api_version or api_version not in _IDENTITY_API_VERSION_3:
self.stderr.write(
"WARNING: The identity version <{0}> is not in supported "
"versions <{1}>, falling back to <{2}>.".format(
api_version,
_IDENTITY_API_VERSION_2 + _IDENTITY_API_VERSION_3,
_DEFAULT_IDENTITY_API_VERSION
)
)
method = v3.Token if auth_type == 'token' else v3.Password
auth = method(**kwargs)
@ -217,7 +228,7 @@ class Barbican(app.App):
default=client.env('OS_IDENTITY_API_VERSION'),
help='Specify Identity API version to use. '
'Defaults to env[OS_IDENTITY_API_VERSION]'
' or 3.0.')
' or 3.')
parser.add_argument('--os-auth-url', '-A',
metavar='<auth-url>',
default=client.env('OS_AUTH_URL'),

View File

@ -47,7 +47,7 @@ V3_MEDIA_TYPES = [{'base': 'application/json',
{'base': 'application/xml',
'type': 'application/vnd.openstack.identity-v3+xml'}]
V3_VERSION = {'id': 'v3.0',
V3_VERSION = {'id': 'v3',
'links': [{'href': V3_URL, 'rel': 'self'}],
'media-types': V3_MEDIA_TYPES,
'status': 'stable',

View File

@ -57,7 +57,7 @@ class BaseBehaviors(object):
arg_list.extend(
['--os-project-domain-name',
CONF.keymanager.project_domain_name])
arg_list.extend(['--os-identity-api-version', '3.0'])
arg_list.extend(['--os-identity-api-version', '3'])
else:
arg_list.extend(['--os-auth-url', CONF.identity.uri])
arg_list.extend(['--os-tenant-name', CONF.keymanager.project_name])