5b7b1cab79
- Refactored to keep every transformation of built-in types (e.g. FS, Secret, etc) to/from CUE in the same place (plancontext) - dagger.#Service and dagger.#Secret are now following the new FS-like format (e.g. `_service: id: string`) - Backward compatibility - dagger.#Stream is now an alias for dagger.#Service Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
46 lines
916 B
Go
46 lines
916 B
Go
package task
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"cuelang.org/go/cue"
|
|
"github.com/rs/zerolog/log"
|
|
"go.dagger.io/dagger/compiler"
|
|
"go.dagger.io/dagger/plancontext"
|
|
"go.dagger.io/dagger/solver"
|
|
)
|
|
|
|
func init() {
|
|
Register("SecretFile", func() Task { return &secretFileTask{} })
|
|
}
|
|
|
|
type secretFileTask struct {
|
|
}
|
|
|
|
func (c secretFileTask) Run(ctx context.Context, pctx *plancontext.Context, _ solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
|
lg := log.Ctx(ctx)
|
|
|
|
var secretFile struct {
|
|
Path string
|
|
}
|
|
|
|
if err := v.Decode(&secretFile); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lg.Debug().Str("path", secretFile.Path).Msg("loading secret")
|
|
|
|
data, err := os.ReadFile(secretFile.Path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
secret := pctx.Secrets.New(string(data))
|
|
out := compiler.NewValue()
|
|
if err := out.FillPath(cue.ParsePath("contents"), secret.Value()); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|