File size: 1,711 Bytes
b40c49c | 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 | """
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 FUNCTIONS
from cfnlint.jsonschema import Validator
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema
class Value(CfnLintJsonSchema):
"""Check if Outputs have string values"""
id = "E6101"
shortdesc = "Validate that outputs values are a string"
description = "Make sure that output values have a type of string"
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html"
tags = ["outputs"]
def __init__(self):
super().__init__(
keywords=["Outputs/*"],
all_matches=True,
)
def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
key = "Value"
value = instance.get(key)
if not value:
return
conditions = {}
condition = instance.get("Condition")
if condition:
conditions = {condition: True}
validator = validator.evolve(
context=validator.context.evolve(
functions=list(FUNCTIONS),
conditions=validator.context.conditions.evolve(
conditions,
),
strict_types=False,
)
)
for err in validator.descend(
value,
schema={
"type": ["string"],
},
path=key,
property_path=key,
):
if err.rule is None:
err.rule = self
yield err
|