in src/cfnlint/template.py [0:0]
def get_values(self, obj, key, path=[]):
"""
Logic for getting the value of a key
Returns None if the item isn't found
Returns empty list if the item is found but Ref or GetAtt
Returns all the values as a list if condition
Returns the value if its just a string, int, boolean, etc.
"""
LOGGER.debug('Get the value for key %s in %s', key, obj)
matches = []
if not isinstance(obj, dict):
return None
value = obj.get(key)
if value is None:
return None
if isinstance(value, (dict)):
if len(value) == 1:
is_condition = False
is_no_value = False
for obj_key, obj_value in value.items():
if obj_key in cfnlint.helpers.CONDITION_FUNCTIONS:
is_condition = True
results = self.get_condition_values(obj_value, path[:] + [obj_key])
if isinstance(results, list):
for result in results:
check_obj = obj.copy()
check_obj[key] = result['Value']
matches.extend(self.get_values(check_obj, key, result['Path']))
elif obj_key == 'Ref' and obj_value == 'AWS::NoValue':
is_no_value = True
if not is_condition and not is_no_value:
result = {}
result['Path'] = path[:]
result['Value'] = value
matches.append(result)
else:
result = {}
result['Path'] = path[:]
result['Value'] = value
matches.append(result)
elif isinstance(value, (list)):
for list_index, list_value in enumerate(value):
if isinstance(list_value, dict):
if len(list_value) == 1:
is_condition = False
is_no_value = False
for obj_key, obj_value in list_value.items():
if obj_key in cfnlint.helpers.CONDITION_FUNCTIONS:
is_condition = True
results = self.get_condition_values(
obj_value, path[:] + [list_index, obj_key])
if isinstance(results, list):
matches.extend(results)
elif obj_key == 'Ref' and obj_value == 'AWS::NoValue':
is_no_value = True
if not is_condition and not is_no_value:
result = {}
result['Path'] = path[:] + [list_index]
result['Value'] = list_value
matches.append(result)
else:
result = {}
result['Path'] = path[:] + [list_index]
result['Value'] = list_value
matches.append(result)
else:
result = {}
result['Path'] = path[:] + [list_index]
result['Value'] = list_value
matches.append(result)
else:
result = {}
result['Path'] = path[:]
result['Value'] = value
matches.append(result)
return matches