mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-14 19:58:45 +00:00
Allow kyverno jp to take yaml files as inputs (#3768)
This commit is contained in:
parent
0a5f004047
commit
05c5f1b340
2 changed files with 7 additions and 5 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
gojmespath "github.com/jmespath/go-jmespath"
|
gojmespath "github.com/jmespath/go-jmespath"
|
||||||
jmespath "github.com/kyverno/kyverno/pkg/engine/jmespath"
|
jmespath "github.com/kyverno/kyverno/pkg/engine/jmespath"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command returns jp command
|
// Command returns jp command
|
||||||
|
@ -57,18 +58,20 @@ func Command() *cobra.Command {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var input interface{}
|
var input interface{}
|
||||||
var jsonParser *json.Decoder
|
|
||||||
if filename != "" {
|
if filename != "" {
|
||||||
f, err := ioutil.ReadFile(filename)
|
f, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening input file: %w", err)
|
return fmt.Errorf("error opening input file: %w", err)
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(f, &input); err != nil {
|
if err := yaml.Unmarshal(f, &input); err != nil {
|
||||||
return fmt.Errorf("error parsing input json: %w", err)
|
return fmt.Errorf("error parsing input json: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jsonParser = json.NewDecoder(os.Stdin)
|
f, err := ioutil.ReadAll(os.Stdin)
|
||||||
if err := jsonParser.Decode(&input); err != nil {
|
if err != nil {
|
||||||
|
return fmt.Errorf("error opening input file: %w", err)
|
||||||
|
}
|
||||||
|
if err := yaml.Unmarshal(f, &input); err != nil {
|
||||||
return fmt.Errorf("error parsing input json: %w", err)
|
return fmt.Errorf("error parsing input json: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -21,7 +21,6 @@ require (
|
||||||
github.com/go-logr/logr v1.2.2
|
github.com/go-logr/logr v1.2.2
|
||||||
github.com/google/go-containerregistry v0.8.1-0.20220209165246-a44adc326839
|
github.com/google/go-containerregistry v0.8.1-0.20220209165246-a44adc326839
|
||||||
github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20220301182634-bfe2ffc6b6bd
|
github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20220301182634-bfe2ffc6b6bd
|
||||||
github.com/google/martian v2.1.1-0.20190517191504-25dcb96d9e51+incompatible
|
|
||||||
github.com/googleapis/gnostic v0.5.5
|
github.com/googleapis/gnostic v0.5.5
|
||||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
|
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
|
||||||
github.com/in-toto/in-toto-golang v0.3.4-0.20211211042327-af1f9fb822bf
|
github.com/in-toto/in-toto-golang v0.3.4-0.20211211042327-af1f9fb822bf
|
||||||
|
|
Loading…
Add table
Reference in a new issue