summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-05-31 18:52:47 +0200
committerGitHub <noreply@github.com>2022-05-31 18:52:47 +0200
commitc4d824d57d696bcf0e2a1e8e0fd87078e6eaadd3 (patch)
tree9748f854777466d12694698b14e00bc5d655692d /python
parent6a303c25207f08e6872a1e15211385c9bd458203 (diff)
parentdf039e9c797a24e4599d6d0b3bacfabfef894bfd (diff)
downloadvyos-1x-c4d824d57d696bcf0e2a1e8e0fd87078e6eaadd3.tar.gz
vyos-1x-c4d824d57d696bcf0e2a1e8e0fd87078e6eaadd3.zip
Merge pull request #1344 from sarthurdev/pki_update
pki: T3642: Update conf scripts using changed PKI objects
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index de55e108b..0d62fbfe9 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -757,21 +757,26 @@ def dict_search_args(dict_object, *path):
dict_object = dict_object[item]
return dict_object
-def dict_search_recursive(dict_object, key):
+def dict_search_recursive(dict_object, key, path=[]):
""" Traverse a dictionary recurisvely and return the value of the key
we are looking for.
Thankfully copied from https://stackoverflow.com/a/19871956
+
+ Modified to yield optional path to found keys
"""
if isinstance(dict_object, list):
for i in dict_object:
- for x in dict_search_recursive(i, key):
- yield x
+ new_path = path + [i]
+ for x in dict_search_recursive(i, key, new_path):
+ yield x
elif isinstance(dict_object, dict):
if key in dict_object:
- yield dict_object[key]
- for j in dict_object.values():
- for x in dict_search_recursive(j, key):
+ new_path = path + [key]
+ yield dict_object[key], new_path
+ for k, j in dict_object.items():
+ new_path = path + [k]
+ for x in dict_search_recursive(j, key, new_path):
yield x
def get_bridge_fdb(interface):