mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +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 {
|
||||
Filename string `json:"filename"`
|
||||
Kind string `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
Msg string `json:"msg"`
|
||||
Filename string `json:"filename"`
|
||||
Kind string `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
Msg string `json:"msg"`
|
||||
Errors []string `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package validator
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ const (
|
|||
type Result struct {
|
||||
Resource resource.Resource
|
||||
Err error
|
||||
ErrPaths []string
|
||||
Status Status
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +183,20 @@ func (val *v) ValidateResource(res resource.Resource) Result {
|
|||
|
||||
err = schema.Validate(r)
|
||||
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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue