-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruleset.go
62 lines (55 loc) · 1.45 KB
/
ruleset.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
package main
import (
"fmt"
"strings"
)
func validate(command string) bool {
fmt.Println("validate the dockerfile is syntactically correct")
// TODO
return true
}
func capitalize(command string) string {
fmt.Println("capitalize all of the commands")
s := strings.SplitN(command, " ", 2)
s[0] = strings.ToUpper(s[0])
command = strings.Join(s, " ")
fmt.Println(command)
return command
}
func checkFirstCommand(command string) bool {
fmt.Println("first command must be FROM")
command = strings.ToUpper(command)
if strings.HasPrefix(command, "FROM ") {
return true
}
return false
}
func checkFromTag(command string) bool {
fmt.Println("FROM command should have a tag")
if strings.Contains(command, ":") {
return true
}
return false
}
func Rules(command string, line int) string {
// Run against ruleset unless it's a comment
if strings.HasPrefix(command, "#") {
fmt.Println("Line is a comment")
} else {
v := validate(command)
fmt.Println(v)
command = capitalize(command)
if line == 1 {
v = checkFirstCommand(command)
fmt.Println(v)
v = checkFromTag(command)
fmt.Println(v)
}
// check for too many layers
if line == 128 {
fmt.Println("Too many layers were found, reduce the number of commands")
}
}
fmt.Println(line)
return command
}