2020-06-26 08:23:54 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2020-11-12 17:58:24 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2020-12-25 20:38:48 +00:00
|
|
|
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
|
|
|
|
}
|