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:
Andrea Luzzardi
2021-03-18 15:03:45 -07:00
parent eb6fe17df3
commit e6bb3f12f4
5 changed files with 177 additions and 0 deletions

View File

@@ -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)
}