mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 19:15:27 +00:00
use bytes slice
This commit is contained in:
parent
cf8d067fea
commit
d55ab2f827
@ -1,8 +1,8 @@
|
|||||||
package yaml
|
package yaml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectdiscovery/gologger"
|
"github.com/projectdiscovery/gologger"
|
||||||
@ -56,16 +56,11 @@ func (j *YamlMultiDocFormat) Parse(input io.Reader, resultsCb formats.ParseReqRe
|
|||||||
}
|
}
|
||||||
tpl := []string{string(data)}
|
tpl := []string{string(data)}
|
||||||
dvs := mapToKeyValueSlice(j.opts.Variables)
|
dvs := mapToKeyValueSlice(j.opts.Variables)
|
||||||
finalInput, err = ytt(tpl, dvs, j.opts.VarsFilePaths)
|
finalData, err := ytt(tpl, dvs, j.opts.VarsFilePaths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not apply ytt templating")
|
return errors.Wrap(err, "could not apply ytt templating")
|
||||||
}
|
}
|
||||||
finalData, err := io.ReadAll(finalInput)
|
finalInput = bytes.NewReader(finalData)
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not read templated input")
|
|
||||||
}
|
|
||||||
finalInput = strings.NewReader(string(finalData))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder := YamlUtil.NewDecoder(finalInput)
|
decoder := YamlUtil.NewDecoder(finalInput)
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
package yaml
|
package yaml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
yttcmd "carvel.dev/ytt/pkg/cmd/template"
|
yttcmd "carvel.dev/ytt/pkg/cmd/template"
|
||||||
@ -12,7 +10,7 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"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
|
// create and invoke ytt "template" command
|
||||||
templatingOptions := yttcmd.NewOptions()
|
templatingOptions := yttcmd.NewOptions()
|
||||||
|
|
||||||
@ -38,12 +36,7 @@ func ytt(tpl, dvs []string, varFiles []string) (io.Reader, error) {
|
|||||||
return nil, output.Err
|
return nil, output.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
// output.DocSet contains the full set of resulting YAML documents, in order.
|
return output.DocSet.AsBytes()
|
||||||
bs, err := output.DocSet.AsBytes()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return bytes.NewReader(bs), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// templatesAsInput conveniently wraps one or more strings, each in a files.File, into a template.Input.
|
// templatesAsInput conveniently wraps one or more strings, each in a files.File, into a template.Input.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user