mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-24 08:36:46 +00:00
* feat: support mock in CLI for VPs Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * implement get cm mock Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * move into cel package Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
34 lines
708 B
Go
34 lines
708 B
Go
package context
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/go-git/go-billy/v5"
|
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
|
|
"k8s.io/apimachinery/pkg/util/yaml"
|
|
)
|
|
|
|
func Load(f billy.Filesystem, filepath string) (*v1alpha1.Context, error) {
|
|
yamlBytes, err := readFile(f, filepath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
vals := &v1alpha1.Context{}
|
|
if err := yaml.UnmarshalStrict(yamlBytes, vals); err != nil {
|
|
return nil, err
|
|
}
|
|
return vals, nil
|
|
}
|
|
|
|
func readFile(f billy.Filesystem, filepath string) ([]byte, error) {
|
|
if f != nil {
|
|
file, err := f.Open(filepath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
return io.ReadAll(file)
|
|
}
|
|
return os.ReadFile(filepath)
|
|
}
|