Class: ResourceTypeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn-model/validator/resource_type_validator.rb

Class Method Summary collapse

Class Method Details

.validate(cloudformation_yml) ⇒ Object



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
# File 'lib/cfn-model/validator/resource_type_validator.rb', line 5

def self.validate(cloudformation_yml)
  hash = YAML.load cloudformation_yml
  if hash == false || hash.nil?
    raise ParserError.new 'yml empty'
  end

  if hash.is_a? Array or hash['Resources'].nil? or hash['Resources'].empty?
    raise ParserError.new 'Illegal cfn - no Resources'
  end

  resources = hash['Resources']

  resources.each do |resource_id, resource|
    if resource['Type'].nil?
      raise ParserError.new "Illegal cfn - missing Type: id: #{resource_id}"
    end
  end

  parameters = hash['Parameters']
  unless parameters.nil?
    parameters.each do |parameter_id, parameter|
      if parameter['Type'].nil?
        raise ParserError.new "Illegal cfn - missing Parameter Type: id: #{parameter_id}"
      end
    end
  end

  hash
end