forked from jgsqware/clairctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclair.go
More file actions
67 lines (54 loc) · 1.7 KB
/
Copy pathclair.go
File metadata and controls
67 lines (54 loc) · 1.7 KB
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
package clair
import (
"strconv"
"strings"
"github.com/coreos/clair/api/v1"
"github.com/coreos/pkg/capnslog"
"github.com/jgsqware/clairctl/xstrings"
"github.com/spf13/viper"
"net/http"
)
var log = capnslog.NewPackageLogger("github.com/jgsqware/clairctl", "clair")
var uri string
var headers map[string]string
var host string
var healthURI string
//ImageAnalysis Full image analysis
type ImageAnalysis struct {
Registry, ImageName, Tag string
Layers []v1.LayerEnvelope
}
func (imageAnalysis ImageAnalysis) String() string {
return imageAnalysis.Registry + "/" + imageAnalysis.ImageName + ":" + imageAnalysis.Tag
}
//MostRecentLayer returns the most recent layer of an ImageAnalysis object
func (imageAnalysis ImageAnalysis) MostRecentLayer() v1.LayerEnvelope {
return imageAnalysis.Layers[0]
}
func fmtURI(u string, port int) string {
if port != 0 {
u += ":" + strconv.Itoa(port)
}
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
u = "http://" + u
}
return u
}
func (imageAnalysis ImageAnalysis) ShortName(l v1.Layer) string {
return xstrings.Substr(l.Name, 0, 12)
}
//Config configure Clair from configFile
func Config() {
uri = fmtURI(viper.GetString("clair.uri"), viper.GetInt("clair.port")) + "/v1"
healthURI = fmtURI(viper.GetString("clair.uri"), viper.GetInt("clair.healthPort")) + "/health"
Report.Path = viper.GetString("clair.report.path")
Report.Format = viper.GetString("clair.report.format")
headers = viper.GetStringMapString("clair.request.headers")
host = viper.GetString("clair.request.host")
}
func SetRequestHeaders(request *http.Request) {
request.Host = host
for name, value := range headers {
request.Header.Add(name, value)
}
}