mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-18 09:27:02 +00:00
Try to expose JSON paths
This commit is contained in:
parent
682ca5c9e2
commit
7ca7952835
2 changed files with 24 additions and 8 deletions
|
|
@ -9,12 +9,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type oresult struct {
|
type oresult struct {
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
Errors []string `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsono struct {
|
type jsono struct {
|
||||||
|
|
@ -63,7 +64,7 @@ func (o *jsono) Write(result validator.Result) error {
|
||||||
|
|
||||||
if o.verbose || (result.Status != validator.Valid && result.Status != validator.Skipped && result.Status != validator.Empty) {
|
if o.verbose || (result.Status != validator.Valid && result.Status != validator.Skipped && result.Status != validator.Empty) {
|
||||||
sig, _ := result.Resource.Signature()
|
sig, _ := result.Resource.Signature()
|
||||||
o.results = append(o.results, oresult{Filename: result.Resource.Path, Kind: sig.Kind, Name: sig.Name, Version: sig.Version, Status: st, Msg: msg})
|
o.results = append(o.results, oresult{Filename: result.Resource.Path, Kind: sig.Kind, Name: sig.Name, Version: sig.Version, Status: st, Msg: msg, Errors: result.ErrPaths})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package validator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
|
@ -30,6 +31,7 @@ const (
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Resource resource.Resource
|
Resource resource.Resource
|
||||||
Err error
|
Err error
|
||||||
|
ErrPaths []string
|
||||||
Status Status
|
Status Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +183,20 @@ func (val *v) ValidateResource(res resource.Resource) Result {
|
||||||
|
|
||||||
err = schema.Validate(r)
|
err = schema.Validate(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Result{Resource: res, Status: Invalid, Err: fmt.Errorf("problem validating schema. Check JSON formatting: %s", err)}
|
errPaths := []string{}
|
||||||
|
var e *jsonschema.ValidationError
|
||||||
|
if errors.As(err, &e) {
|
||||||
|
for _, cause := range e.Causes {
|
||||||
|
errPaths = append(errPaths, cause.KeywordLocation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result{
|
||||||
|
Resource: res,
|
||||||
|
Status: Invalid,
|
||||||
|
Err: fmt.Errorf("problem validating schema. Check JSON formatting: %s", err),
|
||||||
|
ErrPaths: errPaths,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result{Resource: res, Status: Valid}
|
return Result{Resource: res, Status: Valid}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue