-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem-pattern.go
80 lines (64 loc) · 1.9 KB
/
item-pattern.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
73
74
75
76
77
78
79
80
package main
import (
"errors"
"fmt"
"regexp"
)
type ItemInvalidName struct {
name, description, kind string
}
func (iin *ItemInvalidName) Name() string {
return iin.name
}
func (iin *ItemInvalidName) Description() string {
return iin.description
}
func (iin *ItemInvalidName) Kind() string {
return iin.kind
}
func (iin *ItemInvalidName) Lint(config *Config, params LinterParams) (ResultMap, error) {
//see item-env for these two getters
resultEnv, _ := ResultEnv(config, params, iin.Kind())
keysEnv := KeysEnv(resultEnv)
//name pattern
resultInvalidName := make(ResultMap)
reNamespace, err := regexp.Compile(params.NamespacePattern)
checkNamespace := err == nil
if err != nil {
return nil, errors.New(fmt.Sprintf("%s", err))
}
reName, err := regexp.Compile(params.NamePattern)
checkName := err == nil
if err != nil {
return nil, errors.New(fmt.Sprintf("%s", err))
}
reContainer, err := regexp.Compile(params.ContainerPattern)
checkContainer := err == nil
if err != nil {
return nil, errors.New(fmt.Sprintf("%s", err))
}
for _, key := range keysEnv {
item := resultEnv[key]
for _, spec := range item {
if checkNamespace == true {
if reNamespace.FindStringIndex(spec.Namespace) == nil {
display := fmt.Sprintf("%s !~ /%s/", spec.Namespace, params.NamespacePattern)
resultInvalidName[display] = append(resultInvalidName[display], spec)
}
}
if checkName == true {
if reName.FindStringIndex(spec.Name) == nil {
display := fmt.Sprintf("%s !~ /%s/", spec.Name, params.NamePattern)
resultInvalidName[display] = append(resultInvalidName[display], spec)
}
}
if checkContainer == true {
if reContainer.FindStringIndex(spec.Container) == nil {
display := fmt.Sprintf("%s !~ /%s/", spec.Container, params.ContainerPattern)
resultInvalidName[display] = append(resultInvalidName[display], spec)
}
}
}
}
return resultInvalidName, nil
}