-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Transform section to have the full transform def (#3470)
* Allow Transform section to have the full transform def * Switch transform validation to rule E1005
- Loading branch information
Showing
12 changed files
with
177 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
38 changes: 38 additions & 0 deletions
38
src/cfnlint/data/schemas/other/transforms/configuration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"additionalProperties": false, | ||
"items": { | ||
"$ref": "#/", | ||
"type": [ | ||
"string", | ||
"object" | ||
] | ||
}, | ||
"properties": { | ||
"Name": { | ||
"type": "string" | ||
}, | ||
"Parameters": { | ||
"patternProperties": { | ||
".*": { | ||
"type": [ | ||
"string", | ||
"array", | ||
"boolean", | ||
"object", | ||
"number", | ||
"integer" | ||
] | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"Name" | ||
], | ||
"type": [ | ||
"string", | ||
"array", | ||
"object" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import cfnlint.data.schemas.other.transforms | ||
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails | ||
|
||
|
||
class Configuration(CfnLintJsonSchema): | ||
"""Check if Parameters are configured correctly""" | ||
|
||
id = "E1005" | ||
shortdesc = "Validate Transform configuration" | ||
description = ( | ||
"Validate that the transforms section of a template is properly configured" | ||
) | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html" | ||
tags = ["transform"] | ||
|
||
def __init__(self): | ||
"""Init""" | ||
super().__init__( | ||
keywords=["Transform"], | ||
schema_details=SchemaDetails( | ||
cfnlint.data.schemas.other.transforms, "configuration.json" | ||
), | ||
all_matches=True, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from collections import deque | ||
|
||
import pytest | ||
|
||
from cfnlint.jsonschema import ValidationError | ||
from cfnlint.rules.transforms.Configuration import Configuration | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rule(): | ||
rule = Configuration() | ||
yield rule | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,instance,expected", | ||
[ | ||
( | ||
"Empty list is ok", | ||
[], | ||
[], | ||
), | ||
( | ||
"String is ok", | ||
"Foo", | ||
[], | ||
), | ||
( | ||
"List is ok", | ||
["Foo", "Bar"], | ||
[], | ||
), | ||
( | ||
"Object is ok", | ||
{"Name": "Foo", "Parameters": {"Bar": "Test"}}, | ||
[], | ||
), | ||
( | ||
"Array of objects is ok", | ||
[ | ||
{"Name": "Foo", "Parameters": {"Bar": "Test"}}, | ||
"Foo", | ||
], | ||
[], | ||
), | ||
( | ||
"Missing required Name", | ||
{"Parameters": {"Bar": "Test"}}, | ||
[ | ||
ValidationError( | ||
"'Name' is a required property", | ||
validator="required", | ||
rule=Configuration(), | ||
path=deque([]), | ||
schema_path=deque(["required"]), | ||
) | ||
], | ||
), | ||
( | ||
"No additional property names are allowed", | ||
{"Name": "Foo", "Foo": "Bar", "Parameters": {"Bar": "Test"}}, | ||
[ | ||
ValidationError( | ||
"Additional properties are not allowed ('Foo' was unexpected)", | ||
validator="additionalProperties", | ||
rule=Configuration(), | ||
path=deque(["Foo"]), | ||
schema_path=deque(["additionalProperties"]), | ||
) | ||
], | ||
), | ||
( | ||
"Null is not ok", | ||
None, | ||
[ | ||
ValidationError( | ||
"None is not of type 'string', 'array', 'object'", | ||
validator="type", | ||
rule=Configuration(), | ||
path=deque([]), | ||
schema_path=deque(["type"]), | ||
) | ||
], | ||
), | ||
], | ||
) | ||
def test_validate(name, instance, expected, rule, validator): | ||
errs = list(rule.validate(validator, {}, instance, {})) | ||
|
||
assert errs == expected, f"Test {name!r} got {errs!r}" |