示例#1
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
}
示例#2
0
//Analyse return Clair Image analysis
func Analyse(image Image) clair.ImageAnalysis {
	c := len(image.FsLayers)
	res := []v1.LayerEnvelope{}

	for i := range image.FsLayers {
		l := image.FsLayers[c-i-1].BlobSum
		lShort := xstrings.Substr(l, 0, 12)

		if a, err := clair.Analyse(l); err != nil {
			logrus.Infof("analysing layer [%v] %d/%d: %v", lShort, i+1, c, err)
		} else {
			logrus.Infof("analysing layer [%v] %d/%d", lShort, i+1, c)
			res = append(res, a)
		}
	}
	return clair.ImageAnalysis{
		Registry:  xstrings.TrimPrefixSuffix(image.Registry, "http://", "/v2"),
		ImageName: image.Name,
		Tag:       image.Tag,
		Layers:    res,
	}
}