-
Notifications
You must be signed in to change notification settings - Fork 23
/
types.go
68 lines (57 loc) · 1.49 KB
/
types.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
package dockercmd
import (
"context"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)
type ImageVulnerabilities struct {
Label string
ImageName string
Critical string
High string
Medium string
Low string
UnknownSeverity string
}
// takes [][]bytes returned by regex.FindSubmatches and returns ImageVulnerabilities
func makeImageVulnerabilities(submatches [][]byte) ImageVulnerabilities {
//this makes sure "" is not printed in the table
unknownSev := string(submatches[8])
if unknownSev == "" {
unknownSev = "0"
}
return ImageVulnerabilities{
Label: string(submatches[1]),
ImageName: string(submatches[2]),
Critical: string(submatches[3]),
High: string(submatches[4]),
Medium: string(submatches[5]),
Low: string(submatches[6]),
UnknownSeverity: unknownSev,
}
}
type ScoutData struct {
ImageVulEntries []ImageVulnerabilities
}
type DockerClient struct {
cli *client.Client
containerListArgs container.ListOptions
}
func NewDockerClient() DockerClient {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
return DockerClient{
cli: cli,
containerListArgs: container.ListOptions{
Size: true,
All: false,
Latest: false,
},
}
}
func (dc DockerClient) PingDocker() error {
_, err := dc.cli.Ping(context.Background())
return err
}