engine: Make paths relative to the CUE file they're defined in
Fixes #1309 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
committed by
Sam Alba
parent
ec69734c51
commit
9c81a155c9
@@ -2,7 +2,6 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -20,25 +19,26 @@ type inputSecretFileTask struct {
|
||||
}
|
||||
|
||||
func (c *inputSecretFileTask) Run(ctx context.Context, pctx *plancontext.Context, _ solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
||||
var secretFile struct {
|
||||
Path string
|
||||
TrimSpace bool
|
||||
}
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
if err := v.Decode(&secretFile); err != nil {
|
||||
path, err := v.Lookup("path").AbsPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lg := log.Ctx(ctx)
|
||||
lg.Debug().Str("path", secretFile.Path).Str("trimSpace", fmt.Sprintf("%t", secretFile.TrimSpace)).Msg("loading secret")
|
||||
lg.Debug().Str("path", path).Msg("loading secret")
|
||||
|
||||
fileBytes, err := os.ReadFile(secretFile.Path)
|
||||
fileBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plaintext := string(fileBytes)
|
||||
if secretFile.TrimSpace {
|
||||
trimSpace, err := v.Lookup("trimSpace").Bool()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if trimSpace {
|
||||
plaintext = strings.TrimSpace(plaintext)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user