-
Notifications
You must be signed in to change notification settings - Fork 2
/
port.go
50 lines (43 loc) · 1.31 KB
/
port.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
package resource
import (
"github.com/SimonBaeumer/goss/system"
"github.com/SimonBaeumer/goss/util"
)
type Port struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Meta meta `json:"meta,omitempty" yaml:"meta,omitempty"`
Port string `json:"-" yaml:"-"`
Listening matcher `json:"listening" yaml:"listening"`
IP matcher `json:"ip,omitempty" yaml:"ip,omitempty"`
}
func (p *Port) ID() string { return p.Port }
func (p *Port) SetID(id string) { p.Port = id }
func (p *Port) GetTitle() string { return p.Title }
func (p *Port) GetMeta() meta { return p.Meta }
func (p *Port) Validate(sys *system.System) []TestResult {
skip := false
sysPort := sys.NewPort(p.Port, sys, util.Config{})
var results []TestResult
results = append(results, ValidateValue(p, "listening", p.Listening, sysPort.Listening, skip))
if shouldSkip(results) {
skip = true
}
if p.IP != nil {
results = append(results, ValidateValue(p, "ip", p.IP, sysPort.IP, skip))
}
return results
}
func NewPort(sysPort system.Port, config util.Config) (*Port, error) {
port := sysPort.Port()
listening, _ := sysPort.Listening()
p := &Port{
Port: port,
Listening: listening,
}
if !contains(config.IgnoreList, "ip") {
if ip, err := sysPort.IP(); err == nil {
p.IP = ip
}
}
return p, nil
}