Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 - Increase code coverage #2586

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"Type": {
"type": "string",
"cfnType": true
"awsType": true
},
"UpdateReplacePolicy": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"aws-autoscaling-autoscalinggroup/onlyone"
]
},
{
"op": "add",
"path": "/properties/AvailabilityZones/awsType",
"value": "AvailabilityZones"
},
{
"op": "add",
"path": "/properties/AvailabilityZones/items/awsType",
"value": "AvailabilityZone"
},
{
"op": "add",
"path": "/definitions/LaunchTemplateSpecification/cfnSchema",
Expand Down
12 changes: 12 additions & 0 deletions src/cfnlint/data/ExtendedProviderSchema/all/aws-dax-cluster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZones/awsType",
"value": "AvailabilityZones"
},
{
"op": "add",
"path": "/properties/AvailabilityZones/items/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
7 changes: 7 additions & 0 deletions src/cfnlint/data/ExtendedProviderSchema/all/aws-ec2-host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
"aws-ec2-instance/blockdevicemapping-virtualname-exclusive",
"aws-ec2-instance/blockdevicemapping-onlyone"
]
},
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"op": "add",
"path": "/definitions/BlockDeviceMapping/cfnSchema",
"value": ["aws-ec2-launchtemplate/blockdevicemapping-virtualname"]
},
{
"op": "add",
"path": "/definitions/Placement/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
10 changes: 10 additions & 0 deletions src/cfnlint/data/ExtendedProviderSchema/all/aws-ec2-spotfleet.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@
"op": "add",
"path": "/definitions/SpotFleetRequestConfigData/cfnSchema",
"value": ["aws-ec2-spotfleet/spotfleetrequestconfigdata-onlyone"]
},
{
"op": "add",
"path": "/definitions/LaunchTemplateOverrides/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
},
{
"op": "add",
"path": "/definitions/SpotPlacement/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"op": "add",
"path": "/properties/AvailabilityZones/awsType",
"value": "AvailabilityZones"
},
{
"op": "add",
"path": "/properties/AvailabilityZones/items/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/definitions/TargetDescription/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/definitions/PlacementType/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "add",
"path": "/definitions/PhysicalConnectionRequirements/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"aws-opsworks-instance/blockdevicemapping-virtualname",
"aws-opsworks-instance/blockdevicemapping-onlyone"
]
},
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
]
10 changes: 10 additions & 0 deletions src/cfnlint/data/ExtendedProviderSchema/all/aws-rds-dbcluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
"aws-rds-dbcluster/snapshotidentifier-exclusive",
"aws-rds-dbcluster/serverless-exclusive"
]
},
{
"op": "add",
"path": "/properties/AvailabilityZones/awsType",
"value": "AvailabilityZones"
},
{
"op": "add",
"path": "/properties/AvailabilityZones/items/awsType",
"value": "AvailabilityZone"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"aws-rds-dbinstance/sourcedbinstanceidentifier-exclusive",
"aws-rds-dbinstance/aurora-exclusive"
]
},
{
"op": "add",
"path": "/properties/AvailabilityZone/awsType",
"value": "AvailabilityZone"
}
]
10 changes: 7 additions & 3 deletions src/cfnlint/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@
FUNCTION_NOT = "Fn::Not"
FUNCTION_EQUALS = "Fn::Equals"

PSEUDOPARAMS = [
PSEUDOPARAMS_SINGLE = [
"AWS::AccountId",
"AWS::NotificationARNs",
"AWS::NoValue",
"AWS::Partition",
"AWS::Region",
"AWS::StackId",
"AWS::StackName",
"AWS::URLSuffix",
]

PSEUDOPARAMS_MULTIPLE = [
"AWS::NotificationARNs",
]

PSEUDOPARAMS = ["AWS::NoValue"] + PSEUDOPARAMS_SINGLE + PSEUDOPARAMS_MULTIPLE

LIMITS = {
"Mappings": {"number": 200, "attributes": 200, "name": 255}, # in characters
"Outputs": {
Expand Down
8 changes: 8 additions & 0 deletions src/cfnlint/jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ class Unset:

def __repr__(self):
return "<unset>"


def unbool(element, true=object(), false=object()):
if element is True:
return true
if element is False:
return false
return element
2 changes: 1 addition & 1 deletion src/cfnlint/jsonschema/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
equal,
extras_msg,
find_additional_properties,
unbool,
uniq,
)

from cfnlint.jsonschema._utils import unbool
from cfnlint.jsonschema.exceptions import ValidationError


Expand Down
13 changes: 3 additions & 10 deletions src/cfnlint/rules/functions/GetAtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from jsonschema.exceptions import best_match
from jsonschema.validators import extend

from cfnlint.jsonschema import ValidationError
from cfnlint.jsonschema import ValidationError, _utils
from cfnlint.rules import CloudFormationLintRule, RuleMatch
from cfnlint.template import Template

Expand All @@ -26,19 +26,12 @@ class GetAtt(CloudFormationLintRule):
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html"
tags = ["functions", "getatt"]

def _unbool(self, element, true=object(), false=object()):
if element is True:
return true
if element is False:
return false
return element

# pylint: disable=unused-argument
def _enum(self, validator, enums, instance, schema):
enums.sort()
if instance in (0, 1):
unbooled = self._unbool(instance)
if all(unbooled != self._unbool(each) for each in enums):
unbooled = _utils.unbool(instance)
if all(unbooled != _utils.unbool(each) for each in enums):
yield ValidationError(f"{instance!r} is not one of {enums!r}")
elif instance not in enums:
if validator.is_type(instance, "string"):
Expand Down
4 changes: 2 additions & 2 deletions src/cfnlint/rules/resources/Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
self.regions = []
self.validator = create_validator(
validators={
"cfnType": self._cfnType,
"awsType": self._awsType,
},
cfn=None,
rules=None,
Expand All @@ -38,7 +38,7 @@ def initialize(self, cfn):
self.regions = cfn.regions

# pylint: disable=unused-argument
def _cfnType(self, validator, iT, instance, schema):
def _awsType(self, validator, iT, instance, schema):
if not validator.is_type(instance, "string"):
return
for region in self.regions:
Expand Down
13 changes: 3 additions & 10 deletions src/cfnlint/rules/resources/properties/AllowedValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from cfnlint.jsonschema import ValidationError
from cfnlint.jsonschema import ValidationError, _utils
from cfnlint.rules import CloudFormationLintRule


Expand All @@ -18,13 +18,6 @@ class AllowedValue(CloudFormationLintRule):
"W2030": None,
}

def _unbool(self, element, true=object(), false=object()):
if element is True:
return true
if element is False:
return false
return element

# pylint: disable=unused-argument
def enum(self, validator, enums, instance, schema):
if isinstance(instance, dict):
Expand All @@ -34,8 +27,8 @@ def enum(self, validator, enums, instance, schema):
yield from self.child_rules["W2030"].validate(v, enums)
return
if instance in (0, 1):
unbooled = self._unbool(instance)
if all(unbooled != self._unbool(each) for each in enums):
unbooled = _utils.unbool(instance)
if all(unbooled != _utils.unbool(each) for each in enums):
yield ValidationError(f"{instance!r} is not one of {enums!r}")
elif instance not in enums:
yield ValidationError(f"{instance!r} is not one of {enums!r}")
Loading