-
Notifications
You must be signed in to change notification settings - Fork 4
/
host.go
67 lines (55 loc) · 1.16 KB
/
host.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
package ppsh
import (
"io/ioutil"
"os"
yaml "gopkg.in/yaml.v2"
)
type Result struct {
UUID string `json:"uuid,omitempty"`
Host string `json:"host"`
Cmd string `json:"cmd"`
Success bool `json:"success"`
Code int `json:"code,omitempty"`
Detail string `json:"detail,omitempty"`
Error string `json:"error,omitempty"`
}
type Host struct {
UUID string `yaml:"-"`
IP string `yaml:"ip"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
CertKey string `yaml:"cert-key"`
Ciphers []string `yaml:"ciphers"`
Tasks []string `yaml:"tasks"`
Taskbook string `yaml:"taskbook"`
Result Result `yaml:"-"`
Platform string `yaml:"platform"`
Timeout int `yaml:"timeout"`
}
func (h *Host) ParseTaskbook() error {
f, err := os.Open(h.Taskbook)
if err != nil {
return err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
return err
}
err = yaml.Unmarshal([]byte(data), &h.Tasks)
if err != nil {
return err
}
return nil
}
type Platform string
const (
LINUX = "linux"
OTHER = "other"
)
type Format int
const (
JSON Format = iota + 1
PLAIN
)