This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/plan/task/secretfile.go
Andrea Luzzardi 0aea10d23e dagger.#FS support
- Implement dagger.#FS support
- Migrate `context.imports` to dagger.#FS
- Backward compat: dagger.#FS can be passed in lieu of a
  dagger.#Artifact
- For instance, an import (`dagger.#FS`) can be passed to the current
  `yarn.#Package` implementation

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
2021-11-30 12:58:50 -08:00

47 lines
892 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
}
id := pctx.Secrets.Register(&plancontext.Secret{
PlainText: string(data),
})
return compiler.NewValueWithContent(id,
cue.Str("contents"),
cue.Str("id"),
)
}