in src/cfnlint/rules/resources/properties/Properties.py [0:0]
def _check_list_for_condition(self, text, prop, parenttype, resourcename, propspec, path):
""" Loop for conditions """
matches = []
if len(text) == 3:
for if_i, if_v in enumerate(text[1:]):
condition_path = path[:] + [if_i + 1]
if isinstance(if_v, list):
for index, item in enumerate(if_v):
arrproppath = condition_path[:]
arrproppath.append(index)
matches.extend(self.propertycheck(
item, propspec['ItemType'],
parenttype, resourcename, arrproppath, False))
elif isinstance(if_v, dict):
if len(if_v) == 1:
for d_k, d_v in if_v.items():
if d_k != 'Ref' or d_v != 'AWS::NoValue':
if d_k == 'Fn::GetAtt':
resource_name = None
if isinstance(d_v, list):
resource_name = d_v[0]
elif isinstance(d_v, six.string_types):
resource_name = d_v.split('.')[0]
if resource_name:
resource_type = self.cfn.template.get(
'Resources', {}).get(resource_name, {}).get('Type')
if not (resource_type.startswith('Custom::')):
message = 'Property {0} should be of type List for resource {1} at {2}'
matches.append(
RuleMatch(
condition_path,
message.format(prop, resourcename, ('/'.join(str(x) for x in condition_path)))))
elif d_k == 'Fn::If':
matches.extend(
self._check_list_for_condition(
d_v, prop, parenttype, resourcename, propspec, condition_path)
)
else:
message = 'Property {0} should be of type List for resource {1} at {2}'
matches.append(
RuleMatch(
condition_path,
message.format(prop, resourcename, ('/'.join(str(x) for x in condition_path)))))
else:
message = 'Property {0} should be of type List for resource {1} at {2}'
matches.append(
RuleMatch(
condition_path,
message.format(prop, resourcename, ('/'.join(str(x) for x in condition_path)))))
else:
message = 'Property {0} should be of type List for resource {1} at {2}'
matches.append(
RuleMatch(
condition_path,
message.format(prop, resourcename, ('/'.join(str(x) for x in condition_path)))))
else:
message = 'Invalid !If condition specified at %s' % (
'/'.join(map(str, path)))
matches.append(RuleMatch(path, message))
return matches