rename analyse to analyze
This commit is contained in:
parent
fec01ae1ee
commit
afd0d46d04
@ -20,13 +20,13 @@ clairctl can be used for Docker Hub and self-hosted Registry
|
|||||||
# Command
|
# Command
|
||||||
|
|
||||||
```
|
```
|
||||||
Analyse your docker image with Clair, directly from your registry.
|
Analyze your docker image with Clair, directly from your registry.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
clairctl [command]
|
clairctl [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
analyse Analyse Docker image
|
analyze Analyze Docker image
|
||||||
health Get Health of clairctl and underlying services
|
health Get Health of clairctl and underlying services
|
||||||
login Log in to a Docker registry
|
login Log in to a Docker registry
|
||||||
logout Log out from a Docker registry
|
logout Log out from a Docker registry
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/coreos/clair/api/v1"
|
"github.com/coreos/clair/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Analyse get Analysis os specified layer
|
//Analyze get Analysis os specified layer
|
||||||
func Analyse(id string) (v1.LayerEnvelope, error) {
|
func Analyze(id string) (v1.LayerEnvelope, error) {
|
||||||
|
|
||||||
lURI := fmt.Sprintf("%v/layers/%v?vulnerabilities", uri, id)
|
lURI := fmt.Sprintf("%v/layers/%v?vulnerabilities", uri, id)
|
||||||
// lURI := fmt.Sprintf("%v/layers/%v/vulnerabilities?minimumPriority=%v", uri, id, priority)
|
// lURI := fmt.Sprintf("%v/layers/%v/vulnerabilities?minimumPriority=%v", uri, id, priority)
|
@ -15,16 +15,16 @@ type ReportConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//ReportAsHTML report analysis as HTML
|
//ReportAsHTML report analysis as HTML
|
||||||
func ReportAsHTML(analyses ImageAnalysis) (string, error) {
|
func ReportAsHTML(analyzes ImageAnalysis) (string, error) {
|
||||||
asset, err := Asset("templates/analysis-template.html")
|
asset, err := Asset("templates/analysis-template.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("accessing template: %v", err)
|
return "", fmt.Errorf("accessing template: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
templte := template.Must(template.New("analysis-template").Parse(string(asset)))
|
templte := template.Must(template.New("analysis-template").Parse(string(asset)))
|
||||||
|
|
||||||
var doc bytes.Buffer
|
var doc bytes.Buffer
|
||||||
err = templte.Execute(&doc, analyses)
|
err = templte.Execute(&doc, analyzes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("rendering HTML report: %v", err)
|
return "", fmt.Errorf("rendering HTML report: %v", err)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const analyseTplt = `
|
const analyzeTplt = `
|
||||||
Image: {{.String}}
|
Image: {{.String}}
|
||||||
{{.Layers | len}} layers found
|
{{.Layers | len}} layers found
|
||||||
{{$ia := .}}
|
{{$ia := .}}
|
||||||
@ -21,20 +21,20 @@ Image: {{.String}}
|
|||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
var analyseCmd = &cobra.Command{
|
var analyzeCmd = &cobra.Command{
|
||||||
Use: "analyse IMAGE",
|
Use: "analyze IMAGE",
|
||||||
Short: "Analyse Docker image",
|
Short: "Analyze Docker image",
|
||||||
Long: `Analyse a Docker image with Clair, against Ubuntu, Red hat and Debian vulnerabilities databases`,
|
Long: `Analyze a Docker image with Clair, against Ubuntu, Red hat and Debian vulnerabilities databases`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
fmt.Printf("clairctl: \"analyse\" requires a minimum of 1 argument")
|
fmt.Printf("clairctl: \"analyze\" requires a minimum of 1 argument")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ia := analyse(args[0])
|
ia := analyze(args[0])
|
||||||
|
|
||||||
err := template.Must(template.New("analysis").Parse(analyseTplt)).Execute(os.Stdout, ia)
|
err := template.Must(template.New("analysis").Parse(analyzeTplt)).Execute(os.Stdout, ia)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(errInternalError)
|
fmt.Println(errInternalError)
|
||||||
logrus.Fatalf("rendering analysis: %v", err)
|
logrus.Fatalf("rendering analysis: %v", err)
|
||||||
@ -42,7 +42,7 @@ var analyseCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func analyse(imageName string) clair.ImageAnalysis {
|
func analyze(imageName string) clair.ImageAnalysis {
|
||||||
var err error
|
var err error
|
||||||
var image docker.Image
|
var image docker.Image
|
||||||
|
|
||||||
@ -71,12 +71,12 @@ func analyse(imageName string) clair.ImageAnalysis {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return docker.Analyse(image)
|
return docker.Analyze(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(analyseCmd)
|
RootCmd.AddCommand(analyzeCmd)
|
||||||
analyseCmd.Flags().BoolVarP(&docker.IsLocal, "local", "l", false, "Use local images")
|
analyzeCmd.Flags().BoolVarP(&docker.IsLocal, "local", "l", false, "Use local images")
|
||||||
analyseCmd.Flags().StringP("priority", "p", "Low", "Vulnerabilities priority [Low, Medium, High, Critical]")
|
analyzeCmd.Flags().StringP("priority", "p", "Low", "Vulnerabilities priority [Low, Medium, High, Critical]")
|
||||||
viper.BindPFlag("clair.priority", analyseCmd.Flags().Lookup("priority"))
|
viper.BindPFlag("clair.priority", analyzeCmd.Flags().Lookup("priority"))
|
||||||
}
|
}
|
@ -23,11 +23,11 @@ var reportCmd = &cobra.Command{
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
analyses := analyse(args[0])
|
analyzes := analyze(args[0])
|
||||||
imageName := strings.Replace(analyses.ImageName, "/", "-", -1) + "-" + analyses.Tag
|
imageName := strings.Replace(analyzes.ImageName, "/", "-", -1) + "-" + analyzes.Tag
|
||||||
switch clair.Report.Format {
|
switch clair.Report.Format {
|
||||||
case "html":
|
case "html":
|
||||||
html, err := clair.ReportAsHTML(analyses)
|
html, err := clair.ReportAsHTML(analyzes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(errInternalError)
|
fmt.Println(errInternalError)
|
||||||
logrus.Fatalf("generating HTML report: %v", err)
|
logrus.Fatalf("generating HTML report: %v", err)
|
||||||
@ -39,7 +39,7 @@ var reportCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "json":
|
case "json":
|
||||||
json, err := xstrings.ToIndentJSON(analyses)
|
json, err := xstrings.ToIndentJSON(analyzes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(errInternalError)
|
fmt.Println(errInternalError)
|
||||||
|
@ -31,7 +31,7 @@ var logLevel string
|
|||||||
// RootCmd represents the base command when called without any subcommands
|
// RootCmd represents the base command when called without any subcommands
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
Use: "clairctl",
|
Use: "clairctl",
|
||||||
Short: "Analyse your docker image with Clair, directly from your registry or local images.",
|
Short: "Analyze your docker image with Clair, directly from your registry or local images.",
|
||||||
Long: ``,
|
Long: ``,
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/coreos/clair/cmd/clairctl/xstrings"
|
"github.com/coreos/clair/cmd/clairctl/xstrings"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Analyse return Clair Image analysis
|
//Analyze return Clair Image analysis
|
||||||
func Analyse(image Image) clair.ImageAnalysis {
|
func Analyze(image Image) clair.ImageAnalysis {
|
||||||
c := len(image.FsLayers)
|
c := len(image.FsLayers)
|
||||||
res := []v1.LayerEnvelope{}
|
res := []v1.LayerEnvelope{}
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ func Analyse(image Image) clair.ImageAnalysis {
|
|||||||
l := image.FsLayers[c-i-1].BlobSum
|
l := image.FsLayers[c-i-1].BlobSum
|
||||||
lShort := xstrings.Substr(l, 0, 12)
|
lShort := xstrings.Substr(l, 0, 12)
|
||||||
|
|
||||||
if a, err := clair.Analyse(l); err != nil {
|
if a, err := clair.Analyze(l); err != nil {
|
||||||
logrus.Infof("analysing layer [%v] %d/%d: %v", lShort, i+1, c, err)
|
logrus.Infof("analysing layer [%v] %d/%d: %v", lShort, i+1, c, err)
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("analysing layer [%v] %d/%d", lShort, i+1, c)
|
logrus.Infof("analysing layer [%v] %d/%d", lShort, i+1, c)
|
||||||
|
Loading…
Reference in New Issue
Block a user