Skip to content

Commit 05e818c

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Improve masking of secrets in configuration show"
2 parents a7aa9e8 + 1de4c66 commit 05e818c

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

openstackclient/common/configuration.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
"""Configuration action implementations"""
1515

16+
from keystoneauth1.loading import base
1617
from osc_lib.command import command
1718
import six
1819

@@ -44,12 +45,13 @@ def get_parser(self, prog_name):
4445

4546
def take_action(self, parsed_args):
4647

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+
4752
info = self.app.client_manager.get_configuration()
4853
for key, value in six.iteritems(info.pop('auth', {})):
49-
if parsed_args.mask:
50-
if 'password' in key.lower():
51-
value = REDACTED
52-
if 'token' in key.lower():
54+
if parsed_args.mask and key.lower() in secret_opts:
5355
value = REDACTED
5456
info['auth.' + key] = value
5557
return zip(*sorted(six.iteritems(info)))

openstackclient/tests/common/test_configuration.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# under the License.
1212
#
1313

14+
import mock
15+
1416
from openstackclient.common import configuration
1517
from openstackclient.tests import fakes
1618
from openstackclient.tests import utils
@@ -33,7 +35,12 @@ class TestConfiguration(utils.TestCommand):
3335
fakes.REGION_NAME,
3436
)
3537

36-
def test_show(self):
38+
opts = [mock.Mock(secret=True, dest="password"),
39+
mock.Mock(secret=True, dest="token")]
40+
41+
@mock.patch("keystoneauth1.loading.base.get_plugin_options",
42+
return_value=opts)
43+
def test_show(self, m_get_plugin_opts):
3744
arglist = []
3845
verifylist = [('mask', True)]
3946
cmd = configuration.ShowConfiguration(self.app, None)
@@ -44,7 +51,9 @@ def test_show(self):
4451
self.assertEqual(self.columns, columns)
4552
self.assertEqual(self.datalist, data)
4653

47-
def test_show_unmask(self):
54+
@mock.patch("keystoneauth1.loading.base.get_plugin_options",
55+
return_value=opts)
56+
def test_show_unmask(self, m_get_plugin_opts):
4857
arglist = ['--unmask']
4958
verifylist = [('mask', False)]
5059
cmd = configuration.ShowConfiguration(self.app, None)
@@ -62,7 +71,9 @@ def test_show_unmask(self):
6271
)
6372
self.assertEqual(datalist, data)
6473

65-
def test_show_mask(self):
74+
@mock.patch("keystoneauth1.loading.base.get_plugin_options",
75+
return_value=opts)
76+
def test_show_mask(self, m_get_plugin_opts):
6677
arglist = ['--mask']
6778
verifylist = [('mask', True)]
6879
cmd = configuration.ShowConfiguration(self.app, None)

0 commit comments

Comments
 (0)