forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trail.go
64 lines (55 loc) · 1.65 KB
/
trail.go
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
package runn
import "fmt"
type TrailType string
const (
TrailTypeRunbook TrailType = "runbook"
TrailTypeStep TrailType = "step"
TrailTypeBeforeFunc TrailType = "beforeFunc"
TrailTypeAfterFunc TrailType = "afterFunc"
)
type RunnerType string
const (
RunnerTypeHTTP RunnerType = "http"
RunnerTypeDB RunnerType = "db"
RunnerTypeGRPC RunnerType = "grpc"
RunnerTypeCDP RunnerType = "cdp"
RunnerTypeSSH RunnerType = "ssh"
RunnerTypeExec RunnerType = "exec"
RunnerTypeTest RunnerType = "test"
RunnerTypeDump RunnerType = "dump"
RunnerTypeInclude RunnerType = "include"
RunnerTypeBind RunnerType = "bind"
)
// Trail - The trail of elements in the runbook at runtime.
type Trail struct {
Type TrailType `json:"type"`
Desc string `json:"desc,omitempty"`
RunbookID string `json:"id,omitempty"`
RunbookPath string `json:"path,omitempty"`
StepKey string `json:"key,omitempty"`
StepRunnerType RunnerType `json:"runner_type,omitempty"`
StepRunnerKey string `json:"runner_key,omitempty"`
FuncIndex int `json:"func_index,omitempty"`
}
type Trails []Trail
func (tr Trail) String() string {
switch tr.Type {
case TrailTypeRunbook:
return fmt.Sprintf("runbook[%s]", tr.RunbookPath)
case TrailTypeStep:
return fmt.Sprintf("steps[%s]", tr.StepKey)
case TrailTypeBeforeFunc:
return fmt.Sprintf("beforeFunc[%d]", tr.FuncIndex)
case TrailTypeAfterFunc:
return fmt.Sprintf("afterFunc[%d]", tr.FuncIndex)
default:
return "invalid"
}
}
func (trs Trails) toInterfaceSlice() []any {
s := make([]any, len(trs))
for i, v := range trs {
s[i] = v
}
return s
}