Class: SchemaGenerator
- Inherits:
-
Object
- Object
- SchemaGenerator
- Defined in:
- lib/cfn-model/validator/schema_generator.rb
Overview
This generator is a bit of hacking to trick kwalify into validating yaml for a cfn template.
because cfn uses open-ended key names for the resources.… a static schema can’t be used with kwalify. so first we make sure there is a basic structure of resources with Type values then we generate the schema from the document for the keys and cross-reference with schema files per resource type
Instance Method Summary collapse
Instance Method Details
#generate(cloudformation_yml) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cfn-model/validator/schema_generator.rb', line 14 def generate(cloudformation_yml) # make sure structure of Resources is decent and that every record has a Type at least cloudformation_hash = ResourceTypeValidator.validate cloudformation_yml parameters_schema = generate_schema_for_parameter_keys cloudformation_hash resources_schema = generate_schema_for_resource_keys cloudformation_hash main_schema = YAML.safe_load IO.read(schema_file('schema.yml.erb')) if parameters_schema.empty? main_schema['mapping'].delete 'Parameters' else main_schema['mapping']['Parameters']['mapping'] = parameters_schema end main_schema['mapping']['Resources']['mapping'] = resources_schema main_schema end |