Skip to content

Commit c08fccc

Browse files
authored
Expand boto auto detection to include sub properties (#3763)
* Add boto subproperty logic
1 parent 1b42200 commit c08fccc

File tree

295 files changed

+6528
-33
lines changed

Some content is hidden

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

295 files changed

+6528
-33
lines changed

scripts/boto/_automated_patches.py

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from _types import AllPatches, Patch, ResourcePatches
1111

12+
from cfnlint.schema.resolver import RefResolver
13+
1214
skip = [
1315
"account",
1416
"chime",
@@ -90,12 +92,63 @@ def get_last_date(service_dir: Path) -> str:
9092
return last_date
9193

9294

95+
def _nested_objects(
96+
resolver: RefResolver,
97+
schema_data: dict[str, Any],
98+
boto_data: dict[str, Any],
99+
shape_data: dict[str, Any],
100+
start_path: str,
101+
source: list[str],
102+
):
103+
results = {}
104+
for member, member_data in shape_data.get("members", {}).items():
105+
for p_name, p_data in schema_data.get("properties", {}).items():
106+
if p_name in skip_property_names:
107+
continue
108+
if p_name.lower() == member.lower():
109+
110+
path = f"{start_path}/properties/{p_name}"
111+
112+
while True:
113+
if "$ref" not in p_data:
114+
break
115+
path = p_data["$ref"][1:]
116+
p_data = resolver.resolve_from_url(p_data["$ref"])
117+
118+
# skip if we already have an enum or pattern
119+
if any([p_data.get(field) for field in _fields]):
120+
continue
121+
122+
member_shape_name = member_data.get("shape")
123+
member_shape = boto_data.get("shapes", {}).get(member_shape_name, {})
124+
125+
if member_shape.get("type") == "structure":
126+
if p_data.get("type") == "object":
127+
results.update(
128+
_nested_objects(
129+
resolver, p_data, boto_data, member_shape, path, source
130+
)
131+
)
132+
133+
if not any([member_shape.get(field) for field in _fields]):
134+
continue
135+
136+
results[path] = Patch(
137+
source=source,
138+
shape=member_shape_name,
139+
)
140+
141+
return results
142+
143+
93144
def _per_resource_patch(
94145
schema_data: dict[str, Any], boto_data: dict[str, Any], source: list[str]
95146
) -> ResourcePatches:
96147
results: ResourcePatches = {}
97148
create_operations = get_schema_create_operations(schema_data)
98149
shapes = {}
150+
151+
resolver = RefResolver.from_schema(schema_data)
99152
for create_operation in create_operations:
100153
shapes.update(get_shapes(boto_data, create_operation))
101154
create_shape = (
@@ -105,39 +158,16 @@ def _per_resource_patch(
105158
.get("shape")
106159
)
107160

108-
for member, member_data in (
109-
boto_data.get("shapes", {}).get(create_shape, {}).get("members", {}).items()
110-
):
111-
for p_name, p_data in schema_data.get("properties", {}).items():
112-
if p_name in skip_property_names:
113-
continue
114-
if p_name.lower() == member.lower():
115-
116-
path = f"/properties/{p_name}"
117-
118-
if "$ref" in p_data:
119-
pointer = p_data["$ref"].split("/")
120-
p_data = schema_data.get(pointer[1], {}).get(pointer[2], {})
121-
if not p_data:
122-
continue
123-
path = f"/{'/'.join(pointer[1:])}"
124-
125-
# skip if we already have an enum or pattern
126-
if any([p_data.get(field) for field in _fields]):
127-
continue
128-
129-
member_shape_name = member_data.get("shape")
130-
member_shape = boto_data.get("shapes", {}).get(
131-
member_shape_name, {}
132-
)
133-
134-
if not any([member_shape.get(field) for field in _fields]):
135-
continue
136-
137-
results[path] = Patch(
138-
source=source,
139-
shape=member_shape_name,
140-
)
161+
results.update(
162+
_nested_objects(
163+
resolver,
164+
schema_data,
165+
boto_data,
166+
boto_data.get("shapes", {}).get(create_shape, {}),
167+
"",
168+
source,
169+
)
170+
)
141171

142172
return results
143173

src/cfnlint/data/schemas/patches/extensions/all/aws_acmpca_certificateauthority/boto.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/CrlConfiguration/properties/CustomCname/pattern",
5+
"value": "[-a-zA-Z0-9;/?:@&=+$,%_.!~*()']*"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/CrlConfiguration/properties/S3BucketName/pattern",
10+
"value": "[-a-zA-Z0-9._/]+"
11+
},
12+
{
13+
"op": "add",
14+
"path": "/definitions/CrlConfiguration/properties/S3ObjectAcl/enum",
15+
"value": [
16+
"BUCKET_OWNER_FULL_CONTROL",
17+
"PUBLIC_READ"
18+
]
19+
},
20+
{
21+
"op": "add",
22+
"path": "/definitions/OcspConfiguration/properties/OcspCustomCname/pattern",
23+
"value": "[-a-zA-Z0-9;/?:@&=+$,%_.!~*()']*"
24+
},
225
{
326
"op": "add",
427
"path": "/properties/KeyStorageSecurityStandard/enum",

src/cfnlint/data/schemas/patches/extensions/all/aws_amplify_app/boto.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"op": "add",
44
"path": "/properties/AccessToken/pattern",
55
"value": "(?s).+"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/AutoBranchCreationConfig/properties/BuildSpec/pattern",
10+
"value": "(?s).+"
611
}
712
]

src/cfnlint/data/schemas/patches/extensions/all/aws_amplify_branch/__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": "/definitions/Backend/properties/StackArn/pattern",
5+
"value": "^arn:aws:cloudformation:[a-z0-9-]+:\\d{12}:stack/.+/.+$"
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": "/definitions/ConnectorOAuthRequest/properties/AuthCode/pattern",
5+
"value": "\\S+"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/ConnectorOAuthRequest/properties/RedirectUri/pattern",
10+
"value": "\\S+"
11+
}
12+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_applicationautoscaling_scalingpolicy/boto.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,34 @@
9494
"StepScaling",
9595
"TargetTrackingScaling"
9696
]
97+
},
98+
{
99+
"op": "add",
100+
"path": "/definitions/StepScalingPolicyConfiguration/properties/AdjustmentType/enum",
101+
"value": [
102+
"ChangeInCapacity",
103+
"ExactCapacity",
104+
"PercentChangeInCapacity"
105+
]
106+
},
107+
{
108+
"op": "add",
109+
"path": "/definitions/StepScalingPolicyConfiguration/properties/MetricAggregationType/enum",
110+
"value": [
111+
"Average",
112+
"Maximum",
113+
"Minimum"
114+
]
115+
},
116+
{
117+
"op": "add",
118+
"path": "/definitions/CustomizedMetricSpecification/properties/Statistic/enum",
119+
"value": [
120+
"Average",
121+
"Maximum",
122+
"Minimum",
123+
"SampleCount",
124+
"Sum"
125+
]
97126
}
98127
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/CodeConfigurationValues/properties/BuildCommand/pattern",
5+
"value": "[^\\x0a\\x0d]+"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/CodeConfigurationValues/properties/StartCommand/pattern",
10+
"value": "[^\\x0a\\x0d]+"
11+
},
12+
{
13+
"op": "add",
14+
"path": "/definitions/ImageConfiguration/properties/StartCommand/pattern",
15+
"value": "[^\\x0a\\x0d]+"
16+
}
17+
]

src/cfnlint/data/schemas/patches/extensions/all/aws_appstream_appblock/boto.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"path": "/properties/Name/pattern",
55
"value": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$"
66
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/S3Location/properties/S3Bucket/pattern",
10+
"value": "^[0-9a-z\\.\\-]*(?<!\\.)$"
11+
},
712
{
813
"op": "add",
914
"path": "/definitions/PackagingType/enum",

src/cfnlint/data/schemas/patches/extensions/all/aws_appstream_application/boto.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"path": "/properties/Name/pattern",
55
"value": "^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$"
66
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/S3Location/properties/S3Bucket/pattern",
10+
"value": "^[0-9a-z\\.\\-]*(?<!\\.)$"
11+
},
712
{
813
"op": "add",
914
"path": "/definitions/Arn/pattern",

0 commit comments

Comments
 (0)