1515from rpdk .core .exceptions import FragmentValidationError
1616
1717from .lint_warning_printer import print_cfn_lint_warnings
18- from .module_fragment_reader import get_template_file_size_in_bytes , read_raw_fragments
18+ from .module_fragment_reader import read_raw_fragments
1919
2020LOG = logging .getLogger (__name__ )
2121FRAGMENT_DIR = "fragments"
2222SAMPLE_FRAGMENT_OUTPUT = "sample.json"
2323SCHEMA_NAME = "schema.json"
2424SAMPLE_FRAGMENT = "../data/examples/module/sample.json"
25- RESOURCE_LIMIT = 500
26- OUTPUT_LIMIT = 200
27- MAPPING_LIMIT = 200
28- MAPPING_ATTRIBUTE_LIMIT = 200
29- TEMPLATE_FILE_SIZE_IN_BYTES_LIMIT = 1500000
3025
3126
3227class TemplateFragment : # pylint: disable=too-many-instance-attributes
3328 def __init__ (self , type_name , root = None ):
3429 self .root = Path (root ) if root else Path .cwd ()
3530 self .fragment_dir = self .root / FRAGMENT_DIR
3631 self .type_name = type_name
37- self .resource_limit = RESOURCE_LIMIT
38- self .output_limit = OUTPUT_LIMIT
39- self .mapping_limit = MAPPING_LIMIT
40- self .mapping_attribute_limit = MAPPING_ATTRIBUTE_LIMIT
41- self .template_file_size_in_bytes_limit = TEMPLATE_FILE_SIZE_IN_BYTES_LIMIT
4232
4333 LOG .debug ("Fragment directory: %s" , self .fragment_dir )
4434
@@ -69,17 +59,13 @@ def validate_fragments(self):
6959 since it can occur anywhere in the template.
7060 """
7161 raw_fragments = read_raw_fragments (self .fragment_dir )
72- self .__validate_file_size_limit ()
7362 self .__validate_resources (raw_fragments )
74- self .__validate_parameters (raw_fragments )
7563 self .__validate_no_transforms_present (raw_fragments )
7664 self .__validate_outputs (raw_fragments )
77- self .__validate_mappings (raw_fragments )
7865 print_cfn_lint_warnings (self .fragment_dir )
7966
8067 def __validate_outputs (self , raw_fragments ):
8168 self .__validate_no_exports_present (raw_fragments )
82- self .__validate_output_limit (raw_fragments )
8369
8470 @staticmethod
8571 def __validate_no_exports_present (raw_fragments ):
@@ -91,24 +77,7 @@ def __validate_no_exports_present(raw_fragments):
9177 "Found an Export statement in Output: " + _output_name
9278 )
9379
94- def __validate_output_limit (self , raw_fragments ):
95- if "Outputs" in raw_fragments :
96- output_count = len (raw_fragments ["Outputs" ].items ())
97- if output_count > self .output_limit :
98- raise FragmentValidationError (
99- "The Module template fragment has "
100- + str (output_count )
101- + " outputs but must not exceed the limit of "
102- + str (self .output_limit )
103- + " outputs"
104- )
105-
10680 def __validate_resources (self , raw_fragments ):
107- if "Resources" not in raw_fragments :
108- raise FragmentValidationError (
109- "A Module template fragment must have a Resources section"
110- )
111- self .__validate_resource_limit (raw_fragments )
11281 for _resource_name , resource in raw_fragments ["Resources" ].items ():
11382 if "Type" in resource :
11483 self .__validate_no_nested_stacks (resource )
@@ -118,10 +87,6 @@ def __validate_resources(self, raw_fragments):
11887 raise FragmentValidationError (
11988 "Resource '" + _resource_name + "' is invalid"
12089 )
121- else :
122- raise FragmentValidationError (
123- "Resource '" + _resource_name + "' has neither Type nor Name"
124- )
12590
12691 @staticmethod
12792 def __validate_no_include (resource ):
@@ -142,26 +107,6 @@ def __validate_no_nested_stacks(resource):
142107 "Template fragment can't contain nested stack."
143108 )
144109
145- def __validate_resource_limit (self , raw_fragments ):
146- resource_count = len (raw_fragments ["Resources" ].items ())
147- if resource_count > self .resource_limit :
148- raise FragmentValidationError (
149- "The Module template fragment has "
150- + str (resource_count )
151- + " resources but must not exceed the limit of "
152- + str (self .resource_limit )
153- + " resources"
154- )
155-
156- @staticmethod
157- def __validate_parameters (raw_fragments ):
158- if "Parameters" in raw_fragments :
159- for _parameter_name , parameter in raw_fragments ["Parameters" ].items ():
160- if "Type" not in parameter :
161- raise FragmentValidationError (
162- "Parameter '" + _parameter_name + "' must have a Type"
163- )
164-
165110 @staticmethod
166111 def __validate_no_transforms_present (raw_fragments ):
167112 if "transform" in raw_fragments or "Transform" in raw_fragments :
@@ -173,45 +118,6 @@ def __validate_no_transforms_present(raw_fragments):
173118 "Template fragment can't contain any transform."
174119 )
175120
176- def __validate_mappings (self , raw_fragments ):
177- self .__validate_mapping_limit (raw_fragments )
178- self .__validate_mapping_attribute_limit (raw_fragments )
179-
180- def __validate_mapping_limit (self , raw_fragments ):
181- if "Mappings" in raw_fragments :
182- mapping_count = len (raw_fragments ["Mappings" ].items ())
183- if mapping_count > self .mapping_limit :
184- raise FragmentValidationError (
185- "The Module template fragment has "
186- + str (mapping_count )
187- + " mappings but must not exceed the limit of "
188- + str (self .output_limit )
189- + " mappings"
190- )
191-
192- def __validate_mapping_attribute_limit (self , raw_fragments ):
193- if "Mappings" in raw_fragments :
194- for _mapping_name , mapping in raw_fragments ["Mappings" ].items ():
195- attribute_count = len (mapping .items ())
196- if attribute_count > self .mapping_attribute_limit :
197- raise FragmentValidationError (
198- "The mapping "
199- + _mapping_name
200- + " has "
201- + str (attribute_count )
202- + " attributes but must not exceed the limit of "
203- + str (self .output_limit )
204- + " mapping attributes"
205- )
206-
207- def __validate_file_size_limit (self ):
208- total_size = get_template_file_size_in_bytes (self .fragment_dir )
209- if total_size > self .template_file_size_in_bytes_limit :
210- raise FragmentValidationError (
211- "The total file size of the template"
212- " fragments exceeds the CloudFormation Template size limit"
213- )
214-
215121 @staticmethod
216122 def __build_resources (raw_fragments ):
217123 raw_resources = {}
0 commit comments