forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniqueItems.py
36 lines (31 loc) · 1.23 KB
/
UniqueItems.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from cfnlint.jsonschema import ValidationError, _utils
from cfnlint.rules import CloudFormationLintRule
class UniqueItems(CloudFormationLintRule):
"""Check if duplicates exist in a List"""
id = "E3037"
shortdesc = "Check if a list has duplicate values"
description = (
"Certain lists don't support duplicate items. "
"Check when duplicates are provided but not supported."
)
source_url = "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#uniqueitems"
tags = ["resources", "property", "list"]
child_rules = {
"I3037": None,
}
# pylint: disable=unused-argument
def uniqueItems(self, validator, uI, instance, schema):
if not validator.is_type(instance, "array"):
return
if not _utils.uniq(instance):
if uI:
yield ValidationError(f"{instance!r} has non-unique elements")
elif self.child_rules["I3037"]:
yield ValidationError(
f"{instance!r} has non-unique elements",
rule=self.child_rules["I3037"],
)