summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-03-24 18:02:58 +0000
committerGerrit Code Review <review@openstack.org>2023-03-24 18:02:58 +0000
commit1ffe514621b1382c1172391ef038ec48a46a6846 (patch)
tree84dff950ad82b64cdb837e71bf35adab0a15c8c6
parentfe013f741718efb81ffae680617688ddfb8ce9d1 (diff)
parentee952c1bf250550d5da5b8a988e9e930edefce86 (diff)
downloadpython-swiftclient-1ffe514621b1382c1172391ef038ec48a46a6846.tar.gz
Merge "Ensure v*password auth_type correctly implies auth version"
-rw-r--r--swiftclient/service.py19
-rw-r--r--test/unit/test_shell.py86
2 files changed, 100 insertions, 5 deletions
diff --git a/swiftclient/service.py b/swiftclient/service.py
index 79cf86c..3d1b476 100644
--- a/swiftclient/service.py
+++ b/swiftclient/service.py
@@ -90,14 +90,26 @@ class SwiftError(Exception):
def process_options(options):
+ auth_types_to_versions = {
+ 'v1password': '1.0',
+ 'v2password': '2.0',
+ 'v3password': '3',
+ 'v3applicationcredential': '3',
+ }
+
+ version_from_type = auth_types_to_versions.get(options['os_auth_type'])
+ if version_from_type:
+ options['auth_version'] = version_from_type
+
# tolerate sloppy auth_version
if options.get('auth_version') == '3.0':
options['auth_version'] = '3'
elif options.get('auth_version') == '2':
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')):
+ if options.get('auth_version') not in ('2.0', '3') and \
+ options.get('os_auth_type') != 'v1password' 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',
@@ -109,9 +121,6 @@ def process_options(options):
else:
options['auth_version'] = '2.0'
- if options.get('os_auth_type', None) == 'v3applicationcredential':
- options['auth_version'] == '3'
-
# Use new-style args if old ones not present
if not options['auth'] and options['os_auth_url']:
options['auth'] = options['os_auth_url']
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py
index 5e69f4a..e76f73c 100644
--- a/test/unit/test_shell.py
+++ b/test/unit/test_shell.py
@@ -2759,6 +2759,92 @@ class TestParsing(TestBase):
swiftclient.shell.main(args)
self._verify_opts(result[0], expected_opts, expected_os_opts, {})
+ def test_os_auth_type_password_implies_version(self):
+ args = ["", "stat"]
+ env = {
+ 'OS_AUTH_URL': 'http://example.com/auth',
+ 'OS_AUTH_TYPE': 'v1password',
+ 'OS_USERNAME': 'user',
+ 'OS_PASSWORD': 'secret',
+ }
+ result = [None, None]
+ fake_command = self._make_fake_command(result)
+ with mock.patch.dict(os.environ, env):
+ with mock.patch('swiftclient.shell.st_stat', fake_command):
+ swiftclient.shell.main(args)
+ self._verify_opts(result[0], {
+ 'auth_version': '1.0',
+ 'user': 'user',
+ 'key': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v1password',
+ 'username': 'user',
+ 'password': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v1password',
+ 'username': 'user',
+ 'password': 'secret',
+ 'identity_api_version': '1.0',
+ })
+
+ env = {
+ 'OS_AUTH_URL': 'http://example.com/auth',
+ 'OS_AUTH_TYPE': 'v2password',
+ 'OS_USERNAME': 'user',
+ 'OS_PASSWORD': 'secret',
+ }
+ result = [None, None]
+ fake_command = self._make_fake_command(result)
+ with mock.patch.dict(os.environ, env):
+ with mock.patch('swiftclient.shell.st_stat', fake_command):
+ swiftclient.shell.main(args)
+ self._verify_opts(result[0], {
+ 'auth_version': '2.0',
+ 'user': 'user',
+ 'key': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v2password',
+ 'username': 'user',
+ 'password': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v2password',
+ 'username': 'user',
+ 'password': 'secret',
+ 'identity_api_version': '2.0',
+ })
+
+ env = {
+ 'OS_AUTH_URL': 'http://example.com/auth',
+ 'OS_AUTH_TYPE': 'v3password',
+ 'OS_USERNAME': 'user',
+ 'OS_PASSWORD': 'secret',
+ }
+ result = [None, None]
+ fake_command = self._make_fake_command(result)
+ with mock.patch.dict(os.environ, env):
+ with mock.patch('swiftclient.shell.st_stat', fake_command):
+ swiftclient.shell.main(args)
+ self._verify_opts(result[0], {
+ 'auth_version': '3',
+ 'user': 'user',
+ 'key': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v3password',
+ 'username': 'user',
+ 'password': 'secret',
+ }, {
+ 'auth_url': 'http://example.com/auth',
+ 'auth_type': 'v3password',
+ 'username': 'user',
+ 'password': 'secret',
+ 'identity_api_version': '3',
+ })
+
def test_args_v3(self):
opts = {"auth_version": "3"}
os_opts = {"password": "secret",