コード例 #1
0
ファイル: clair.go プロジェクト: maquanyi/dockyard
func PutLayer(h History) error {
	if err := worker.Process(h.ID, h.Parent, h.localPath); err != nil {
		logrus.Debugf("End find err process: %v", err)
		return err
	}
	return nil
}
コード例 #2
0
ファイル: layers.go プロジェクト: jlamcanopy/clair
// POSTLayers analyzes a layer and returns the engine version that has been used
// for the analysis.
func POSTLayers(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	var parameters POSTLayersParameters
	if s, err := httputils.ParseHTTPBody(r, &parameters); err != nil {
		httputils.WriteHTTPError(w, s, err)
		return
	}

	// Process data.
	if err := worker.Process(parameters.ID, parameters.ParentID, parameters.Path); err != nil {
		httputils.WriteHTTPError(w, 0, err)
		return
	}

	// Get engine version and return.
	httputils.WriteHTTP(w, http.StatusCreated, struct{ Version string }{Version: strconv.Itoa(worker.Version)})
}
コード例 #3
0
ファイル: routes.go プロジェクト: robinjha/clair
func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
	request := LayerEnvelope{}
	err := decodeJSON(r, &request)
	if err != nil {
		writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{err.Error()}})
		return postLayerRoute, http.StatusBadRequest
	}

	if request.Layer == nil {
		writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{"failed to provide layer"}})
		return postLayerRoute, http.StatusBadRequest
	}

	err = worker.Process(ctx.Store, request.Layer.Format, request.Layer.Name, request.Layer.ParentName, request.Layer.Path, request.Layer.Headers)
	if err != nil {
		if err == utils.ErrCouldNotExtract ||
			err == utils.ErrExtractedFileTooBig ||
			err == worker.ErrUnsupported {
			writeResponse(w, r, statusUnprocessableEntity, LayerEnvelope{Error: &Error{err.Error()}})
			return postLayerRoute, statusUnprocessableEntity
		}

		if _, badreq := err.(*cerrors.ErrBadRequest); badreq {
			writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{err.Error()}})
			return postLayerRoute, http.StatusBadRequest
		}

		writeResponse(w, r, http.StatusInternalServerError, LayerEnvelope{Error: &Error{err.Error()}})
		return postLayerRoute, http.StatusInternalServerError
	}

	writeResponse(w, r, http.StatusCreated, LayerEnvelope{Layer: &Layer{
		Name:             request.Layer.Name,
		ParentName:       request.Layer.ParentName,
		Path:             request.Layer.Path,
		Headers:          request.Layer.Headers,
		Format:           request.Layer.Format,
		IndexedByVersion: worker.Version,
	}})
	return postLayerRoute, http.StatusCreated
}
コード例 #4
0
ファイル: clair.go プロジェクト: CodeJuan/dockyard
func ClairGetVulns(ID string, ParentID string, Path string) ([]*database.Vulnerability, error) {
	// Process data.
	logrus.Debugf("Start to get vulnerabilities: %v %v %v", ID, ParentID, Path)
	if err := worker.Process(ID, ParentID, Path); err != nil {
		logrus.Debugf("End find err process: %v", err)
		return nil, err
	}
	// Find layer
	layer, err := database.FindOneLayerByID(ID, []string{database.FieldLayerParent, database.FieldLayerPackages})
	if err != nil {
		logrus.Debugf("Cannot get layer: %v", err)
		return nil, err
	}

	// Find layer's packages.
	packagesNodes, err := layer.AllPackages()
	if err != nil {
		logrus.Debugf("Cannot get packages: %v", err)
		return nil, err
	}

	// Find vulnerabilities.
	return getVulnerabilitiesFromLayerPackagesNodes(packagesNodes, types.Priority(clairConf.VulnPriority), []string{database.FieldVulnerabilityID, database.FieldVulnerabilityLink, database.FieldVulnerabilityPriority, database.FieldVulnerabilityDescription})
}