class CloudFormationValidator
Public Instance Methods
validate(cloudformation_string)
click to toggle source
# File lib/cfn-model/validator/cloudformation_validator.rb, line 8 def validate(cloudformation_string) if json_text?(cloudformation_string) raise ParserError.new('Invalid JSON!') unless valid_json?(cloudformation_string) end schema = SchemaGenerator.new.generate cloudformation_string validator = Kwalify::Validator.new(schema) validator.validate(YAML.load(cloudformation_string)) rescue ArgumentError, IOError, NameError => e raise ParserError, e.inspect end
Private Instance Methods
json_text?(cloudformation_string)
click to toggle source
# File lib/cfn-model/validator/cloudformation_validator.rb, line 22 def json_text?(cloudformation_string) first_character = cloudformation_string.gsub(/\s/, '').split('').first matches = cloudformation_string.scan(/\{[^}]*\}/) first_character == '{' && !matches.empty? end
valid_json?(cloudformation_string)
click to toggle source
# File lib/cfn-model/validator/cloudformation_validator.rb, line 28 def valid_json?(cloudformation_string) JSON.parse(cloudformation_string) true rescue JSON::ParserError => error false end