forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cidr.py
70 lines (62 loc) · 2.13 KB
/
Cidr.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
"""
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 Validator
from cfnlint.rules.functions._BaseFn import BaseFn
class Cidr(BaseFn):
"""Check if Cidr values are correct"""
id = "E1024"
shortdesc = "Cidr validation of parameters"
description = "Making sure the function CIDR is a list with valid values"
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html"
tags = ["functions", "cidr"]
def __init__(self) -> None:
super().__init__("Fn::Cidr", ("array",), None)
self.fn_cidr = self.validate
def schema(self, validator: Validator, instance: Any) -> dict[str, Any]:
functions = [
"Fn::FindInMap",
"Fn::Select",
"Ref",
"Fn::GetAtt",
"Fn::Sub",
"Fn::ImportValue",
"Fn::If",
]
return {
"type": ["array"],
"maxItems": 3,
"minItems": 2,
"fn_items": [
{
"functions": functions,
"schema": {
"type": ["string"],
"pattern": (
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.)"
"{3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
"(\\/([0-9]|[1-2][0-9]|3[0-2]))$"
),
},
},
{
"functions": functions,
"schema": {
"type": ["integer"],
"minimum": 1,
"maximum": 256,
},
},
{
"functions": functions,
"schema": {
"type": ["integer"],
"minimum": 1,
"maximum": 128,
},
},
],
}