added trimSpace to inputs secrets
Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
@@ -2,7 +2,9 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
@@ -18,24 +20,29 @@ type inputSecretFileTask struct {
|
||||
}
|
||||
|
||||
func (c *inputSecretFileTask) Run(ctx context.Context, pctx *plancontext.Context, _ solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
var secretFile struct {
|
||||
Path string
|
||||
Path string
|
||||
TrimSpace bool
|
||||
}
|
||||
|
||||
if err := v.Decode(&secretFile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lg.Debug().Str("path", secretFile.Path).Msg("loading secret")
|
||||
lg := log.Ctx(ctx)
|
||||
lg.Debug().Str("path", secretFile.Path).Str("trimSpace", fmt.Sprintf("%t", secretFile.TrimSpace)).Msg("loading secret")
|
||||
|
||||
plaintext, err := os.ReadFile(secretFile.Path)
|
||||
fileBytes, err := os.ReadFile(secretFile.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secret := pctx.Secrets.New(string(plaintext))
|
||||
plaintext := string(fileBytes)
|
||||
if secretFile.TrimSpace {
|
||||
plaintext = strings.TrimSpace(plaintext)
|
||||
}
|
||||
|
||||
secret := pctx.Secrets.New(plaintext)
|
||||
return compiler.NewValue().FillFields(map[string]interface{}{
|
||||
"contents": secret.MarshalCUE(),
|
||||
})
|
||||
|
Reference in New Issue
Block a user