Skip to content

Commit 85e1576

Browse files
authored
Create ipv4 and ipv6 network formats (#3981)
* Create ipv4 and ipv6 network formats * Update format docs
1 parent 6ce9c49 commit 85e1576

File tree

92 files changed

+641
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+641
-3
lines changed

docs/format_keyword.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ This format validates that the value is a valid Amazon Machine Image (AMI), whic
3535
### AWS::Logs::LogGroup.Name
3636

3737
This format validates that the value is a valid log group name, which is a string of the pattern `^[\.\-_\/#A-Za-z0-9]{1,512}\Z`. More info in [docs](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_LogGroup.html)
38+
39+
### ipv4-network
40+
41+
Validates the value against the python implementation of validating an [IPV4 network](https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv4Network)
42+
43+
### ipv6-network
44+
45+
Validates the value against the python implementation of validating an [IPV6 network](https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv6Network)

scripts/update_schemas_format.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ def _descend(instance: Any, keywords: Sequence[str]) -> Iterator[deque[str]]:
3636
return
3737

3838

39+
def _create_cidr_patch(type_name: str, ref: str, resolver: RefResolver, format: str):
40+
if type_name in [
41+
"AWS::SecurityHub::Insight",
42+
]:
43+
return []
44+
45+
_, resolved = resolver.resolve(ref)
46+
if "$ref" in resolved:
47+
return _create_cidr_patch(type_name, resolved["$ref"], resolver, format)
48+
49+
if "items" in resolved:
50+
return [
51+
Patch(
52+
values={"format": format},
53+
path=f"{ref[1:]}/items",
54+
)
55+
]
56+
57+
return [
58+
_create_patch(
59+
{"format": format},
60+
ref,
61+
resolver=resolver,
62+
)
63+
]
64+
65+
3966
def _create_subnet_ids_patch(type_name: str, ref: str, resolver: RefResolver):
4067

4168
_, resolved = resolver.resolve(ref)
@@ -148,11 +175,17 @@ def _create_security_group_name(type_name: str, ref: str, resolver: RefResolver)
148175
]
149176

150177

151-
def _create_patch(value: dict[str, str], ref: Sequence[str], resolver: RefResolver):
178+
def _create_patch(value: dict[str, str], ref: str, resolver: RefResolver):
152179
_, resolved = resolver.resolve(ref)
153180
if "$ref" in resolved:
154181
return _create_patch(value, resolved["$ref"], resolver)
155182

183+
if "items" in resolved:
184+
return Patch(
185+
values=value,
186+
path=f"{ref[1:]}/items",
187+
)
188+
156189
return Patch(
157190
values=value,
158191
path=ref[1:],
@@ -270,6 +303,42 @@ def main():
270303
)
271304
)
272305

