cfn-model 0.4.4 → 0.4.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a4e445da9675875b5414f73501cb35a9f903ea89ce5f18013b45aed9fd0ecc
|
4
|
+
data.tar.gz: e2b3ec103eb8a3666e82a6e7a53c15582637c855bfaf2d7051a37c8d7ab7bad1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b0ffdee38353e30698e759d5c83e695b942eb1bf9f6691a5ae6669eaabaea42432ea01d33a0cecbf07282b78ef4012cbfa21e41519ed45fbd634c3b680bf49
|
7
|
+
data.tar.gz: 8aef73ceda3ab93de719dcdc840b83524e099f16949c54637835d4595ebb2351487a63cf4b8e4bf1913c335038079ce9ae6e29a23341b2f11106b31fcf758b27
|
@@ -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
|
-
|
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.
|
4
|
+
version: 0.4.5
|
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-
|
11
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|