forked from cloudfoundry-attic/bosh-ext-cli
/
job_property_debug_addr.go
60 lines (48 loc) · 1.39 KB
/
job_property_debug_addr.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
package release
import (
"strings"
boshjob "github.com/cloudfoundry/bosh-cli/release/job"
check "github.com/bosh-tools/bosh-ext-cli/lint/check"
)
type JobPropertyDebugAddr struct {
context check.Context
name string
def boshjob.PropertyDefinition
JobPropertyDebugAddrConfig
}
func NewJobPropertyDebugAddr(context check.Context, name string, def boshjob.PropertyDefinition, config JobPropertyDebugAddrConfig) JobPropertyDebugAddr {
return JobPropertyDebugAddr{context, name, def, config}
}
func (c JobPropertyDebugAddr) Description() check.Description {
return check.Description{
Context_: c.context,
Purpose_: "if property represents a debug address and should not have open address default",
}
}
func (c JobPropertyDebugAddr) Check() ([]check.Suggestion, error) {
var sugs []check.Suggestion
if c.def.Default == nil {
return nil, nil
}
for _, piece := range c.Whitelist {
if strings.Contains(c.def.Description, piece) {
return nil, nil
}
}
defaultStr, ok := c.def.Default.(string)
if !ok {
return nil, nil
}
if strings.Contains(defaultStr, "0.0.0.0") {
for _, piece := range c.DebugPatterns {
if strings.Contains(c.name, piece) {
sugs = append(sugs, check.Simple{
Context_: c.context,
Problem_: "Property holding debug address should not use '0.0.0.0'",
Resolution_: "Update default to use '127.0.0.1'",
})
}
}
}
return sugs, nil
}