diff options
author | Daniil Baturin <daniil@vyos.io> | 2023-11-23 12:48:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-23 12:48:05 +0000 |
commit | a54fe17d7e2bc3ab5834e439d90effc247306fc2 (patch) | |
tree | 337fa11842302140887bfc5738ead6566829c521 /python | |
parent | ed0570b31eac62a9c4f3fa794ca4b9848ae1f279 (diff) | |
parent | 1b7e8f9ff7a86125ca7c8a2035650d5203dc54c5 (diff) | |
download | vyos-1x-a54fe17d7e2bc3ab5834e439d90effc247306fc2.tar.gz vyos-1x-a54fe17d7e2bc3ab5834e439d90effc247306fc2.zip |
Merge pull request #2535 from c-po/crux-pr-2522
https api: T5772: check if keys are configured unless PAM auth is enabled for GraphQL (backport #2522)
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/util.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 3ffd025b9..bac327018 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -237,3 +237,22 @@ def process_named_running(name): if name in p.name(): return p.pid return None + +def dict_search(path, dict_object): + """ Traverse Python dictionary (dict_object) delimited by dot (.). + Return value of key if found, None otherwise. + This is faster implementation then jmespath.search('foo.bar', dict_object)""" + if not isinstance(dict_object, dict) or not path: + return None + + parts = path.split('.') + inside = parts[:-1] + if not inside: + if path not in dict_object: + return None + return dict_object[path] + c = dict_object + for p in parts[:-1]: + c = c.get(p, {}) + return c.get(parts[-1], None) + |