Skip to content

Commit

Permalink
worker: move each data detector to their own packages and remove imag…
Browse files Browse the repository at this point in the history
…e format whitelist
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 3ecb8b6 commit 90fe137
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
6 changes: 6 additions & 0 deletions cmd/clair/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ import (

// Register components
_ "github.com/coreos/clair/notifier/notifiers"

_ "github.com/coreos/clair/updater/fetchers/debian"
_ "github.com/coreos/clair/updater/fetchers/rhel"
_ "github.com/coreos/clair/updater/fetchers/ubuntu"

_ "github.com/coreos/clair/worker/detectors/data/aci"
_ "github.com/coreos/clair/worker/detectors/data/docker"

_ "github.com/coreos/clair/worker/detectors/feature/dpkg"
_ "github.com/coreos/clair/worker/detectors/feature/rpm"

_ "github.com/coreos/clair/worker/detectors/namespace/aptsources"
_ "github.com/coreos/clair/worker/detectors/namespace/lsbrelease"
_ "github.com/coreos/clair/worker/detectors/namespace/osrelease"
Expand Down
2 changes: 1 addition & 1 deletion worker/detectors/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ func DetectData(path string, format string, toExtract []string, maxFileSize int6
}
}

return nil, nil
return nil, cerrors.NewBadRequestError(fmt.Sprintf("unsupported image format '%s'", format))
}
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 data
package aci

import (
"io"
Expand Down
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 data
package docker

import (
"io"
Expand Down
18 changes: 4 additions & 14 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ var (
ErrParentUnknown = errors.New("worker: parent layer is unknown, it must be processed first")

// SupportedNamespacePrefixes is the list of namespace prefixes that the worker supports.
// TODO(Quentin-M): We should remove this from here and allow registered Namespace Detectors to
// tell which prefixes are supported. Otherwise, it doesn't make sense to allow registering them.
// Similarly, we could do the same thing with Data Detectors to detect early unsupported
// ImageFormats.
SupportedNamespacePrefixes = []string{"debian:", "ubuntu:", "centos:"}

// SupportedImageFormat is the list of image formats that the worker supports.
SupportedImageFormat = []string{"Docker", "ACI"}
)

// Process detects the Namespace of a layer, the features it adds/removes, and
Expand All @@ -72,17 +73,6 @@ func Process(datastore database.Datastore, name, parentName, path, imageFormat s
return cerrors.NewBadRequestError("could not process a layer which does not have a format")
}

isSupported := false
for _, format := range SupportedImageFormat {
if strings.EqualFold(imageFormat, format) {
isSupported = true
break
}
}
if !isSupported {
return cerrors.NewBadRequestError("could not process a layer which does not have a supported format")
}

log.Debugf("layer %s: processing (Location: %s, Engine version: %d, Parent: %s, Format: %s)",
name, utils.CleanURL(path), Version, parentName, imageFormat)

Expand Down
4 changes: 2 additions & 2 deletions worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"github.com/coreos/clair/database/pgsql"
"github.com/coreos/clair/utils/types"
"github.com/stretchr/testify/assert"

// Register the required detectors.
_ "github.com/coreos/clair/worker/detectors/data"
_ "github.com/coreos/clair/worker/detectors/data/docker"
_ "github.com/coreos/clair/worker/detectors/feature/dpkg"
_ "github.com/coreos/clair/worker/detectors/namespace/aptsources"
_ "github.com/coreos/clair/worker/detectors/namespace/osrelease"
Expand Down

0 comments on commit 90fe137

Please sign in to comment.