-
Notifications
You must be signed in to change notification settings - Fork 596
/
Format.py
40 lines (32 loc) · 1.29 KB
/
Format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from __future__ import annotations
from typing import Any
from cfnlint.jsonschema import ValidationError, Validator
from cfnlint.jsonschema._keywords import format as parent_format
from cfnlint.rules import CloudFormationLintRule
class Format(CloudFormationLintRule):
id = "E1103"
shortdesc = "Validate the format of a value"
description = "Parent rule for validating the format keyword in schemas"
tags = []
def format(
self, validator: Validator, format: Any, instance: Any, schema: dict[str, Any]
):
if validator.format_checker is not None: # type: ignore
if format in validator.format_checker.checkers:
yield from parent_format(validator, format, instance, schema)
return
for rule in self.child_rules.values():
if rule is None:
continue
if not rule.id:
continue
if format == rule.format_keyword: # type: ignore
if not rule.format(validator, instance): # type: ignore
yield ValidationError(
f"{instance!r} is not a {format!r}",
rule=rule,
)