nuclei/v2/pkg/workflows/compile.go

31 lines
564 B
Go
Raw Normal View History

2020-06-26 08:23:54 +00:00
package workflows
import (
"os"
"github.com/pkg/errors"
2021-02-22 12:19:02 +00:00
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
2020-12-30 07:56:55 +00:00
"gopkg.in/yaml.v2"
2020-06-26 08:23:54 +00:00
)
// Parse a yaml workflow file
2021-02-22 12:19:02 +00:00
func Parse(file string, options *protocols.ExecuterOptions) (*Workflow, error) {
workflow := &Workflow{options: options}
2020-06-26 08:23:54 +00: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 12:37:55 +00:00
}
2020-06-26 08:23:54 +00:00
return workflow, nil
}