Skip to content

Commit 9042668

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Make configuration show not require auth"
2 parents 6f60f83 + 865e182 commit 9042668

6 files changed

Lines changed: 150 additions & 54 deletions

File tree

openstackclient/common/configuration.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
class ShowConfiguration(command.ShowOne):
2626
_description = _("Display configuration details")
2727

28+
auth_required = False
29+
2830
def get_parser(self, prog_name):
2931
parser = super(ShowConfiguration, self).get_parser(prog_name)
3032
mask_group = parser.add_mutually_exclusive_group()
@@ -45,13 +47,21 @@ def get_parser(self, prog_name):
4547

4648
def take_action(self, parsed_args):
4749

48-
auth_plg_name = self.app.client_manager.auth_plugin_name
49-
secret_opts = [o.dest for o in base.get_plugin_options(auth_plg_name)
50-
if o.secret]
51-
5250
info = self.app.client_manager.get_configuration()
51+
52+
# Assume a default secret list in case we do not have an auth_plugin
53+
secret_opts = ["password", "token"]
54+
55+
if getattr(self.app.client_manager, "auth_plugin_name", None):
56+
auth_plg_name = self.app.client_manager.auth_plugin_name
57+
secret_opts = [
58+
o.dest for o in base.get_plugin_options(auth_plg_name)
59+
if o.secret
60+
]
61+
5362
for key, value in six.iteritems(info.pop('auth', {})):
5463
if parsed_args.mask and key.lower() in secret_opts:
55-
value = REDACTED
64+
value = REDACTED
5665
info['auth.' + key] = value
66+
5767
return zip(*sorted(six.iteritems(info)))

openstackclient/tests/functional/base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ class TestCase(testtools.TestCase):
4545
@classmethod
4646
def openstack(cls, cmd, cloud=ADMIN_CLOUD, fail_ok=False):
4747
"""Executes openstackclient command for the given action."""
48-
return execute(
49-
'openstack --os-cloud={cloud} '.format(cloud=cloud) +
50-
cmd, fail_ok=fail_ok)
48+
if cloud is not None:
49+
return execute(
50+
'openstack --os-cloud={cloud} '.format(cloud=cloud) + cmd,
51+
fail_ok=fail_ok
52+
)
53+
else:
54+
# Execute command with no auth
55+
return execute(
56+
'openstack --os-auth-type none ' + cmd,
57+
fail_ok=fail_ok
58+
)
5159

5260
@classmethod
5361
def is_service_enabled(cls, service):

openstackclient/tests/functional/common/test_configuration.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def test_configuration_show(self):
3737
configuration.REDACTED,
3838
cmd_output['auth.password']
3939
)
40+
self.assertIn(
41+
'auth.password',
42+
cmd_output.keys(),
43+
)
4044

4145
# Test show --mask
4246
cmd_output = json.loads(self.openstack(
@@ -65,3 +69,26 @@ def test_configuration_show(self):
6569
configuration.REDACTED,
6670
cmd_output['auth.password']
6771
)
72+
73+
74+
class ConfigurationTestsNoAuth(base.TestCase):
75+
"""Functional test for configuration with no auth"""
76+
77+
def test_configuration_show(self):
78+
79+
# Test show without option
80+
raw_output = self.openstack(
81+
'configuration show',
82+
cloud=None,
83+
)
84+
items = self.parse_listing(raw_output)
85+
self.assert_table_structure(items, BASIC_CONFIG_HEADERS)
86+
87+
cmd_output = json.loads(self.openstack(
88+
'configuration show -f json',
89+
cloud=None,
90+
))
91+
self.assertNotIn(
92+
'auth.password',
93+
cmd_output,
94+
)

openstackclient/tests/unit/integ/cli/test_project.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def setUp(self):
3636

3737
def test_project_id_env(self):
3838
_shell = shell.OpenStackShell()
39-
_shell.run("configuration show".split())
39+
_shell.run("extension list".split())
4040

4141
# Check general calls
42-
self.assertEqual(len(self.requests_mock.request_history), 2)
42+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
4343

4444
# Check discovery request
4545
self.assertEqual(
@@ -57,10 +57,10 @@ def test_project_id_env(self):
5757

5858
def test_project_id_arg(self):
5959
_shell = shell.OpenStackShell()
60-
_shell.run("--os-project-id wsx configuration show".split())
60+
_shell.run("--os-project-id wsx extension list".split())
6161

6262
# Check general calls
63-
self.assertEqual(len(self.requests_mock.request_history), 2)
63+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
6464

6565
# Check discovery request
6666
self.assertEqual(
@@ -94,10 +94,10 @@ def setUp(self):
9494

9595
def test_project_name_env(self):
9696
_shell = shell.OpenStackShell()
97-
_shell.run("configuration show".split())
97+
_shell.run("extension list".split())
9898

9999
# Check general calls
100-
self.assertEqual(len(self.requests_mock.request_history), 2)
100+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
101101

102102
# Check discovery request
103103
self.assertEqual(
@@ -115,10 +115,10 @@ def test_project_name_env(self):
115115

116116
def test_project_name_arg(self):
117117
_shell = shell.OpenStackShell()
118-
_shell.run("--os-project-name qaz configuration show".split())
118+
_shell.run("--os-project-name qaz extension list".split())
119119

120120
# Check general calls
121-
self.assertEqual(len(self.requests_mock.request_history), 2)
121+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
122122

123123
# Check discovery request
124124
self.assertEqual(
@@ -154,10 +154,10 @@ def setUp(self):
154154

155155
def test_project_id_env(self):
156156
_shell = shell.OpenStackShell()
157-
_shell.run("configuration show".split())
157+
_shell.run("extension list".split())
158158

159159
# Check general calls
160-
self.assertEqual(len(self.requests_mock.request_history), 2)
160+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
161161

162162
# Check discovery request
163163
self.assertEqual(
@@ -173,10 +173,10 @@ def test_project_id_env(self):
173173

174174
def test_project_id_arg(self):
175175
_shell = shell.OpenStackShell()
176-
_shell.run("--os-project-id wsx configuration show".split())
176+
_shell.run("--os-project-id wsx extension list".split())
177177

178178
# Check general calls
179-
self.assertEqual(len(self.requests_mock.request_history), 2)
179+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
180180

181181
# Check discovery request
182182
self.assertEqual(
@@ -210,10 +210,10 @@ def setUp(self):
210210

211211
def test_project_name_env(self):
212212
_shell = shell.OpenStackShell()
213-
_shell.run("configuration show".split())
213+
_shell.run("extension list".split())
214214

215215
# Check general calls
216-
self.assertEqual(len(self.requests_mock.request_history), 2)
216+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
217217

218218
# Check discovery request
219219
self.assertEqual(
@@ -234,10 +234,10 @@ def test_project_name_env(self):
234234

235235
def test_project_name_arg(self):
236236
_shell = shell.OpenStackShell()
237-
_shell.run("--os-project-name wsx configuration show".split())
237+
_shell.run("--os-project-name wsx extension list".split())
238238

239239
# Check general calls
240-
self.assertEqual(len(self.requests_mock.request_history), 2)
240+
self.assertNotEqual(len(self.requests_mock.request_history), 0)
241241

242242
# Check discovery request
243243
self.assertEqual(

0 commit comments

Comments
 (0)