|
| 1 | +""" |
| 2 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +SPDX-License-Identifier: MIT-0 |
| 4 | +""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from typing import Any |
| 9 | + |
| 10 | +import cfnlint.data.schemas.other.rules |
| 11 | +from cfnlint.jsonschema import Validator |
| 12 | +from cfnlint.jsonschema._keywords import patternProperties |
| 13 | +from cfnlint.jsonschema._keywords_cfn import cfn_type |
| 14 | +from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails |
| 15 | + |
| 16 | + |
| 17 | +class Configuration(CfnLintJsonSchema): |
| 18 | + id = "E1700" |
| 19 | + shortdesc = "Rules have the appropriate configuration" |
| 20 | + description = "Making sure the Rules section is properly configured" |
| 21 | + source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/rules-section-structure.html" |
| 22 | + tags = ["rules"] |
| 23 | + |
| 24 | + def __init__(self): |
| 25 | + super().__init__( |
| 26 | + keywords=["Rules"], |
| 27 | + schema_details=SchemaDetails( |
| 28 | + cfnlint.data.schemas.other.rules, "configuration.json" |
| 29 | + ), |
| 30 | + all_matches=True, |
| 31 | + ) |
| 32 | + self.validators = { |
| 33 | + "type": cfn_type, |
| 34 | + "patternProperties": self._pattern_properties, |
| 35 | + } |
| 36 | + |
| 37 | + def _pattern_properties( |
| 38 | + self, validator: Validator, aP: Any, instance: Any, schema: Any |
| 39 | + ): |
| 40 | + # We have to rework pattern properties |
| 41 | + # to re-add the keyword or we will have an |
| 42 | + # infinite loop |
| 43 | + validator = validator.evolve( |
| 44 | + function_filter=validator.function_filter.evolve( |
| 45 | + add_cfn_lint_keyword=True, |
| 46 | + ) |
| 47 | + ) |
| 48 | + yield from patternProperties(validator, aP, instance, schema) |
| 49 | + |
| 50 | + def validate( |
| 51 | + self, validator: Validator, conditions: Any, instance: Any, schema: Any |
| 52 | + ): |
| 53 | + rule_validator = self.extend_validator( |
| 54 | + validator=validator, |
| 55 | + schema=self.schema, |
| 56 | + context=validator.context.evolve( |
| 57 | + resources={}, |
| 58 | + strict_types=False, |
| 59 | + ), |
| 60 | + ).evolve( |
| 61 | + context=validator.context.evolve(strict_types=False), |
| 62 | + function_filter=validator.function_filter.evolve( |
| 63 | + add_cfn_lint_keyword=False, |
| 64 | + ), |
| 65 | + ) |
| 66 | + |
| 67 | + yield from super()._iter_errors(rule_validator, instance) |
0 commit comments