diff --git a/swiftclient/service.py b/swiftclient/service.py index dfe20188..081d6246 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -92,11 +92,18 @@ def process_options(options): elif options.get('auth_version') == '2': options['auth_version'] = '2.0' - if (not (options.get('auth') and options.get('user') - and options.get('key')) - and options.get('auth_version') != '3'): - # Use keystone 2.0 auth if any of the old-style args are missing - options['auth_version'] = '2.0' + if options.get('auth_version') not in ('2.0', '3') and not all( + options.get(key) for key in ('auth', 'user', 'key')): + # Use keystone auth if any of the new-style args are present + if any(options.get(k) for k in ( + 'os_user_domain_id', + 'os_user_domain_name', + 'os_project_domain_id', + 'os_project_domain_name')): + # Use v3 if there's any reference to domains + options['auth_version'] = '3' + else: + options['auth_version'] = '2.0' # Use new-style args if old ones not present if not options['auth'] and options['os_auth_url']: diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 34407f43..a4222936 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -1197,8 +1197,7 @@ def parse_args(parser, args, enforce_requires=True): return options, args if (options['os_options']['object_storage_url'] and - options['os_options']['auth_token'] and - options['auth_version'] in ('2.0', '3')): + options['os_options']['auth_token']): return options, args if enforce_requires: diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index f921721f..146d0b61 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -1971,6 +1971,13 @@ class TestKeystoneOptions(MockHttpTest): self._test_options(opts, os_opts, flags=self.flags) opts = {} + self.defaults['auth-version'] = '3' + self._test_options(opts, os_opts, flags=self.flags) + + for o in ('user-domain-name', 'user-domain-id', + 'project-domain-name', 'project-domain-id'): + os_opts.pop(o) + self.defaults['auth-version'] = '2.0' self._test_options(opts, os_opts, flags=self.flags) def test_catalog_options_and_flags_not_required_v3(self): @@ -2021,6 +2028,28 @@ class TestKeystoneOptions(MockHttpTest): os_opts = self._build_os_opts(keys) self._test_options(opts, os_opts) + # ...except when it should be 3 + self.defaults['auth-version'] = '3' + keys = ('username', 'user-domain-name', 'password', 'project-name', + 'auth-url') + os_opts = self._build_os_opts(keys) + self._test_options(opts, os_opts) + + keys = ('username', 'user-domain-id', 'password', 'project-name', + 'auth-url') + os_opts = self._build_os_opts(keys) + self._test_options(opts, os_opts) + + keys = ('username', 'project-domain-name', 'password', 'project-name', + 'auth-url') + os_opts = self._build_os_opts(keys) + self._test_options(opts, os_opts) + + keys = ('username', 'project-domain-id', 'password', 'project-name', + 'auth-url') + os_opts = self._build_os_opts(keys) + self._test_options(opts, os_opts) + def test_url_and_token_provided_on_command_line(self): endpoint = 'http://alternate.com:8080/v1/AUTH_another' token = 'alternate_auth_token'