cfn-model 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4c9c8ff12b1cdc30eed260505fd8e052e4ee7057bb11b7164a585bbd633b930
4
- data.tar.gz: 24e5016ee7865b97c2f796ed0103776881a88377d58d0ee7cebf070cc45b9fae
3
+ metadata.gz: fdcd8f5945e95c1176ca1f7287dcaedde6871834fd1eca97a0f472b471ed721d
4
+ data.tar.gz: a772da89e6547542d4b591fcd56b6cd7773d9af142cbbcb75d1533e47045fc44
5
5
  SHA512:
6
- metadata.gz: fc2d033fc92f83ca6c8677984587c2de20aee0c1fe7fb90eeddd26cb05ea17574b71ef3533bda77eb278a9b383778e5d8a4620ed9ce6e09bb6dedf02c4939f5e
7
- data.tar.gz: 2b4805cc518a26214dbf8e48952feaf1ddaf486a7a87a79dbe919f33c97cb3ac2b75ae9e5fd10cc292d644d9f5f40504c62d0196679219b79e57b5f9ce5be87d
6
+ metadata.gz: 8e2f370d108e5135c6ec8afa6b88df4692a94b0d07a7a0ee080dd364a499c8157090ae49215eef77a3194301d0c9dc5b898aedad732c9a8fce65417e7112bbd8
7
+ data.tar.gz: f8f656c8fcfcfe91db50766e3d7ab56474d1991c5eab6ab5e2c882554c61abf7d9956681b0425d8691ba68199d262ea967f615e4f4c3d3f703658913e5430dcd
@@ -1,12 +1,30 @@
1
1
  require_relative 'schema_generator'
2
2
  require 'kwalify'
3
+ require 'json'
3
4
 
4
5
  class CloudFormationValidator
5
6
  def validate(cloudformation_string)
6
- schema = SchemaGenerator.new.generate cloudformation_string
7
+ if json_text?(cloudformation_string)
8
+ raise ParserError.new('Invalid JSON!') unless valid_json?(cloudformation_string)
9
+ end
7
10
 
11
+ schema = SchemaGenerator.new.generate cloudformation_string
8
12
  validator = Kwalify::Validator.new(schema)
9
-
10
13
  validator.validate(YAML.load(cloudformation_string))
11
14
  end
15
+
16
+ private
17
+
18
+ def json_text?(cloudformation_string)
19
+ first_character = cloudformation_string.gsub(/\s/, '').split('').first
20
+ matches = cloudformation_string.scan(/\{[^}]*\}/)
21
+ first_character == '{' && !matches.empty?
22
+ end
23
+
24
+ def valid_json?(cloudformation_string)
25
+ JSON.parse(cloudformation_string)
26
+ return true
27
+ rescue JSON::ParserError => error
28
+ return false
29
+ end
12
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2019-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop