-
Notifications
You must be signed in to change notification settings - Fork 594
/
NumberRange.py
80 lines (71 loc) · 2.87 KB
/
NumberRange.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from cfnlint.jsonschema._keywords import (
exclusiveMaximum,
exclusiveMinimum,
maximum,
minimum,
)
from cfnlint.rules import CloudFormationLintRule
class NumberRange(CloudFormationLintRule):
"""Check if a Number has a length within the limit"""
id = "E3034"
shortdesc = "Check if a number is between min and max"
description = (
"Check numbers (integers and floats) for its value being between the minimum"
" and maximum"
)
source_url = "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#number-range"
tags = ["resources", "property", "number", "size"]
child_rules = {
"W3034": None,
}
def __init__(self) -> None:
self.parameter_rule = "W3034"
super().__init__()
def minimum(self, validator, m, instance, schema):
if (
len(validator.context.path.value_path) > 0
and validator.context.path.value_path[0] == "Parameters"
):
if self.child_rules.get(self.parameter_rule):
yield from self.child_rules[self.parameter_rule].validate(
validator, m, instance, schema, minimum
)
return
yield from minimum(validator, m, instance, schema)
def maximum(self, validator, m, instance, schema):
if (
len(validator.context.path.value_path) > 0
and validator.context.path.value_path[0] == "Parameters"
):
if self.child_rules.get(self.parameter_rule):
yield from self.child_rules[self.parameter_rule].validate(
validator, m, instance, schema, maximum
)
return
yield from maximum(validator, m, instance, schema)
def exclusiveMaximum(self, validator, m, instance, schema):
if (
len(validator.context.path.value_path) > 0
and validator.context.path.value_path[0] == "Parameters"
):
if self.child_rules.get(self.parameter_rule):
yield from self.child_rules[self.parameter_rule].validate(
validator, m, instance, schema, exclusiveMaximum
)
return
yield from exclusiveMaximum(validator, m, instance, schema)
def exclusiveMinimum(self, validator, m, instance, schema):
if (
len(validator.context.path.value_path) > 0
and validator.context.path.value_path[0] == "Parameters"
):
if self.child_rules.get(self.parameter_rule):
yield from self.child_rules[self.parameter_rule].validate(
validator, m, instance, schema, exclusiveMinimum
)
return
yield from exclusiveMinimum(validator, m, instance, schema)