func analyse(imageName string) clair.ImageAnalysis { var err error var image docker.Image if !docker.IsLocal { image, err = docker.Pull(imageName) if err != nil { if err == xerrors.NotFound { fmt.Println(err) } else { fmt.Println(xerrors.InternalError) } logrus.Fatalf("pulling image %q: %v", imageName, err) } } else { image, err = docker.Parse(imageName) if err != nil { fmt.Println(xerrors.InternalError) logrus.Fatalf("parsing local image %q: %v", imageName, err) } docker.FromHistory(&image) if err != nil { fmt.Println(xerrors.InternalError) logrus.Fatalf("getting local image %q from history: %v", imageName, err) } } return docker.Analyse(image) }
func AnalyseHandler(rw http.ResponseWriter, request *http.Request) error { local := request.URL.Query()["local"] docker.IsLocal = len(local) > 0 logrus.Debugf("Hyperclair is local: %v", docker.IsLocal) var err error var image docker.Image if !docker.IsLocal { image, err = docker.Pull(parseImageURL(request)) if err != nil { return err } } else { image, err = docker.Parse(parseImageURL(request)) if err != nil { return err } docker.FromHistory(&image) if err != nil { return err } } analyses := docker.Analyse(image) analysesJSON, err := xstrings.ToIndentJSON(analyses) if err != nil { return err } rw.Header().Set("Content-Type", "application/json") fmt.Fprint(rw, string(analysesJSON)) return nil }