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

+63-33
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

+23
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

+5
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.
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+
]
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

+29
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
]
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

+5
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

+5
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",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/CertificateBasedAuthProperties/properties/Status/enum",
5+
"value": [
6+
"DISABLED",
7+
"ENABLED",
8+
"ENABLED_NO_DIRECTORY_LOGIN_FALLBACK"
9+
]
10+
},
11+
{
12+
"op": "add",
13+
"path": "/definitions/CertificateBasedAuthProperties/properties/CertificateAuthorityArn/pattern",
14+
"value": "^arn:aws(?:\\-cn|\\-iso\\-b|\\-iso|\\-us\\-gov)?:[A-Za-z0-9][A-Za-z0-9_/.-]{0,62}:[A-Za-z0-9_/.-]{0,63}:[A-Za-z0-9_/.-]{0,63}:[A-Za-z0-9][A-Za-z0-9:_/+=,@.\\\\-]{0,1023}$"
15+
}
16+
]

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

+14
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,19 @@
1717
"op": "add",
1818
"path": "/properties/Name/pattern",
1919
"value": "[_A-Za-z][_0-9A-Za-z]*"
20+
},
21+
{
22+
"op": "add",
23+
"path": "/definitions/AuthorizationConfig/properties/AuthorizationType/enum",
24+
"value": [
25+
"AWS_IAM"
26+
]
27+
},
28+
{
29+
"op": "add",
30+
"path": "/definitions/RelationalDatabaseConfig/properties/RelationalDatabaseSourceType/enum",
31+
"value": [
32+
"RDS_HTTP_ENDPOINT"
33+
]
2034
}
2135
]

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

+25
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,30 @@
88
"op": "add",
99
"path": "/properties/DataSourceName/pattern",
1010
"value": "[_A-Za-z][_0-9A-Za-z]*"
11+
},
12+
{
13+
"op": "add",
14+
"path": "/definitions/SyncConfig/properties/ConflictHandler/enum",
15+
"value": [
16+
"AUTOMERGE",
17+
"LAMBDA",
18+
"NONE",
19+
"OPTIMISTIC_CONCURRENCY"
20+
]
21+
},
22+
{
23+
"op": "add",
24+
"path": "/definitions/SyncConfig/properties/ConflictDetection/enum",
25+
"value": [
26+
"NONE",
27+
"VERSION"
28+
]
29+
},
30+
{
31+
"op": "add",
32+
"path": "/definitions/AppSyncRuntime/properties/Name/enum",
33+
"value": [
34+
"APPSYNC_JS"
35+
]
1136
}
1237
]

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

+25
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,30 @@
2121
"PIPELINE",
2222
"UNIT"
2323
]
24+
},
25+
{
26+
"op": "add",
27+
"path": "/definitions/SyncConfig/properties/ConflictHandler/enum",
28+
"value": [
29+
"AUTOMERGE",
30+
"LAMBDA",
31+
"NONE",
32+
"OPTIMISTIC_CONCURRENCY"
33+
]
34+
},
35+
{
36+
"op": "add",
37+
"path": "/definitions/SyncConfig/properties/ConflictDetection/enum",
38+
"value": [
39+
"NONE",
40+
"VERSION"
41+
]
42+
},
43+
{
44+
"op": "add",
45+
"path": "/definitions/AppSyncRuntime/properties/Name/enum",
46+
"value": [
47+
"APPSYNC_JS"
48+
]
2449
}
2550
]

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

+5
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"op": "add",
44
"path": "/definitions/AssessmentDescription/pattern",
55
"value": "^[\\w\\W\\s\\S]*$"
6+
},
7+
{
8+
"op": "add",
9+
"path": "/definitions/S3Url/pattern",
10+
"value": "^(S|s)3:\\/\\/[a-zA-Z0-9\\-\\.\\(\\)\\'\\*\\_\\!\\/]+$"
611
}
712
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"op": "add",
4+
"path": "/definitions/LaunchTemplateSpecification/properties/LaunchTemplateName/pattern",
5+
"value": "[a-zA-Z0-9\\(\\)\\.\\-/_]+"
6+
}
7+
]

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

+16
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,21 @@
1111
"st1",
1212
"standard"
1313
]
14+
},
15+
{
16+
"op": "add",
17+
"path": "/definitions/MetadataOptions/properties/HttpTokens/enum",
18+
"value": [
19+
"optional",
20+
"required"
21+
]
22+
},
23+
{
24+
"op": "add",
25+
"path": "/definitions/MetadataOptions/properties/HttpEndpoint/enum",
26+
"value": [
27+
"disabled",
28+
"enabled"
29+
]
1430
}
1531
]

0 commit comments

Comments
 (0)