From 889615276af2c1d5ac04971a237e09d2e9fa6bda Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 26 Jan 2017 18:24:04 -0500 Subject: [PATCH] clair: move worker to top level package --- api/v1/routes.go | 8 ++++---- .../DistUpgrade/blank.tar.gz | Bin .../DistUpgrade/jessie.tar.gz | Bin .../DistUpgrade/wheezy.tar.gz | Bin worker/worker.go => worker.go | 19 +++++++----------- worker/worker_test.go => worker_test.go | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) rename {worker/testdata => testdata}/DistUpgrade/blank.tar.gz (100%) rename {worker/testdata => testdata}/DistUpgrade/jessie.tar.gz (100%) rename {worker/testdata => testdata}/DistUpgrade/wheezy.tar.gz (100%) rename worker/worker.go => worker.go (92%) rename worker/worker_test.go => worker_test.go (99%) diff --git a/api/v1/routes.go b/api/v1/routes.go index bde7560d..97048eec 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -25,11 +25,11 @@ import ( "github.com/julienschmidt/httprouter" "github.com/prometheus/client_golang/prometheus" + "github.com/coreos/clair" "github.com/coreos/clair/api/context" "github.com/coreos/clair/database" "github.com/coreos/clair/pkg/commonerr" "github.com/coreos/clair/pkg/tarutil" - "github.com/coreos/clair/worker" ) const ( @@ -109,11 +109,11 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx 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 == tarutil.ErrCouldNotExtract || err == tarutil.ErrExtractedFileTooBig || - err == worker.ErrUnsupported { + err == clair.ErrUnsupported { writeResponse(w, r, statusUnprocessableEntity, LayerEnvelope{Error: &Error{err.Error()}}) return postLayerRoute, statusUnprocessableEntity } @@ -133,7 +133,7 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx Path: request.Layer.Path, Headers: request.Layer.Headers, Format: request.Layer.Format, - IndexedByVersion: worker.Version, + IndexedByVersion: clair.Version, }}) return postLayerRoute, http.StatusCreated } diff --git a/worker/testdata/DistUpgrade/blank.tar.gz b/testdata/DistUpgrade/blank.tar.gz similarity index 100% rename from worker/testdata/DistUpgrade/blank.tar.gz rename to testdata/DistUpgrade/blank.tar.gz diff --git a/worker/testdata/DistUpgrade/jessie.tar.gz b/testdata/DistUpgrade/jessie.tar.gz similarity index 100% rename from worker/testdata/DistUpgrade/jessie.tar.gz rename to testdata/DistUpgrade/jessie.tar.gz diff --git a/worker/testdata/DistUpgrade/wheezy.tar.gz b/testdata/DistUpgrade/wheezy.tar.gz similarity index 100% rename from worker/testdata/DistUpgrade/wheezy.tar.gz rename to testdata/DistUpgrade/wheezy.tar.gz diff --git a/worker/worker.go b/worker.go similarity index 92% rename from worker/worker.go rename to worker.go index 97bcd9f1..92aeea2f 100644 --- a/worker/worker.go +++ b/worker.go @@ -12,15 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package worker implements the logic to extract useful informations from a -// container layer and store it in the database. -package worker +package clair import ( "regexp" - "github.com/coreos/pkg/capnslog" - "github.com/coreos/clair/database" "github.com/coreos/clair/ext/featurefmt" "github.com/coreos/clair/ext/featurens" @@ -36,8 +32,6 @@ const ( ) var ( - log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker") - // ErrUnsupported is the error that should be raised when an OS or package // manager is 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, "") } -// Process detects the Namespace of a layer, the features it adds/removes, 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. -func Process(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error { +// ProcessLayer detects the Namespace of a layer, the features it adds/removes, +// 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. +func ProcessLayer(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error { // Verify parameters. if name == "" { return commonerr.NewBadRequestError("could not process a layer which does not have a name") diff --git a/worker/worker_test.go b/worker_test.go similarity index 99% rename from worker/worker_test.go rename to worker_test.go index 26e104fa..34d6f039 100644 --- a/worker/worker_test.go +++ b/worker_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package worker +package clair import ( "path/filepath"