forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.go
66 lines (57 loc) · 1.19 KB
/
resource.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
package resource
import (
"fmt"
"path/filepath"
"strconv"
"strings"
"github.com/aelsabbahy/goss/system"
"github.com/oleiade/reflections"
)
type Resource interface {
Validate(*system.System) []TestResult
SetID(string)
}
type ResourceRead interface {
ID() string
GetTitle() string
GetMeta() meta
}
type matcher interface{}
type meta map[string]interface{}
func contains(a []string, s string) bool {
for _, e := range a {
if m, _ := filepath.Match(e, s); m {
return true
}
}
return false
}
func deprecateAtoI(depr interface{}, desc string) interface{} {
s, ok := depr.(string)
if !ok {
return depr
}
fmt.Printf("DEPRECATION WARNING: %s should be an integer not a string\n", desc)
i, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return float64(i)
}
func validAttrs(i interface{}, t string) (map[string]bool, error) {
validAttrs := make(map[string]bool)
tags, err := reflections.Tags(i, t)
if err != nil {
return nil, err
}
for _, v := range tags {
validAttrs[strings.Split(v, ",")[0]] = true
}
return validAttrs, nil
}
func shouldSkip(results []TestResult) bool {
if results[0].Err != nil || results[0].Found[0] == "false" {
return true
}
return false
}