306+
for path in _descend(
307+
obj,
308+
[
309+
"CidrIp",
310+
"CIDRIP",
311+
"Cidr",
312+
"Cidrs",
313+
"CidrBlock",
314+
"DestinationCidr",
315+
"DestinationCidrBlock",
316+
"SourceCidrBlock",
317+
"CidrList",
318+
"CidrAllowList",
319+
],
320+
):
321+
if path[-2] == "properties":
322+
resource_patches.extend(
323+
_create_cidr_patch(
324+
resource_type,
325+
ref="#/" + "/".join(path),
326+
resolver=resolver,
327+
format="ipv4-network",
328+
)
329+
)
330+
331+
for path in _descend(obj, ["Ipv6CidrBlock", "Ipv6Cidrs", "CidrIpv6"]):
332+
if path[-2] == "properties":
333+
resource_patches.extend(
334+
_create_cidr_patch(
335+
resource_type,
336+
ref="#/" + "/".join(path),
337+
resolver=resolver,
338+
format="ipv6-network",
339+
)
340+
)
341+
273342
for path in _descend(obj, ["ImageId", "AmiId"]):
274343
if path[-2] == "properties":
275344
resource_patches.append(

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_clientvpnroute/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/DestinationCidrBlock/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/Cidr/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/Cidr/format",
5+
"value": "ipv4-network"
6+
}
7+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_ipampoolcidr/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/Cidr/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/DestinationCidrBlock/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/Ipv6CidrBlock/format",
10+
"value": "ipv6-network"
11+
}
12+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/AnalysisAclRule/properties/Cidr/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/AnalysisSecurityGroupRule/properties/Cidr/format",
10+
"value": "ipv4-network"
11+
},
12+
{
13+
"op": "add",
14+
"path": "/definitions/Explanation/properties/Cidrs/items/format",
15+
"value": "ipv4-network"
16+
},
17+
{
18+
"op": "add",
19+
"path": "/definitions/TransitGatewayRouteTableRoute/properties/DestinationCidr/format",
20+
"value": "ipv4-network"
21+
}
22+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/Entry/properties/Cidr/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/DestinationCidrBlock/format",
10+
"value": "ipv4-network"
11+
}
12+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_securitygroup/format.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/Egress/properties/CidrIp/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/Egress/properties/CidrIpv6/format",
10+
"value": "ipv6-network"
11+
},
212
{
313
"op": "add",
414
"path": "/definitions/Egress/properties/DestinationSecurityGroupId/format",
515
"value": "AWS::EC2::SecurityGroup.Id"
616
},
17+
{
18+
"op": "add",
19+
"path": "/definitions/Ingress/properties/CidrIp/format",
20+
"value": "ipv4-network"
21+
},
22+
{
23+
"op": "add",
24+
"path": "/definitions/Ingress/properties/CidrIpv6/format",
25+
"value": "ipv6-network"
26+
},
727
{
828
"op": "add",
929
"path": "/definitions/Ingress/properties/SourceSecurityGroupId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_securitygroupegress/format.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrIp/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/CidrIpv6/format",
10+
"value": "ipv6-network"
11+
},
212
{
313
"op": "add",
414
"path": "/properties/DestinationSecurityGroupId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_securitygroupingress/format.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrIp/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/CidrIpv6/format",
10+
"value": "ipv6-network"
11+
},
212
{
313
"op": "add",
414
"path": "/properties/GroupId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_subnet/format.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/Ipv6CidrBlock/format",
10+
"value": "ipv6-network"
11+
},
212
{
313
"op": "add",
414
"path": "/properties/SubnetId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_subnetcidrblock/format.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/Ipv6CidrBlock/format",
5+
"value": "ipv6-network"
6+
},
27
{
38
"op": "add",
49
"path": "/properties/SubnetId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_trafficmirrorfilterrule/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/DestinationCidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/SourceCidrBlock/format",
10+
"value": "ipv4-network"
11+
}
12+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/DestinationCidrBlock/format",
5+
"value": "ipv4-network"
6+
}
7+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_verifiedaccessendpoint/format.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/CidrOptions/properties/Cidr/format",
5+
"value": "ipv4-network"
6+
},
27
{
38
"op": "add",
49
"path": "/definitions/SecurityGroupId/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_vpc/format.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
27
{
38
"op": "add",
49
"path": "/properties/DefaultSecurityGroup/format",

src/cfnlint/data/schemas/patches/extensions/all/aws_ec2_vpccidrblock/format.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/properties/Ipv6CidrBlock/format",
10+
"value": "ipv6-network"
11+
},
212
{
313
"op": "add",
414
"path": "/properties/VpcId/format",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/properties/DestinationCidrBlock/format",
5+
"value": "ipv4-network"
6+
}
7+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_eks_cluster/format.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/RemoteNodeNetwork/properties/Cidrs/items/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/RemotePodNetwork/properties/Cidrs/items/format",
10+
"value": "ipv4-network"
11+
},
212
{
313
"op": "add",
414
"path": "/definitions/ResourcesVpcConfig/properties/SecurityGroupIds/format",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/NetworkAclEntry/properties/CidrBlock/format",
5+
"value": "ipv4-network"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/NetworkAclEntry/properties/Ipv6CidrBlock/format",
10+
"value": "ipv6-network"
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/Resource/properties/Cidr/format",
5+
"value": "ipv4-network"
6+
}
7+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/MetricValue/properties/Cidrs/items/format",
5+
"value": "ipv4-network"
6+
}
7+
]

0 commit comments

Comments
 (0)