-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Even more appropriate dynamic references (#3071)
- Loading branch information
Showing
13 changed files
with
521 additions
and
230 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
38 changes: 38 additions & 0 deletions
38
src/cfnlint/rules/functions/DynamicReferenceSecretsManagerPath.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,38 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from typing import Any | ||
|
||
from cfnlint.jsonschema import ValidationError, Validator | ||
from cfnlint.rules import CloudFormationLintRule | ||
|
||
|
||
class DynamicReferenceSecretsManagerPath(CloudFormationLintRule): | ||
id = "E1051" | ||
shortdesc = ( | ||
"Validate dynamic references to secrets manager are only in resource properties" | ||
) | ||
description = ( | ||
"Dynamic references from secrets manager can only be used " | ||
"in resource properties" | ||
) | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-secretsmanager" | ||
tags = ["functions", "dynamic reference"] | ||
|
||
def validate(self, validator: Validator, s: Any, instance: Any, schema: Any): | ||
if len(validator.context.path) >= 3: | ||
if ( | ||
validator.context.path[0] == "Resources" | ||
and validator.context.path[2] == "Properties" | ||
): | ||
return | ||
|
||
yield ValidationError( | ||
( | ||
f"Dynamic reference {instance!r} to secrets manager can only be " | ||
"used in resource properties" | ||
), | ||
rule=self, | ||
) |
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,40 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from typing import Any | ||
|
||
from cfnlint.jsonschema import ValidationError, Validator | ||
from cfnlint.rules import CloudFormationLintRule | ||
|
||
|
||
class DynamicReferenceSsmPath(CloudFormationLintRule): | ||
id = "E1052" | ||
shortdesc = "Validate dynamic references to SSM are in a valid location" | ||
description = ( | ||
"Dynamic references to SSM parameters are only supported " | ||
"in certain locations" | ||
) | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-ssm" | ||
tags = ["functions", "dynamic reference"] | ||
|
||
def validate(self, validator: Validator, s: Any, instance: Any, schema: Any): | ||
if len(validator.context.path) > 0: | ||
if validator.context.path[0] == "Parameters": | ||
if len(validator.context.path) >= 3: | ||
if validator.context.path[2] in ["Default", "AllowedValues"]: | ||
return | ||
elif validator.context.path[0] == "Resources": | ||
if len(validator.context.path) >= 3: | ||
if validator.context.path[2] in ["Properties", "Metadata"]: | ||
return | ||
elif validator.context.path[0] == "Outputs": | ||
if len(validator.context.path) >= 3: | ||
if validator.context.path[2] in ["Value"]: | ||
return | ||
|
||
yield ValidationError( | ||
(f"Dynamic reference {instance!r} to SSM parameters are not allowed here"), | ||
rule=self, | ||
) |
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
40 changes: 0 additions & 40 deletions
40
test/fixtures/templates/bad/functions/dynamic_reference.yaml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.