fix report

This commit is contained in:
jgsqware 2016-06-22 11:22:22 +02:00
parent 0015c86ec3
commit 69679e0ef1
7 changed files with 33 additions and 21 deletions

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
@ -74,11 +73,6 @@ func Push(image reference.Named, manifest schema1.SignedManifest) error {
parentID = payload.Layer.Name parentID = payload.Layer.Name
} }
} }
if config.IsLocal {
if err := cleanLocal(); err != nil {
return err
}
}
return nil return nil
} }
@ -135,17 +129,6 @@ func GetRegistryMapping(layerDigest string) (string, error) {
return registryURI, nil return registryURI, nil
} }
func cleanLocal() error {
logrus.Debugln("cleaning temporary local repository")
err := os.RemoveAll(config.TmpLocal())
if err != nil {
return fmt.Errorf("cleaning temporary local repository: %v", err)
}
return nil
}
func init() { func init() {
registryMapping = map[string]string{} registryMapping = map[string]string{}
} }

View File

@ -83,7 +83,7 @@ func templatesAnalysisTemplateHtml() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "templates/analysis-template.html", size: 16403, mode: os.FileMode(420), modTime: time.Unix(1463761868, 0)} info := bindataFileInfo{name: "templates/analysis-template.html", size: 16403, mode: os.FileMode(420), modTime: time.Unix(1466557241, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }

View File

@ -26,13 +26,18 @@ var reportCmd = &cobra.Command{
config.ImageName = args[0] config.ImageName = args[0]
image, manifest, err := docker.RetrieveManifest(config.ImageName, true) image, manifest, err := docker.RetrieveManifest(config.ImageName, true)
if err != nil { if err != nil {
fmt.Println(errInternalError) fmt.Println(errInternalError)
logrus.Fatalf("retrieving manifest for %q: %v", config.ImageName, err) logrus.Fatalf("retrieving manifest for %q: %v", config.ImageName, err)
} }
analyzes := clair.Analyze(image, manifest) analyzes := clair.Analyze(image, manifest)
imageName := strings.Replace(analyzes.ImageName, "/", "-", -1) + "-" + analyzes.Tag imageName := strings.Replace(analyzes.ImageName, "/", "-", -1)
if analyzes.Tag != "" {
imageName += "-" + analyzes.Tag
}
switch clair.Report.Format { switch clair.Report.Format {
case "html": case "html":
html, err := clair.ReportAsHTML(analyzes) html, err := clair.ReportAsHTML(analyzes)

View File

@ -44,6 +44,12 @@ var RootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd. // This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() { func Execute() {
if err := RootCmd.Execute(); err != nil { if err := RootCmd.Execute(); err != nil {
err = config.Clean()
fmt.Println(err)
os.Exit(-1)
}
if err := config.Clean(); err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(-1) os.Exit(-1)
} }

View File

@ -314,3 +314,16 @@ func Docker0InterfaceIP() (string, error) {
} }
return localIP.String(), nil return localIP.String(), nil
} }
func Clean() error {
if IsLocal {
logrus.Debugln("cleaning temporary local repository")
err := os.RemoveAll(TmpLocal())
if err != nil {
return fmt.Errorf("cleaning temporary local repository: %v", err)
}
}
return nil
}

View File

@ -51,7 +51,7 @@ clair:
updater: updater:
# Frequency the database will be updated with vulnerabilities from the default data sources # Frequency the database will be updated with vulnerabilities from the default data sources
# The value 0 disables the updater entirely. # The value 0 disables the updater entirely.
interval: 0 interval: 2h
notifier: notifier:
# Number of attempts before the notification is marked as failed to be sent # Number of attempts before the notification is marked as failed to be sent

View File

@ -37,6 +37,11 @@ func GetLocalManifest(imageName string, withExport bool) (reference.Named, schem
if err != nil { if err != nil {
return nil, schema1.SignedManifest{}, err return nil, schema1.SignedManifest{}, err
} }
manifest.Name = image.Name()
if strings.Contains(image.String(), ":") {
manifest.Tag = strings.SplitAfter(image.String(), ":")[1]
}
return image, manifest, err return image, manifest, err
} }