cfn-model 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cfn-model/validator/cloudformation_validator.rb +20 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdcd8f5945e95c1176ca1f7287dcaedde6871834fd1eca97a0f472b471ed721d
|
4
|
+
data.tar.gz: a772da89e6547542d4b591fcd56b6cd7773d9af142cbbcb75d1533e47045fc44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.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-
|
11
|
+
date: 2019-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|