Skip to content

Commit

Permalink
Update E3046 to support format keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Jan 17, 2025
1 parent 08284a8 commit 769074b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/format_keyword.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ This format validates that the value is a valid Security Group Name, which must
### AWS::EC2::Image.Id

This format validates that the value is a valid Amazon Machine Image (AMI), which is a string of the pattern `ami-[0-9a-f]{8}` or `ami-[0-9a-f]{17}`. More info in [docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/resource-ids.html)

### AWS::Logs::LogGroup.Name

This format validates that the value is a valid log group name, which is a string of the pattern `^[\.\-_\/#A-Za-z0-9]{1,512}\Z`. More info in [docs](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_LogGroup.html)
21 changes: 17 additions & 4 deletions src/cfnlint/rules/functions/GetAttFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,20 @@ def validate(
getatt_schema = resource_schema.resolver.resolve_cfn_pointer(getatt_ptr)
getatt_fmt = getatt_schema.get("format")
if getatt_fmt != fmt:
yield ValidationError(
f"{{'Fn::GetAtt': {instance!r}}} that does not match {fmt!r}",
rule=self,
)
if getatt_fmt is None:
yield ValidationError(
(
f"{{'Fn::GetAtt': {instance!r}}} does not match "
f"destination format of {fmt!r}"
),
rule=self,
)
else:
yield ValidationError(

Check warning on line 76 in src/cfnlint/rules/functions/GetAttFormat.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/rules/functions/GetAttFormat.py#L76

Added line #L76 was not covered by tests
(
f"{{'Fn::GetAtt': {instance!r}}} with format "
f"{getatt_fmt!r} does not "
f"match destination format of {fmt!r}"
),
rule=self,
)
24 changes: 23 additions & 1 deletion src/cfnlint/rules/resources/ecs/LogConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from __future__ import annotations

from typing import Sequence
from typing import Any, Sequence

import cfnlint.data.schemas.extensions.aws_ecs_taskdefinition
from cfnlint.jsonschema import ValidationResult, Validator
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails


Expand All @@ -32,3 +33,24 @@ def __init__(
),
all_matches=True,
)

def validate(
self, validator: Validator, keywords: Any, instance: Any, schema: dict[str, Any]
) -> ValidationResult:
# if the schema has a description will only replace the message with that
# description and use the best error for the location information
if not self._use_schema_arg:
schema = self._schema

cfn_validator = self.extend_validator(
validator=validator.evolve(
function_filter=validator.function_filter.evolve(
validate_dynamic_references=False,
add_cfn_lint_keyword=False,
)
),
schema=schema,
context=validator.context.evolve(),
)

yield from self._iter_errors(cfn_validator, instance)
4 changes: 2 additions & 2 deletions test/unit/rules/functions/test_getatt_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def template():
[
ValidationError(
(
"{'Fn::GetAtt': ['MyBucket', 'Arn']} that "
"does not match 'AWS::EC2::VPC.Id'"
"{'Fn::GetAtt': ['MyBucket', 'Arn']} "
"does not match destination format of 'AWS::EC2::VPC.Id'"
),
rule=GetAttFormat(),
)
Expand Down

0 comments on commit 769074b

Please sign in to comment.