nuclei/v2/pkg/workflows/compile.go

31 lines
564 B
Go
Raw Normal View History

2020-06-26 10:23:54 +02:00
package workflows
import (
"os"
"github.com/pkg/errors"
2021-02-22 17:49:02 +05:30
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
2020-12-30 13:26:55 +05:30
"gopkg.in/yaml.v2"
2020-06-26 10:23:54 +02:00
)
// Parse a yaml workflow file
2021-02-22 17:49:02 +05:30
func Parse(file string, options *protocols.ExecuterOptions) (*Workflow, error) {
workflow := &Workflow{options: options}
2020-06-26 10:23:54 +02:00
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
err = yaml.NewDecoder(f).Decode(workflow)
if err != nil {
return nil, err
}
if len(workflow.Workflows) == 0 {
return nil, errors.New("no workflow defined")
2020-06-26 14:37:55 +02:00
}
2020-06-26 10:23:54 +02:00
return workflow, nil
}