-
Notifications
You must be signed in to change notification settings - Fork 598
/
Join.py
90 lines (79 loc) · 2.84 KB
/
Join.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
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 ValidationResult
from cfnlint.jsonschema.protocols import Validator
from cfnlint.rules.functions._BaseFn import BaseFn
class Join(BaseFn):
"""Check if Join values are correct"""
id = "E1022"
shortdesc = "Join validation of parameters"
description = "Making sure the join function is properly configured"
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html"
tags = ["functions", "join"]
def __init__(self) -> None:
super().__init__("Fn::Join", ("string",), resolved_rule="W1032")
self.child_rules.update(
{
"I1022": None,
}
)
def schema(self, validator, instance) -> dict[str, Any]:
return {
"type": "array",
"maxItems": 2,
"minItems": 2,
"fn_items": [
{
"schema": {
"type": ["string"],
},
},
{
"functions": [
"Fn::Cidr",
"Fn::FindInMap",
"Fn::GetAtt",
"Fn::If",
"Fn::Split",
"Ref",
],
"schema": {
"type": ["array"],
"fn_items": {
"functions": [
"Fn::Base64",
"Fn::FindInMap",
"Fn::GetAtt",
"Fn::If",
"Fn::ImportValue",
"Fn::Join",
"Fn::Select",
"Fn::Sub",
"Fn::Transform",
"Ref",
],
"schema": {
"type": ["string"],
},
},
},
},
],
}
def fn_join(
self, validator: Validator, s: Any, instance: Any, schema: Any
) -> ValidationResult:
validator = validator.evolve(
context=validator.context.evolve(strict_types=True)
)
errs = list(super().validate(validator, s, instance, schema))
if errs:
yield from iter(errs)
for rule in self.child_rules.values():
if rule is None or not hasattr(rule, "validate"):
continue
yield from rule.validate(validator, s, instance, schema)