Exemple #1
0
func ReportHandler(rw http.ResponseWriter, request *http.Request) error {
	rw.Header().Set("Content-Type", "text/html")
	image, err := docker.Pull(parseImageURL(request))

	if err != nil {
		return err
	}

	analyses := docker.Analyse(image)
	analysesHTML, err := clair.ReportAsHTML(analyses)
	if err != nil {
		return err
	}

	fmt.Fprint(rw, analysesHTML)
	return nil
}
Exemple #2
0
	Long:  `Generate Docker Image vulnerabilities report as HTML or JSON`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			fmt.Printf("hyperclair: \"report\" requires a minimum of 1 argument")
			os.Exit(1)
		}

		if local {
			StartLocalServer()
		}

		analyses := Analyse(args[0])
		imageName := strings.Replace(analyses.ImageName, "/", "-", -1) + "-" + analyses.Tag
		switch clair.Report.Format {
		case "html":
			html, err := clair.ReportAsHTML(analyses)
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("generating HTML report: %v", err)
			}
			err = saveReport(imageName, string(html))
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("saving HTML report: %v", err)
			}

		case "json":
			json, err := xstrings.ToIndentJSON(analyses)

			if err != nil {
				fmt.Println(xerrors.InternalError)