-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathflow_model.go
More file actions
71 lines (58 loc) · 1.88 KB
/
Copy pathflow_model.go
File metadata and controls
71 lines (58 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package usecase
import (
"errors"
"time"
"gopkg.in/yaml.v3"
"github.com/utmstack/utmstack/backend/modules/soar/domain"
)
var (
ErrFlowNotFound = errors.New("flow not found")
ErrSystemFlowContent = errors.New("system flow content is read-only")
)
type FlowCondition struct {
Operator string `yaml:"operator"`
Field string `yaml:"field"`
Value any `yaml:"value"`
}
// FlowCommand is one step in a flow's command chain. Condition (nil on the
// first entry) is how this command joins to the previous one when the chain
// is concatenated into a single shell line.
type FlowCommand struct {
Command string `yaml:"command"`
Condition *domain.Condition `yaml:"condition,omitempty"`
}
// UnmarshalYAML accepts either a bare string (legacy `commands: [cmd, cmd]`)
// or a mapping `{command, condition}`. Bare strings decode with a nil
// Condition; the loader treats that as Always when it's not the first step.
func (fc *FlowCommand) UnmarshalYAML(value *yaml.Node) error {
if value.Kind == yaml.ScalarNode {
fc.Command = value.Value
return nil
}
type raw FlowCommand
var r raw
if err := value.Decode(&r); err != nil {
return err
}
*fc = FlowCommand(r)
return nil
}
type Flow struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Conditions []FlowCondition `yaml:"conditions"`
Commands []FlowCommand `yaml:"commands"`
Shell string `yaml:"shell,omitempty"`
AgentPlatform string `yaml:"agentPlatform,omitempty"`
DefaultAgent string `yaml:"defaultAgent,omitempty"`
ExcludedAgents []string `yaml:"excludedAgents,omitempty"`
}
type StoredFlow struct {
Flow
RelPath string
Modified time.Time
system bool
enabled bool
}
func (sf StoredFlow) Active() bool { return sf.enabled }
func (sf StoredFlow) SystemOwned() bool { return sf.system }