use bytes slice

This commit is contained in:
Mzack9999 2025-07-03 18:05:08 +02:00
parent cf8d067fea
commit d55ab2f827
2 changed files with 5 additions and 17 deletions

View File

@ -1,8 +1,8 @@
package yaml
import (
"bytes"
"io"
"strings"
"github.com/pkg/errors"
"github.com/projectdiscovery/gologger"
@ -56,16 +56,11 @@ func (j *YamlMultiDocFormat) Parse(input io.Reader, resultsCb formats.ParseReqRe
}
tpl := []string{string(data)}
dvs := mapToKeyValueSlice(j.opts.Variables)
finalInput, err = ytt(tpl, dvs, j.opts.VarsFilePaths)
finalData, err := ytt(tpl, dvs, j.opts.VarsFilePaths)
if err != nil {
return errors.Wrap(err, "could not apply ytt templating")
}
finalData, err := io.ReadAll(finalInput)
if err != nil {
return errors.Wrap(err, "could not read templated input")
}
finalInput = strings.NewReader(string(finalData))
finalInput = bytes.NewReader(finalData)
}
decoder := YamlUtil.NewDecoder(finalInput)

View File

@ -1,9 +1,7 @@
package yaml
import (
"bytes"
"fmt"
"io"
"strings"
yttcmd "carvel.dev/ytt/pkg/cmd/template"
@ -12,7 +10,7 @@ import (
"gopkg.in/yaml.v2"
)
func ytt(tpl, dvs []string, varFiles []string) (io.Reader, error) {
func ytt(tpl, dvs []string, varFiles []string) ([]byte, error) {
// create and invoke ytt "template" command
templatingOptions := yttcmd.NewOptions()
@ -38,12 +36,7 @@ func ytt(tpl, dvs []string, varFiles []string) (io.Reader, error) {
return nil, output.Err
}
// output.DocSet contains the full set of resulting YAML documents, in order.
bs, err := output.DocSet.AsBytes()
if err != nil {
return nil, err
}
return bytes.NewReader(bs), nil
return output.DocSet.AsBytes()
}
// templatesAsInput conveniently wraps one or more strings, each in a files.File, into a template.Input.