kubernetes_schemas 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/kubernetes_schemas.gemspec +1 -1
- data/lib/kubernetes_schemas/version.rb +1 -1
- data/lib/kubernetes_schemas.rb +32 -7
- 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: 32cac48598bfe734ec4cf7c48e89fb41be913ab2ba8a6c4bb77e8a0aafaeb9f5
|
4
|
+
data.tar.gz: 7cd8733adca9ca45178b53209f577c764daf656b37c00afb8750afbebb65f4cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 868d384142d016e54117ff09cab5799159f320a2d3b40319ea7337f6a2186011b4a4da6df64ace86ecc5ac78b19a7635ab29c01f2e8b973947a64a6650c3319d
|
7
|
+
data.tar.gz: 99f093f1291fbcbbeb199c7ac0f8349964152e4bef2028266b5ec2179aaaa7e9d42d2f3306e571d3fda430bcd158582f91b6c55b6f47790442ed0969614d0aa0
|
data/.gitignore
CHANGED
data/kubernetes_schemas.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_dependency "
|
26
|
+
spec.add_dependency "json_schemer"
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.17"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/kubernetes_schemas.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "kubernetes_schemas/version"
|
2
|
-
require "
|
2
|
+
require "json_schemer"
|
3
3
|
|
4
4
|
module KubernetesSchemas
|
5
5
|
def self.load(kubernetes_version, strict: false)
|
@@ -7,9 +7,9 @@ module KubernetesSchemas
|
|
7
7
|
path = File.expand_path("../../schemas/#{kubernetes_version}", __FILE__)
|
8
8
|
Dir.each_child(path).with_object({}) { |filename, hash|
|
9
9
|
definition = JSON.parse(File.read(File.join(path, filename)))
|
10
|
-
if definition["x-kubernetes-group-version-kind"]
|
11
|
-
definition
|
12
|
-
|
10
|
+
if kinds = definition["x-kubernetes-group-version-kind"]
|
11
|
+
definition = JSONSchemer.schema(definition)
|
12
|
+
kinds.each do |meta|
|
13
13
|
hash["#{meta["group"]}/#{meta["version"]}/#{meta["kind"]}"] = definition
|
14
14
|
end
|
15
15
|
end
|
@@ -23,12 +23,37 @@ module KubernetesSchemas
|
|
23
23
|
|
24
24
|
def validate(resource)
|
25
25
|
if schema = @schemas["#{resource["apiVersion"]}/#{resource["kind"]}"]
|
26
|
-
|
27
|
-
validator.validate
|
28
|
-
validator.validation_errors.map(&:message)
|
26
|
+
schema.validate(resource).map { |e| stringify(e) }
|
29
27
|
else
|
30
28
|
[]
|
31
29
|
end
|
32
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def stringify(error)
|
34
|
+
data_pointer, type, schema = error.values_at('data_pointer', 'type', 'schema')
|
35
|
+
location = data_pointer.empty? ? 'root' : "property '#{data_pointer}'"
|
36
|
+
|
37
|
+
case type
|
38
|
+
when 'required'
|
39
|
+
keys = error.fetch('details').fetch('missing_keys').join(', ')
|
40
|
+
"#{location} is missing required keys: #{keys}"
|
41
|
+
when 'null', 'string', 'boolean', 'integer', 'number', 'array', 'object'
|
42
|
+
"#{location} is not of type: #{type}"
|
43
|
+
when 'pattern'
|
44
|
+
"#{location} does not match pattern: #{schema.fetch('pattern')}"
|
45
|
+
when 'format'
|
46
|
+
"#{location} does not match format: #{schema.fetch('format')}"
|
47
|
+
when 'const'
|
48
|
+
"#{location} is not: #{schema.fetch('const').inspect}"
|
49
|
+
when 'enum'
|
50
|
+
"#{location} is not one of: #{schema.fetch('enum')}"
|
51
|
+
when 'schema'
|
52
|
+
"#{location} is present, while it is missing in schema"
|
53
|
+
else
|
54
|
+
"#{location} is invalid: error_type=#{type}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
33
58
|
end
|
34
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Forkert
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2022-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json_schemer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|