inputs decryption using SOPS
- Add support for --input-json and --input-yaml (plaintext) - Input files can optionally be encrypted using sops, with transparent decryption by dagger Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
cueerrors "cuelang.org/go/cue/errors"
|
||||
cuejson "cuelang.org/go/encoding/json"
|
||||
cueyaml "cuelang.org/go/encoding/yaml"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -34,6 +36,14 @@ func Err(err error) error {
|
||||
return DefaultCompiler.Err(err)
|
||||
}
|
||||
|
||||
func DecodeJSON(path string, data []byte) (*Value, error) {
|
||||
return DefaultCompiler.DecodeJSON(path, data)
|
||||
}
|
||||
|
||||
func DecodeYAML(path string, data []byte) (*Value, error) {
|
||||
return DefaultCompiler.DecodeYAML(path, data)
|
||||
}
|
||||
|
||||
// Polyfill for a cue runtime
|
||||
// (we call it compiler to avoid confusion with dagger runtime)
|
||||
// Use this instead of cue.Runtime
|
||||
@@ -83,6 +93,22 @@ func (c *Compiler) Compile(name string, src interface{}) (*Value, error) {
|
||||
return c.Wrap(inst.Value(), inst), nil
|
||||
}
|
||||
|
||||
func (c *Compiler) DecodeJSON(path string, data []byte) (*Value, error) {
|
||||
inst, err := cuejson.Decode(c.Cue(), path, data)
|
||||
if err != nil {
|
||||
return nil, Err(err)
|
||||
}
|
||||
return c.Wrap(inst.Value(), inst), nil
|
||||
}
|
||||
|
||||
func (c *Compiler) DecodeYAML(path string, data []byte) (*Value, error) {
|
||||
inst, err := cueyaml.Decode(c.Cue(), path, data)
|
||||
if err != nil {
|
||||
return nil, Err(err)
|
||||
}
|
||||
return c.Wrap(inst.Value(), inst), nil
|
||||
}
|
||||
|
||||
func (c *Compiler) Wrap(v cue.Value, inst *cue.Instance) *Value {
|
||||
return wrapValue(v, inst, c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user