Skip to content

Commit

Permalink
V1 Rework the last of the awsType rules (#3263)
Browse files Browse the repository at this point in the history
* Rework the last of the awsType rules
* Fix an issue with path in SnapStart
* Remove aws type and cleanup additional checks
  • Loading branch information
kddejong committed May 24, 2024
1 parent a8ce012 commit 6af0e42
Show file tree
Hide file tree
Showing 26 changed files with 472 additions and 269 deletions.
8 changes: 2 additions & 6 deletions src/cfnlint/data/schemas/other/metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
}
},
"properties": {
"AWS::CloudFormation::Interface": {
"awsType": "CfnMetadataInterface"
},
"cfn-lint": {
"awsType": "CfnMetadataCfnLint"
}
"AWS::CloudFormation::Interface": {},
"cfn-lint": {}
},
"type": "object"
}
3 changes: 0 additions & 3 deletions src/cfnlint/data/schemas/other/outputs/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"additionalProperties": false,
"properties": {
"Condition": {
"awsType": [
"CfnCondition"
],
"type": [
"string"
]
Expand Down
69 changes: 13 additions & 56 deletions src/cfnlint/data/schemas/other/resources/configuration.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
{
"additionalProperties": {
"$ref": "#/definitions/ResourceConfiguration"
},
"additionalProperties": false,
"definitions": {
"CloudFormationInitConfig": {
"properties": {
"config": {
"properties": {
"commands": {
"awsType": "CfnInitCommands"
},
"files": {
"awsType": "CfnInitFiles"
},
"groups": {
"awsType": "CfnInitGroups"
},
"packages": {
"awsType": "CfnInitPackages"
},
"services": {
"awsType": "CfnInitServices"
},
"sources": {
"awsType": "CfnInitSources"
},
"users": {
"awsType": "CfnInitUsers"
}
},
"type": "object"
}
},
"type": "object"
},
"ResourceConfiguration": {
"additionalProperties": false,
"awsType": "CfnResourceProperties",
"else": {
"not": {
"required": [
Expand All @@ -61,15 +27,12 @@
},
"properties": {
"Condition": {
"awsType": "CfnCondition",
"type": "string"
},
"CreationPolicy": {
"type": "object"
},
"DeletionPolicy": {
"awsType": "CfnDeletionPolicy"
},
"DeletionPolicy": {},
"DependsOn": {
"items": {
"type": "string"
Expand All @@ -79,19 +42,13 @@
"array"
]
},
"Metadata": {
"awsType": "CfnResourceMetadata"
},
"Metadata": {},
"Properties": {},
"Type": {
"type": "string"
},
"UpdatePolicy": {
"type": "object"
},
"UpdateReplacePolicy": {
"awsType": "CfnResourceUpdateReplacePolicy"
},
"UpdatePolicy": {},
"UpdateReplacePolicy": {},
"Version": {
"type": "string"
}
Expand All @@ -100,13 +57,9 @@
"Type"
],
"then": {
"not": {
"required": [
"CreationPolicy",
"UpdatePolicy"
]
},
"properties": {
"CreationPolicy": false,
"UpdatePolicy": false,
"Version": {
"type": "string"
}
Expand All @@ -116,9 +69,13 @@
}
},
"maxProperties": 500,
"patternProperties": {
"^[a-zA-Z0-9]+$": {
"$ref": "#/definitions/ResourceConfiguration"
}
},
"propertyNames": {
"maxLength": 255,
"pattern": "^[a-zA-Z0-9]+$"
"maxLength": 255
},
"type": "object"
}
54 changes: 13 additions & 41 deletions src/cfnlint/data/schemas/other/resources/metadata.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
{
"allOf": [
{
"type": [
"object",
"array"
]
},
{
"additionalProperties": {
"type": [
"object",
"string"
]
},
"properties": {
"AWS::CloudFormation::Init": {
"additionalProperties": true,
"properties": {
"AWS::CloudFormation::Init": {
"properties": {
"config": {
"properties": {
"commands": {
"awsType": "CfnInitCommands"
},
"files": {
"awsType": "CfnInitFiles"
},
"groups": {
"awsType": "CfnInitGroups"
},
"packages": {
"awsType": "CfnInitPackages"
},
"services": {
"awsType": "CfnInitServices"
},
"sources": {
"awsType": "CfnInitSources"
},
"users": {
"awsType": "CfnInitUsers"
}
},
"type": "object"
}
},
"type": "object"
}
},
"properties": {},
"type": "object"
}
},
"type": [
"object",
"array"
]
}
20 changes: 5 additions & 15 deletions src/cfnlint/data/schemas/other/template/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,11 @@
"Description": {
"type": "string"
},
"Mappings": {
"awsType": "CfnMappings"
},
"Metadata": {
"awsType": "CfnMetadata"
},
"Outputs": {
"awsType": "CfnOutputs"
},
"Parameters": {
"awsType": "CfnParameters"
},
"Resources": {
"awsType": "CfnResources"
},
"Mappings": {},
"Metadata": {},
"Outputs": {},
"Parameters": {},
"Resources": {},
"Rules": {
"type": "object"
},
Expand Down
2 changes: 1 addition & 1 deletion src/cfnlint/jsonschema/_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def properties(
subschema,
path=k[0] if len(k) > 0 else p,
schema_path=p,
property_path=k[0] if len(k) > 0 else p,
property_path=p,
)


Expand Down
2 changes: 2 additions & 0 deletions src/cfnlint/rules/_Rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def __repr__(self):
return f"{self.id}: {self.shortdesc}"

def __eq__(self, other):
if other is None:
return False
return self.id == other.id

@property
Expand Down
4 changes: 2 additions & 2 deletions src/cfnlint/rules/conditions/Condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class Condition(BaseFn):
tags = ["functions", "and"]

def __init__(self) -> None:
super().__init__("Fn::And", ("boolean",))
super().__init__("Condition", ("boolean",))
self.condition = self.validate

def schema(self, validator, instance) -> Dict[str, Any]:
return {
"type": "string",
"awsType": "CfnCondition",
"enum": list(validator.context.conditions.keys()),
}
41 changes: 0 additions & 41 deletions src/cfnlint/rules/jsonschema/AwsType.py

This file was deleted.

5 changes: 4 additions & 1 deletion src/cfnlint/rules/jsonschema/CfnLint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SPDX-License-Identifier: MIT-0
"""

from cfnlint.jsonschema._utils import Unset
from cfnlint.rules import CloudFormationLintRule


Expand All @@ -19,6 +20,7 @@ def cfnLint(self, validator, keywords, instance, schema):
add_cfn_lint_keyword=False,
)
)

for keyword in keywords:
for rule in self.child_rules.values():
if rule is None:
Expand All @@ -30,5 +32,6 @@ def cfnLint(self, validator, keywords, instance, schema):
if rule_keyword == keyword:
for err in rule.validate(validator, keyword, instance, schema):
if err.rule is None:
err.rule = rule
if isinstance(err.validator, Unset):
err.rule = rule
yield err
8 changes: 4 additions & 4 deletions src/cfnlint/rules/jsonschema/CfnLintJsonSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from cfnlint.helpers import load_resource
from cfnlint.jsonschema import ValidationError
from cfnlint.jsonschema._keywords import type
from cfnlint.jsonschema.exceptions import best_match
from cfnlint.rules.jsonschema.Base import BaseJsonSchema

Expand Down Expand Up @@ -38,8 +37,6 @@ def __init__(
)
self._use_schema_arg = False

self.validators["type"] = type

@property
def schema(self):
return self._schema
Expand Down Expand Up @@ -70,7 +67,10 @@ def validate(self, validator, keywords, instance, schema):
cfn_validator = self.extend_validator(
validator=validator,
schema=schema,
context=validator.context.evolve(functions=[]),
context=validator.context.evolve(
functions=[],
strict_types=True,
),
)

yield from self._iter_errors(cfn_validator, instance)
4 changes: 2 additions & 2 deletions src/cfnlint/rules/jsonschema/JsonSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cfnlint.data.schemas.other import template as schema_template
from cfnlint.helpers import load_resource
from cfnlint.jsonschema import CfnTemplateValidator
from cfnlint.jsonschema._keywords_cfn import cfn_type
from cfnlint.rules.jsonschema.Base import BaseJsonSchema
from cfnlint.template import Template

Expand All @@ -27,7 +28,6 @@ def __init__(self):
"""Init"""
super().__init__()
self.rule_set = {
"awsType": "E1100",
"cfnLint": "E1101",
"condition": "E8007",
"dynamicReference": "E1050",
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self):
self.config_definition = {"sections": {"default": "", "type": "string"}}
self.configure()
self.validators = {
"awsType": None,
"type": cfn_type,
}

@property
Expand Down
Loading

0 comments on commit 6af0e42

Please sign in to comment.