|
| 1 | +""" |
| 2 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +SPDX-License-Identifier: MIT-0 |
| 4 | +""" |
| 5 | +from cfnlint.helpers import LIMITS |
| 6 | +from cfnlint.rules import RuleMatch |
| 7 | + |
| 8 | + |
| 9 | +def approaching_name_limit(cfn, section): |
| 10 | + """approaching name limit""" |
| 11 | + matches = [] |
| 12 | + for name in cfn.template.get(section, {}): |
| 13 | + if LIMITS['threshold'] * LIMITS[section]['name'] < len(name) <= LIMITS[section]['name']: |
| 14 | + message = 'The length of ' + section[:-1] + ' name ({0}) is approaching the limit ({1})' |
| 15 | + matches.append(RuleMatch([section, name], message.format(len(name), LIMITS[section]['name']))) |
| 16 | + return matches |
| 17 | + |
| 18 | + |
| 19 | +def approaching_number_limit(cfn, section): |
| 20 | + """approaching number limit""" |
| 21 | + matches = [] |
| 22 | + number = cfn.template.get(section, {}) |
| 23 | + if LIMITS['threshold'] * LIMITS[section]['number'] < len(number) <= LIMITS[section]['number']: |
| 24 | + message = 'The number of ' + section + ' ({0}) is approaching the limit ({1})' |
| 25 | + matches.append(RuleMatch([section], message.format(len(number), LIMITS[section]['number']))) |
| 26 | + return matches |
| 27 | + |
| 28 | + |
| 29 | +def name_limit(cfn, section): |
| 30 | + """exceeding name limit""" |
| 31 | + matches = [] |
| 32 | + for name in cfn.template.get(section, {}): |
| 33 | + if len(name) > LIMITS[section]['name']: |
| 34 | + message = 'The length of ' + section[:-1] + ' name ({0}) exceeds the limit ({1})' |
| 35 | + matches.append(RuleMatch([section, name], message.format(len(name), LIMITS[section]['name']))) |
| 36 | + return matches |
| 37 | + |
| 38 | + |
| 39 | +def number_limit(cfn, section): |
| 40 | + """exceeding number limit""" |
| 41 | + matches = [] |
| 42 | + number = cfn.template.get(section, {}) |
| 43 | + if len(number) > LIMITS[section]['number']: |
| 44 | + message = 'The number of ' + section + ' ({0}) exceeds the limit ({1})' |
| 45 | + matches.append(RuleMatch([section], message.format(len(number), LIMITS[section]['number']))) |
| 46 | + return matches |
0 commit comments