fix clair health port
This commit is contained in:
parent
368227e4dd
commit
21c68cd795
@ -12,16 +12,16 @@ import (
|
||||
)
|
||||
|
||||
var uri string
|
||||
var healthPort int
|
||||
var healthURI string
|
||||
|
||||
//Report Reporting Config value
|
||||
var Report ReportConfig
|
||||
|
||||
//VulnerabiliesCounts Total count of vulnerabilities by type
|
||||
type VulnerabiliesCounts map[types.Priority]int
|
||||
type vulnerabiliesCounts map[types.Priority]int
|
||||
|
||||
//Total return to total of Vulnerabilities
|
||||
func (v VulnerabiliesCounts) Total() int {
|
||||
func (v vulnerabiliesCounts) Total() int {
|
||||
var c int
|
||||
for _, count := range v {
|
||||
c += count
|
||||
@ -30,12 +30,12 @@ func (v VulnerabiliesCounts) Total() int {
|
||||
}
|
||||
|
||||
//Count return count of severities in Vulnerabilities
|
||||
func (v VulnerabiliesCounts) Count(severity string) int {
|
||||
func (v vulnerabiliesCounts) Count(severity string) int {
|
||||
return v[types.Priority(severity)]
|
||||
}
|
||||
|
||||
//RelativeCount get the percentage of vulnerabilities of a severity
|
||||
func (v VulnerabiliesCounts) RelativeCount(severity string) float64 {
|
||||
func (v vulnerabiliesCounts) RelativeCount(severity string) float64 {
|
||||
count := v[types.Priority(severity)]
|
||||
result := float64(count) / float64(v.Total()) * 100
|
||||
return math.Ceil(result*100) / 100
|
||||
@ -52,7 +52,7 @@ func (imageAnalysis ImageAnalysis) String() string {
|
||||
}
|
||||
|
||||
// CountVulnerabilities counts all image vulnerability
|
||||
func (imageAnalysis ImageAnalysis) CountVulnerabilities(l v1.Layer) int {
|
||||
func (imageAnalysis ImageAnalysis) countVulnerabilities(l v1.Layer) int {
|
||||
count := 0
|
||||
for _, f := range l.Features {
|
||||
count += len(f.Vulnerabilities)
|
||||
@ -61,8 +61,8 @@ func (imageAnalysis ImageAnalysis) CountVulnerabilities(l v1.Layer) int {
|
||||
}
|
||||
|
||||
// CountAllVulnerabilities Total count of vulnerabilities
|
||||
func (imageAnalysis ImageAnalysis) CountAllVulnerabilities() VulnerabiliesCounts {
|
||||
result := make(VulnerabiliesCounts)
|
||||
func (imageAnalysis ImageAnalysis) CountAllVulnerabilities() vulnerabiliesCounts {
|
||||
result := make(vulnerabiliesCounts)
|
||||
|
||||
l := imageAnalysis.Layers[len(imageAnalysis.Layers)-1]
|
||||
|
||||
@ -81,24 +81,21 @@ func (imageAnalysis ImageAnalysis) LastLayer() *v1.Layer {
|
||||
return imageAnalysis.Layers[len(imageAnalysis.Layers)-1].Layer
|
||||
}
|
||||
|
||||
type VulnerabilityWithFeature struct {
|
||||
type vulnerabilityWithFeature struct {
|
||||
v1.Vulnerability
|
||||
Feature string
|
||||
}
|
||||
|
||||
func fmtURI(u string, port int) string {
|
||||
|
||||
|
||||
func fmtURI(u string, port int) {
|
||||
uri = u
|
||||
if port != 0 {
|
||||
uri += ":" + strconv.Itoa(port)
|
||||
u += ":" + strconv.Itoa(port)
|
||||
}
|
||||
if !strings.HasSuffix(uri, "/v1") {
|
||||
uri += "/v1"
|
||||
}
|
||||
if !strings.HasPrefix(uri, "http://") && !strings.HasPrefix(uri, "https://") {
|
||||
uri = "http://" + uri
|
||||
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
|
||||
u = "http://" + u
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (imageAnalysis ImageAnalysis) ShortName(l v1.Layer) string {
|
||||
@ -107,8 +104,8 @@ func (imageAnalysis ImageAnalysis) ShortName(l v1.Layer) string {
|
||||
|
||||
//Config configure Clair from configFile
|
||||
func Config() {
|
||||
fmtURI(viper.GetString("clair.uri"), viper.GetInt("clair.port"))
|
||||
healthPort = viper.GetInt("clair.healthPort")
|
||||
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")
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
func IsHealthy() bool {
|
||||
healthURI := strings.Replace(uri, "6060/v1", strconv.Itoa(healthPort), 1) + "/health"
|
||||
logrus.Debugln("requesting health on: " + healthURI)
|
||||
response, err := http.Get(healthURI)
|
||||
if err != nil {
|
||||
|
||||
|
@ -26,8 +26,7 @@ func ReportAsHTML(analyzes ImageAnalysis) (string, error) {
|
||||
}
|
||||
|
||||
funcs := template.FuncMap{
|
||||
"invertedPriorities": InvertedPriorities,
|
||||
"vulnerabilities": Vulnerabilities,
|
||||
"vulnerabilities": vulnerabilities,
|
||||
"sortedVulnerabilities": SortedVulnerabilities,
|
||||
}
|
||||
|
||||
@ -41,7 +40,7 @@ func ReportAsHTML(analyzes ImageAnalysis) (string, error) {
|
||||
return doc.String(), nil
|
||||
}
|
||||
|
||||
func InvertedPriorities() []types.Priority {
|
||||
func invertedPriorities() []types.Priority {
|
||||
ip := make([]types.Priority, len(types.Priorities))
|
||||
for i, j := 0, len(types.Priorities)-1; i <= j; i, j = i+1, j-1 {
|
||||
ip[i], ip[j] = types.Priorities[j], types.Priorities[i]
|
||||
@ -51,15 +50,15 @@ func InvertedPriorities() []types.Priority {
|
||||
}
|
||||
|
||||
//Vulnerabilities return a list a vulnerabilities
|
||||
func Vulnerabilities(imageAnalysis ImageAnalysis) map[types.Priority][]VulnerabilityWithFeature {
|
||||
func vulnerabilities(imageAnalysis ImageAnalysis) map[types.Priority][]vulnerabilityWithFeature {
|
||||
|
||||
result := make(map[types.Priority][]VulnerabilityWithFeature)
|
||||
result := make(map[types.Priority][]vulnerabilityWithFeature)
|
||||
|
||||
l := imageAnalysis.Layers[len(imageAnalysis.Layers)-1]
|
||||
for _, f := range l.Layer.Features {
|
||||
for _, v := range f.Vulnerabilities {
|
||||
|
||||
result[types.Priority(v.Severity)] = append(result[types.Priority(v.Severity)], VulnerabilityWithFeature{Vulnerability: v, Feature: f.Name + ":" + f.Version})
|
||||
result[types.Priority(v.Severity)] = append(result[types.Priority(v.Severity)], vulnerabilityWithFeature{Vulnerability: v, Feature: f.Name + ":" + f.Version})
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +74,7 @@ func SortedVulnerabilities(imageAnalysis ImageAnalysis) []v1.Feature {
|
||||
for _, f := range l.Layer.Features {
|
||||
if len(f.Vulnerabilities) > 0 {
|
||||
vulnerabilities := []v1.Vulnerability{}
|
||||
for _, p := range InvertedPriorities() {
|
||||
for _, p := range invertedPriorities() {
|
||||
for _, v := range f.Vulnerabilities {
|
||||
if types.Priority(v.Severity) == p {
|
||||
vulnerabilities = append(vulnerabilities, v)
|
||||
|
@ -83,7 +83,7 @@ func templatesAnalysisTemplateHtml() (*asset, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "templates/analysis-template.html", size: 16409, mode: os.FileMode(420), modTime: time.Unix(1463667501, 0)}
|
||||
info := bindataFileInfo{name: "templates/analysis-template.html", size: 16409, mode: os.FileMode(420), modTime: time.Unix(1463760760, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user