clair: move worker to top level package

This commit is contained in:
Jimmy Zelinskie 2017-01-26 18:24:04 -05:00
parent e5c567f3f9
commit 889615276a
6 changed files with 12 additions and 17 deletions

View File

@ -25,11 +25,11 @@ import (
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/coreos/clair"
"github.com/coreos/clair/api/context" "github.com/coreos/clair/api/context"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/pkg/commonerr" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/pkg/tarutil" "github.com/coreos/clair/pkg/tarutil"
"github.com/coreos/clair/worker"
) )
const ( const (
@ -109,11 +109,11 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx
return postLayerRoute, http.StatusBadRequest return postLayerRoute, http.StatusBadRequest
} }
err = worker.Process(ctx.Store, request.Layer.Format, request.Layer.Name, request.Layer.ParentName, request.Layer.Path, request.Layer.Headers) err = clair.ProcessLayer(ctx.Store, request.Layer.Format, request.Layer.Name, request.Layer.ParentName, request.Layer.Path, request.Layer.Headers)
if err != nil { if err != nil {
if err == tarutil.ErrCouldNotExtract || if err == tarutil.ErrCouldNotExtract ||
err == tarutil.ErrExtractedFileTooBig || err == tarutil.ErrExtractedFileTooBig ||
err == worker.ErrUnsupported { err == clair.ErrUnsupported {
writeResponse(w, r, statusUnprocessableEntity, LayerEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, statusUnprocessableEntity, LayerEnvelope{Error: &Error{err.Error()}})
return postLayerRoute, statusUnprocessableEntity return postLayerRoute, statusUnprocessableEntity
} }
@ -133,7 +133,7 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx
Path: request.Layer.Path, Path: request.Layer.Path,
Headers: request.Layer.Headers, Headers: request.Layer.Headers,
Format: request.Layer.Format, Format: request.Layer.Format,
IndexedByVersion: worker.Version, IndexedByVersion: clair.Version,
}}) }})
return postLayerRoute, http.StatusCreated return postLayerRoute, http.StatusCreated
} }

View File

@ -12,15 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package worker implements the logic to extract useful informations from a package clair
// container layer and store it in the database.
package worker
import ( import (
"regexp" "regexp"
"github.com/coreos/pkg/capnslog"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/featurefmt" "github.com/coreos/clair/ext/featurefmt"
"github.com/coreos/clair/ext/featurens" "github.com/coreos/clair/ext/featurens"
@ -36,8 +32,6 @@ const (
) )
var ( var (
log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker")
// ErrUnsupported is the error that should be raised when an OS or package // ErrUnsupported is the error that should be raised when an OS or package
// manager is not supported. // manager is not supported.
ErrUnsupported = commonerr.NewBadRequestError("worker: OS and/or package manager are not supported") ErrUnsupported = commonerr.NewBadRequestError("worker: OS and/or package manager are not supported")
@ -54,11 +48,12 @@ func cleanURL(str string) string {
return urlParametersRegexp.ReplaceAllString(str, "") return urlParametersRegexp.ReplaceAllString(str, "")
} }
// Process detects the Namespace of a layer, the features it adds/removes, and // ProcessLayer detects the Namespace of a layer, the features it adds/removes,
// then stores everything in the database. // and then stores everything in the database.
// TODO(Quentin-M): We could have a goroutine that looks for layers that have been analyzed with an //
// older engine version and that processes them. // TODO(Quentin-M): We could have a goroutine that looks for layers that have
func Process(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error { // been analyzed with an older engine version and that processes them.
func ProcessLayer(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error {
// Verify parameters. // Verify parameters.
if name == "" { if name == "" {
return commonerr.NewBadRequestError("could not process a layer which does not have a name") return commonerr.NewBadRequestError("could not process a layer which does not have a name")

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package worker package clair
import ( import (
"path/filepath" "path/filepath"