-
Notifications
You must be signed in to change notification settings - Fork 48
/
plugin.go
72 lines (58 loc) · 1.34 KB
/
plugin.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
65
66
67
68
69
70
71
72
package types
import (
"github.com/ssbeatty/jsonschema"
"github.com/ssbeatty/oms/pkg/transport"
"reflect"
"strings"
)
type Step interface {
ID() string
SetID(id string)
Exec(session *transport.Session, sudo bool) ([]byte, error)
GetSchema() (interface{}, error)
Create(conf []byte) (Step, error)
Name() string
Desc() string
Config() interface{}
}
// build in
type BaseStep struct {
id string // 任务步骤标识
}
func (bs *BaseStep) SetID(id string) {
bs.id = id
}
func (bs *BaseStep) ID() string {
return bs.id
}
func readStringArray(v reflect.Value) (vals []string) {
count := v.Len()
for i := 0; i < count; i++ {
child := v.Index(i)
s := child.String()
vals = append(vals, s)
}
return
}
func ParseCaches(conf interface{}) []string {
var ret []string
if conf == nil {
return ret
}
v := reflect.ValueOf(conf)
t := reflect.TypeOf(conf).Elem()
for i := 0; i < t.NumField(); i++ {
if strings.Contains(t.Field(i).Tag.Get("jsonschema"), "format=data-url") {
if t.Field(i).Type.Kind() == reflect.String {
ret = append(ret, v.Elem().Field(i).String())
} else if t.Field(i).Type.Kind() == reflect.Slice {
ret = readStringArray(v.Elem().Field(i))
}
}
}
return ret
}
func GetSchema(config interface{}) (interface{}, error) {
ref := jsonschema.Reflector{DoNotReference: true}
return ref.Reflect(config), nil
}