-
Notifications
You must be signed in to change notification settings - Fork 594
/
ToJsonString.py
76 lines (65 loc) · 2.34 KB
/
ToJsonString.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
"""
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.helpers import PSEUDOPARAMS
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
from cfnlint.rules.functions._BaseFn import BaseFn
class ToJsonString(BaseFn):
"""Check if ToJsonString values are correct"""
id = "E1031"
shortdesc = "ToJsonString validation of parameters"
description = "Making sure Fn::ToJsonString is configured correctly"
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html"
tags = ["functions", "toJsonString"]
def __init__(self) -> None:
super().__init__(
"Fn::ToJsonString",
("string",),
(
"Fn::FindInMap",
"Fn::GetAtt",
"Fn::GetAZs",
"Fn::If",
"Fn::Select",
"Fn::Split",
"Ref",
),
resolved_rule="W1040",
)
def schema(self, validator: Validator, instance: Any) -> dict[str, Any]:
return {
"type": ["array", "object"],
"minItems": 1,
"minProperties": 1,
}
def validator(self, validator: Validator) -> Validator:
return validator.evolve(
context=validator.context.evolve(
functions=self.functions,
pseudo_parameters=set(
[sp for sp in PSEUDOPARAMS if sp != "AWS::NotificationARNs"]
),
),
function_filter=validator.function_filter.evolve(
add_cfn_lint_keyword=False,
),
)
def fn_tojsonstring(
self, validator: Validator, s: Any, instance: Any, schema: Any
) -> ValidationResult:
if not validator.context.transforms.has_language_extensions_transform():
yield ValidationError(
(
f"{self.fn.name} is not supported without "
"'AWS::LanguageExtensions' transform"
),
validator=self.fn.py,
rule=self,
)
return
for err in super().validate(validator, s, instance, schema):
err.rule = self
yield err