Skip to content

Commit

Permalink
clair: move worker to top level package
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Jan 26, 2017
1 parent e5c567f commit 8896152
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions api/v1/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 7 additions & 12 deletions worker/worker.go → worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion worker/worker_test.go → worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8896152

Please sign in to comment.