forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid.go
64 lines (55 loc) · 1.61 KB
/
id.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 IDType string
const (
IDTypeRunbook IDType = "runbook"
IDTypeStep IDType = "step"
IDTypeBeforeFunc IDType = "beforeFunc"
IDTypeAfterFunc IDType = "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"
)
// ID - ID and context of each element in the runbook.
type ID struct {
Type IDType `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 IDs []ID
func (id ID) String() string {
switch id.Type {
case IDTypeRunbook:
return fmt.Sprintf("runbook[%s]", id.RunbookPath)
case IDTypeStep:
return fmt.Sprintf("steps[%s]", id.StepKey)
case IDTypeBeforeFunc:
return fmt.Sprintf("beforeFunc[%d]", id.FuncIndex)
case IDTypeAfterFunc:
return fmt.Sprintf("afterFunc[%d]", id.FuncIndex)
default:
return "invalid"
}
}
func (ids IDs) toInterfaceSlice() []interface{} {
s := make([]interface{}, len(ids))
for i, v := range ids {
s[i] = v
}
return s
}