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"
"fmt"
"net/http"
"os"
"strings"
"github.com/Sirupsen/logrus"
@ -74,11 +73,6 @@ func Push(image reference.Named, manifest schema1.SignedManifest) error {
parentID = payload.Layer.Name
}
}
if config.IsLocal {
if err := cleanLocal(); err != nil {
return err
}
}
return nil
}
@ -135,17 +129,6 @@ func GetRegistryMapping(layerDigest string) (string, error) {
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() {
registryMapping = map[string]string{}
}

View File

@ -83,7 +83,7 @@ func templatesAnalysisTemplateHtml() (*asset, error) {
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}
return a, nil
}

View File

@ -26,13 +26,18 @@ var reportCmd = &cobra.Command{
config.ImageName = args[0]
image, manifest, err := docker.RetrieveManifest(config.ImageName, true)
if err != nil {
fmt.Println(errInternalError)
logrus.Fatalf("retrieving manifest for %q: %v", config.ImageName, err)
}
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 {
case "html":
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.
func Execute() {
if err := RootCmd.Execute(); err != nil {
err = config.Clean()
fmt.Println(err)
os.Exit(-1)
}
if err := config.Clean(); err != nil {
fmt.Println(err)
os.Exit(-1)
}

View File

@ -314,3 +314,16 @@ func Docker0InterfaceIP() (string, error) {
}
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:
# Frequency the database will be updated with vulnerabilities from the default data sources
# The value 0 disables the updater entirely.
interval: 0
interval: 2h
notifier:
# Number of attempts before the notification is marked as failed to be sent

View File

@ -22,7 +22,7 @@ import (
//GetLocalManifest retrieve manifest for local image
func GetLocalManifest(imageName string, withExport bool) (reference.Named, schema1.SignedManifest, error) {
image, err := reference.ParseNamed(imageName)
if err != nil {
return nil, schema1.SignedManifest{}, err
@ -37,6 +37,11 @@ func GetLocalManifest(imageName string, withExport bool) (reference.Named, schem
if err != nil {
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
}