""" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0 """ from __future__ import unicode_literals import regex as re from cfnlint.rules import CloudFormationLintRule, RuleMatch class Used(CloudFormationLintRule): """Check if Parameters are used""" id = "W2001" shortdesc = "Check if Parameters are Used" description = "Making sure the parameters defined are used" source_url = "https://github.com/aws-cloudformation/cfn-python-lint" tags = ["parameters"] def searchstring(self, string, parameter): """Search string for tokenized fields""" regex = re.compile(rf"\${({parameter})}") return regex.findall(string) def isparaminref(self, subs, parameter): """Search sub strings for parameters""" for sub in subs: if isinstance(sub, (str)): if self.searchstring(sub, parameter): return True return False def match(self, cfn): matches = [] reftrees = cfn.transform_pre.get("Ref") subtrees = cfn.transform_pre.get("Fn::Sub") refs = [] for reftree in reftrees: refs.append(reftree[-1]) subs = [] for subtree in subtrees: if isinstance(subtree[-1], list): subs.extend(cfn.get_sub_parameters(subtree[-1][0])) elif isinstance(subtree[-1], str): subs.extend(cfn.get_sub_parameters(subtree[-1])) for paramname, _ in cfn.get_parameters().items(): if paramname not in refs: if paramname not in subs: message = "Parameter {0} not used." matches.append( RuleMatch(["Parameters", paramname], message.format(paramname)) ) return matches
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
AllowedPattern.py | File | 7.98 KB | 0644 |
|
AllowedValue.py | File | 7.12 KB | 0644 |
|
ApproachingLimitName.py | File | 691 B | 0644 |
|
ApproachingLimitNumber.py | File | 695 B | 0644 |
|
ApproachingLimitValue.py | File | 3.09 KB | 0644 |
|
Configuration.py | File | 6.65 KB | 0644 |
|
Default.py | File | 5.51 KB | 0644 |
|
DefaultRef.py | File | 986 B | 0644 |
|
LambdaMemorySize.py | File | 2.45 KB | 0644 |
|
LimitName.py | File | 709 B | 0644 |
|
LimitNumber.py | File | 697 B | 0644 |
|
LimitValue.py | File | 2.82 KB | 0644 |
|
Name.py | File | 698 B | 0644 |
|
Types.py | File | 1.24 KB | 0644 |
|
Used.py | File | 1.82 KB | 0644 |
|
__init__.py | File | 106 B | 0644 |
|