Beispiel #1
0
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)
}
Beispiel #2
0
//PushHandler push image to Clair
func PushHandler(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 image docker.Image
	if !docker.IsLocal {
		var err error
		image, err = docker.Pull(parseImageURL(request))
		if err != nil {
			return err
		}
	} else {
		var err error
		image, err = docker.Parse(parseImageURL(request))
		if err != nil {
			return err
		}
		err = docker.Prepare(&image)
		logrus.Debugf("prepared image layers: %d", len(image.FsLayers))
		if err != nil {
			return err
		}
	}

	logrus.Info("Pushing Image")
	if err := docker.Push(image); err != nil {
		return err
	}
	rw.WriteHeader(http.StatusCreated)
	return nil
}
Beispiel #3
0
func getHyperclairURI(imageName string, path ...string) (string, error) {
	image, err := docker.Parse(imageName)
	if err != nil {
		return "", err
	}
	registry := xstrings.TrimPrefixSuffix(image.Registry, "http://", "/v2")
	registry = xstrings.TrimPrefixSuffix(registry, "https://", "/v2")
	url := fmt.Sprintf("%v/%v", HyperclairURI, image.Name)
	for _, p := range path {
		url = fmt.Sprintf("%v/%v", url, p)
	}

	if local {
		registry = "localhost:60000"
	}

	url = fmt.Sprintf("%v?realm=%v&reference=%v", url, registry, image.Tag)

	return url, nil
}
Beispiel #4
0
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
}
Beispiel #5
0
		var image docker.Image
		if !docker.IsLocal {
			var err error
			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 {
			var err error
			image, err = docker.Parse(imageName)
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("parsing local image %q: %v", imageName, err)
			}
			err = docker.Prepare(&image)
			logrus.Debugf("prepared image layers: %d", len(image.FsLayers))
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("preparing local image %q from history: %v", imageName, err)
			}
		}

		logrus.Info("Pushing Image")
		if err := docker.Push(image); err != nil {
			if err != nil {