diff options
author | Ben Nemec <bnemec@redhat.com> | 2018-11-28 19:38:48 +0000 |
---|---|---|
committer | Ben Nemec <bnemec@redhat.com> | 2018-12-03 16:44:28 +0000 |
commit | ddc436925887b6ece4aba19a36e53ede0b22ae21 (patch) | |
tree | 1b6b47759b64c505f102a1d1f9e2aeefbafae343 /oslo_utils/strutils.py | |
parent | c568717706b18eab1c679c6792b8016f5fbb9a35 (diff) | |
download | oslo-utils-ddc436925887b6ece4aba19a36e53ede0b22ae21.tar.gz |
Support non-dict mappings in mask_dict_password
mask_dict_password doesn't actually have a dependency on the dict
type specifically. It can work on any subclass of collections.Mapping.
This changes the isinstance check to reflect that and adds a unit
test using a collections.Mapping subclass.
Change-Id: I28781acf027b9b34f8274196db5dd4d2a9adc9ba
Closes-Bug: 1804528
Diffstat (limited to 'oslo_utils/strutils.py')
-rw-r--r-- | oslo_utils/strutils.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/oslo_utils/strutils.py b/oslo_utils/strutils.py index ebcc104..d7b104d 100644 --- a/oslo_utils/strutils.py +++ b/oslo_utils/strutils.py @@ -17,6 +17,7 @@ System-level utilities and helper functions. """ +import collections import math import re import unicodedata @@ -390,12 +391,12 @@ def mask_dict_password(dictionary, secret="***"): # nosec """ - if not isinstance(dictionary, dict): - raise TypeError("Expected a dictionary, got %s instead." + if not isinstance(dictionary, collections.Mapping): + raise TypeError("Expected a Mapping, got %s instead." % type(dictionary)) out = {} for k, v in dictionary.items(): - if isinstance(v, dict): + if isinstance(v, collections.Mapping): out[k] = mask_dict_password(v, secret=secret) continue # NOTE(jlvillal): Check to see if anything in the dictionary 'key' |