-
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.
- Loading branch information
Showing
27 changed files
with
521 additions
and
381 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from cfnlint.jsonschema import Validator | ||
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema | ||
|
||
|
||
class DeploymentParameters(CfnLintJsonSchema): | ||
"""Check if Parameters are configured correctly""" | ||
|
||
id = "E2900" | ||
shortdesc = "Parameters have appropriate properties" | ||
description = "Making sure the parameters are properly configured" | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html" | ||
tags = ["parameters"] | ||
|
||
def __init__(self): | ||
"""Init""" | ||
super().__init__( | ||
keywords=["Parameters"], | ||
all_matches=True, | ||
) | ||
|
||
def _is_type_a_list(self, parameter_type: str) -> bool: | ||
return "List" in parameter_type and "CommaDelimitedList" not in parameter_type | ||
|
||
def _build_schema(self, instance: Any) -> dict[str, Any]: | ||
if not isinstance(instance, dict): | ||
return {} | ||
|
||
schema: dict[str, Any] = { | ||
"properties": {}, | ||
"additionalProperties": False, | ||
"required": [], | ||
"type": "object", | ||
} | ||
|
||
singular_types = ["string", "integer", "number", "boolean"] | ||
|
||
for parameter_name, parameter_object in instance.items(): | ||
schema["properties"][parameter_name] = {} | ||
if not isinstance(parameter_object, dict): | ||
continue | ||
if "Default" not in parameter_object: | ||
schema["required"] = [parameter_name] | ||
|
||
parameter_type = parameter_object.get("Type") | ||
if not isinstance(parameter_type, str): | ||
continue | ||
|
||
if self._is_type_a_list(parameter_type): | ||
schema["properties"][parameter_name] = { | ||
"type": "array", | ||
"items": { | ||
"type": singular_types, | ||
}, | ||
} | ||
if "AllowedValues" in parameter_object: | ||
schema["properties"][parameter_name]["items"]["enum"] = ( | ||
parameter_object["AllowedValues"] | ||
) | ||
if "Pattern" in parameter_object: | ||
if self._is_type_a_list(parameter_type): | ||
schema["properties"][parameter_name]["items"]["pattern"] = ( | ||
parameter_object["Pattern"] | ||
) | ||
else: | ||
schema["properties"][parameter_name]["type"] = singular_types | ||
if "AllowedValues" in parameter_object: | ||
schema["properties"][parameter_name]["enum"] = parameter_object[ | ||
"AllowedValues" | ||
] | ||
if "Pattern" in parameter_object: | ||
schema["properties"][parameter_name]["pattern"] = parameter_object[ | ||
"Pattern" | ||
] | ||
|
||
return schema | ||
|
||
def validate(self, validator: Validator, _: Any, instance: Any, schema: Any): | ||
if not validator.cfn.parameters: | ||
return | ||
|
||
cfn_validator = self.extend_validator( | ||
validator=validator, | ||
schema=self._build_schema(instance), | ||
context=validator.context, | ||
).evolve( | ||
context=validator.context.evolve(strict_types=False), | ||
function_filter=validator.function_filter.evolve( | ||
add_cfn_lint_keyword=False, | ||
), | ||
) | ||
|
||
for err in super()._iter_errors(cfn_validator, validator.cfn.parameters): | ||
# we use enum twice. Once for the type and once for the property | ||
# names. There are separate error numbers so we do this. | ||
if "propertyNames" in err.schema_path and "enum" in err.schema_path: | ||
err.rule = self | ||
yield err |
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
File renamed without changes.
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,15 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Any | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Deployment: | ||
|
||
template_file_path: str = field() | ||
parameters: dict[str, Any] = field(default_factory=dict) | ||
tags: dict[str, str] = field(default_factory=dict) |
10 changes: 10 additions & 0 deletions
10
src/cfnlint/runner/deployment_file/deployment_types/__init__.py
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,10 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
__all__ = ["create_deployment_from_git_sync"] | ||
|
||
from cfnlint.runner.deployment_file.deployment_types.git_sync import ( | ||
create_deployment_from_git_sync, | ||
) |
20 changes: 20 additions & 0 deletions
20
src/cfnlint/runner/deployment_file/deployment_types/git_sync.py
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,20 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from typing import Any | ||
|
||
from cfnlint.runner.deployment_file.deployment import Deployment | ||
|
||
|
||
def create_deployment_from_git_sync(data: dict[str, Any]) -> Deployment: | ||
|
||
template_file_path = data.get("template-file-path") | ||
if not template_file_path: | ||
raise ValueError("template-file-path is required") | ||
parameters = data.get("parameters", {}) | ||
tags = data.get("tags", {}) | ||
return Deployment( | ||
template_file_path=template_file_path, parameters=parameters, tags=tags | ||
) |
Oops, something went wrong.