Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with searchvar keys chain #115

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def flatten_dict(d, parent_key='', sep='.'):
return dict(items)


def deep_get(dictionary, keys):
def deep_get(dictionary, keys, previousKey=None):
'''
Search recursively for 'keys' in 'dictionary' and return value, otherwise return None
'''
Expand All @@ -202,7 +202,7 @@ def deep_get(dictionary, keys):
return None

# Recurse with next keys in the chain on the dict
return deep_get(value, keys[1:])
return deep_get(value, keys[1:], previousKey=keys[0])
else:
if isinstance(dictionary, dict):
# If we find nothing, check for globbing, loop and match with dict keys
Expand All @@ -215,14 +215,20 @@ def deep_get(dictionary, keys):
return dictionary[dict_key]

# If we have more variables in the chain, continue recursion
return deep_get(dictionary[dict_key], keys[1:])

# No globbing, move down the dictionary and recurse
for v in dictionary.values():
if isinstance(v, dict):
item = deep_get(v, keys)
if item:
return item
return deep_get(dictionary[dict_key], keys[1:], previousKey=keys[0])

if not previousKey:
# No previous keys in chain and no globbing, move down the dictionary and recurse
for v in dictionary.values():
if isinstance(v, dict):
item = None
if len(keys) > 1:
item = deep_get(v, keys, previousKey=keys[0])
else:
item = deep_get(v, keys)

if item:
return item

return value

Expand Down