pkg: cerrors -> commonerr

This commit is contained in:
Jimmy Zelinskie 2017-01-13 02:08:52 -05:00
parent 8dea744236
commit 78cef02fda
24 changed files with 120 additions and 119 deletions

View File

@ -27,8 +27,8 @@ import (
"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/tarutil" "github.com/coreos/clair/pkg/tarutil"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/worker" "github.com/coreos/clair/worker"
) )
@ -118,7 +118,7 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx
return postLayerRoute, statusUnprocessableEntity return postLayerRoute, statusUnprocessableEntity
} }
if _, badreq := err.(*cerrors.ErrBadRequest); badreq { if _, badreq := err.(*commonerr.ErrBadRequest); badreq {
writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{err.Error()}})
return postLayerRoute, http.StatusBadRequest return postLayerRoute, http.StatusBadRequest
} }
@ -143,7 +143,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
_, withVulnerabilities := r.URL.Query()["vulnerabilities"] _, withVulnerabilities := r.URL.Query()["vulnerabilities"]
dbLayer, err := ctx.Store.FindLayer(p.ByName("layerName"), withFeatures, withVulnerabilities) dbLayer, err := ctx.Store.FindLayer(p.ByName("layerName"), withFeatures, withVulnerabilities)
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, LayerEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, LayerEnvelope{Error: &Error{err.Error()}})
return getLayerRoute, http.StatusNotFound return getLayerRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -159,7 +159,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
func deleteLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) { func deleteLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
err := ctx.Store.DeleteLayer(p.ByName("layerName")) err := ctx.Store.DeleteLayer(p.ByName("layerName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, LayerEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, LayerEnvelope{Error: &Error{err.Error()}})
return deleteLayerRoute, http.StatusNotFound return deleteLayerRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -223,7 +223,7 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
} }
dbVulns, nextPage, err := ctx.Store.ListVulnerabilities(namespace, limit, page) dbVulns, nextPage, err := ctx.Store.ListVulnerabilities(namespace, limit, page)
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}})
return getVulnerabilityRoute, http.StatusNotFound return getVulnerabilityRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -273,7 +273,7 @@ func postVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Para
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true) err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case *cerrors.ErrBadRequest: case *commonerr.ErrBadRequest:
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}})
return postVulnerabilityRoute, http.StatusBadRequest return postVulnerabilityRoute, http.StatusBadRequest
default: default:
@ -290,7 +290,7 @@ func getVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Param
_, withFixedIn := r.URL.Query()["fixedIn"] _, withFixedIn := r.URL.Query()["fixedIn"]
dbVuln, err := ctx.Store.FindVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName")) dbVuln, err := ctx.Store.FindVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}})
return getVulnerabilityRoute, http.StatusNotFound return getVulnerabilityRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -334,7 +334,7 @@ func putVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Param
err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true) err = ctx.Store.InsertVulnerabilities([]database.Vulnerability{vuln}, true)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case *cerrors.ErrBadRequest: case *commonerr.ErrBadRequest:
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{err.Error()}})
return putVulnerabilityRoute, http.StatusBadRequest return putVulnerabilityRoute, http.StatusBadRequest
default: default:
@ -349,7 +349,7 @@ func putVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Param
func deleteVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) { func deleteVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
err := ctx.Store.DeleteVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName")) err := ctx.Store.DeleteVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}})
return deleteVulnerabilityRoute, http.StatusNotFound return deleteVulnerabilityRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -363,7 +363,7 @@ func deleteVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Pa
func getFixes(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) { func getFixes(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
dbVuln, err := ctx.Store.FindVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName")) dbVuln, err := ctx.Store.FindVulnerability(p.ByName("namespaceName"), p.ByName("vulnerabilityName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}})
return getFixesRoute, http.StatusNotFound return getFixesRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -403,11 +403,11 @@ func putFix(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *co
err = ctx.Store.InsertVulnerabilityFixes(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), []database.FeatureVersion{dbFix}) err = ctx.Store.InsertVulnerabilityFixes(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), []database.FeatureVersion{dbFix})
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case *cerrors.ErrBadRequest: case *commonerr.ErrBadRequest:
writeResponse(w, r, http.StatusBadRequest, FeatureEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusBadRequest, FeatureEnvelope{Error: &Error{err.Error()}})
return putFixRoute, http.StatusBadRequest return putFixRoute, http.StatusBadRequest
default: default:
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}})
return putFixRoute, http.StatusNotFound return putFixRoute, http.StatusNotFound
} }
@ -422,7 +422,7 @@ func putFix(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *co
func deleteFix(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) { func deleteFix(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
err := ctx.Store.DeleteVulnerabilityFix(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), p.ByName("fixName")) err := ctx.Store.DeleteVulnerabilityFix(p.ByName("vulnerabilityNamespace"), p.ByName("vulnerabilityName"), p.ByName("fixName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, FeatureEnvelope{Error: &Error{err.Error()}})
return deleteFixRoute, http.StatusNotFound return deleteFixRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -468,7 +468,7 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params
} }
dbNotification, nextPage, err := ctx.Store.GetNotification(p.ByName("notificationName"), limit, page) dbNotification, nextPage, err := ctx.Store.GetNotification(p.ByName("notificationName"), limit, page)
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, NotificationEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, NotificationEnvelope{Error: &Error{err.Error()}})
return deleteNotificationRoute, http.StatusNotFound return deleteNotificationRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {
@ -484,7 +484,7 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params
func deleteNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) { func deleteNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) (string, int) {
err := ctx.Store.DeleteNotification(p.ByName("notificationName")) err := ctx.Store.DeleteNotification(p.ByName("notificationName"))
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
writeResponse(w, r, http.StatusNotFound, NotificationEnvelope{Error: &Error{err.Error()}}) writeResponse(w, r, http.StatusNotFound, NotificationEnvelope{Error: &Error{err.Error()}})
return deleteNotificationRoute, http.StatusNotFound return deleteNotificationRoute, http.StatusNotFound
} else if err != nil { } else if err != nil {

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -21,12 +21,12 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
) )
func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) { func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) {
if feature.Name == "" { if feature.Name == "" {
return 0, cerrors.NewBadRequestError("could not find/insert invalid Feature") return 0, commonerr.NewBadRequestError("could not find/insert invalid Feature")
} }
// Do cache lookup. // Do cache lookup.
@ -65,7 +65,7 @@ func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) {
func (pgSQL *pgSQL) insertFeatureVersion(fv database.FeatureVersion) (id int, err error) { func (pgSQL *pgSQL) insertFeatureVersion(fv database.FeatureVersion) (id int, err error) {
err = versionfmt.Valid(fv.Feature.Namespace.VersionFormat, fv.Version) err = versionfmt.Valid(fv.Feature.Namespace.VersionFormat, fv.Version)
if err != nil { if err != nil {
return 0, cerrors.NewBadRequestError("could not find/insert invalid FeatureVersion") return 0, commonerr.NewBadRequestError("could not find/insert invalid FeatureVersion")
} }
// Do cache lookup. // Do cache lookup.

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -18,14 +18,14 @@ import (
"database/sql" "database/sql"
"time" "time"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
) )
// InsertKeyValue stores (or updates) a single key / value tuple. // InsertKeyValue stores (or updates) a single key / value tuple.
func (pgSQL *pgSQL) InsertKeyValue(key, value string) (err error) { func (pgSQL *pgSQL) InsertKeyValue(key, value string) (err error) {
if key == "" || value == "" { if key == "" || value == "" {
log.Warning("could not insert a flag which has an empty name or value") log.Warning("could not insert a flag which has an empty name or value")
return cerrors.NewBadRequestError("could not insert a flag which has an empty name or value") return commonerr.NewBadRequestError("could not insert a flag which has an empty name or value")
} }
defer observeQueryTime("InsertKeyValue", "all", time.Now()) defer observeQueryTime("InsertKeyValue", "all", time.Now())

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -22,8 +22,8 @@ import (
"github.com/guregu/null/zero" "github.com/guregu/null/zero"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
) )
func (pgSQL *pgSQL) FindLayer(name string, withFeatures, withVulnerabilities bool) (database.Layer, error) { func (pgSQL *pgSQL) FindLayer(name string, withFeatures, withVulnerabilities bool) (database.Layer, error) {
@ -247,12 +247,12 @@ func (pgSQL *pgSQL) InsertLayer(layer database.Layer) error {
// Verify parameters // Verify parameters
if layer.Name == "" { if layer.Name == "" {
log.Warning("could not insert a layer which has an empty Name") log.Warning("could not insert a layer which has an empty Name")
return cerrors.NewBadRequestError("could not insert a layer which has an empty Name") return commonerr.NewBadRequestError("could not insert a layer which has an empty Name")
} }
// Get a potentially existing layer. // Get a potentially existing layer.
existingLayer, err := pgSQL.FindLayer(layer.Name, true, false) existingLayer, err := pgSQL.FindLayer(layer.Name, true, false)
if err != nil && err != cerrors.ErrNotFound { if err != nil && err != commonerr.ErrNotFound {
return err return err
} else if err == nil { } else if err == nil {
if existingLayer.EngineVersion >= layer.EngineVersion { if existingLayer.EngineVersion >= layer.EngineVersion {
@ -271,7 +271,7 @@ func (pgSQL *pgSQL) InsertLayer(layer database.Layer) error {
if layer.Parent != nil { if layer.Parent != nil {
if layer.Parent.ID == 0 { if layer.Parent.ID == 0 {
log.Warning("Parent is expected to be retrieved from database when inserting a layer.") log.Warning("Parent is expected to be retrieved from database when inserting a layer.")
return cerrors.NewBadRequestError("Parent is expected to be retrieved from database when inserting a layer.") return commonerr.NewBadRequestError("Parent is expected to be retrieved from database when inserting a layer.")
} }
parentID = zero.IntFrom(int64(layer.Parent.ID)) parentID = zero.IntFrom(int64(layer.Parent.ID))
@ -429,7 +429,7 @@ func (pgSQL *pgSQL) DeleteLayer(name string) error {
} }
if affected <= 0 { if affected <= 0 {
return cerrors.ErrNotFound return commonerr.ErrNotFound
} }
return nil return nil

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -363,19 +363,19 @@ func testInsertLayerUpdate(t *testing.T, datastore database.Datastore) {
func testInsertLayerDelete(t *testing.T, datastore database.Datastore) { func testInsertLayerDelete(t *testing.T, datastore database.Datastore) {
err := datastore.DeleteLayer("TestInsertLayerX") err := datastore.DeleteLayer("TestInsertLayerX")
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
err = datastore.DeleteLayer("TestInsertLayer3") err = datastore.DeleteLayer("TestInsertLayer3")
assert.Nil(t, err) assert.Nil(t, err)
_, err = datastore.FindLayer("TestInsertLayer3", false, false) _, err = datastore.FindLayer("TestInsertLayer3", false, false)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
_, err = datastore.FindLayer("TestInsertLayer4a", false, false) _, err = datastore.FindLayer("TestInsertLayer4a", false, false)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
_, err = datastore.FindLayer("TestInsertLayer4b", true, false) _, err = datastore.FindLayer("TestInsertLayer4b", true, false)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
} }
func cmpFV(a, b database.FeatureVersion) bool { func cmpFV(a, b database.FeatureVersion) bool {

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -17,7 +17,7 @@ package pgsql
import ( import (
"time" "time"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
) )
// Lock tries to set a temporary lock in the database. // Lock tries to set a temporary lock in the database.
@ -80,7 +80,7 @@ func (pgSQL *pgSQL) Unlock(name, owner string) {
func (pgSQL *pgSQL) FindLock(name string) (string, time.Time, error) { func (pgSQL *pgSQL) FindLock(name string) (string, time.Time, error) {
if name == "" { if name == "" {
log.Warning("could not find an invalid lock") log.Warning("could not find an invalid lock")
return "", time.Time{}, cerrors.NewBadRequestError("could not find an invalid lock") return "", time.Time{}, commonerr.NewBadRequestError("could not find an invalid lock")
} }
defer observeQueryTime("FindLock", "all", time.Now()) defer observeQueryTime("FindLock", "all", time.Now())

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -18,12 +18,12 @@ import (
"time" "time"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
) )
func (pgSQL *pgSQL) insertNamespace(namespace database.Namespace) (int, error) { func (pgSQL *pgSQL) insertNamespace(namespace database.Namespace) (int, error) {
if namespace.Name == "" { if namespace.Name == "" {
return 0, cerrors.NewBadRequestError("could not find/insert invalid Namespace") return 0, commonerr.NewBadRequestError("could not find/insert invalid Namespace")
} }
if pgSQL.cache != nil { if pgSQL.cache != nil {

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -19,7 +19,7 @@ import (
"time" "time"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/guregu/null/zero" "github.com/guregu/null/zero"
"github.com/pborman/uuid" "github.com/pborman/uuid"
) )
@ -242,7 +242,7 @@ func (pgSQL *pgSQL) DeleteNotification(name string) error {
} }
if affected <= 0 { if affected <= 0 {
return cerrors.ErrNotFound return commonerr.ErrNotFound
} }
return nil return nil

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -37,7 +37,7 @@ func TestNotification(t *testing.T) {
// Try to get a notification when there is none. // Try to get a notification when there is none.
_, err = datastore.GetAvailableNotification(time.Second) _, err = datastore.GetAvailableNotification(time.Second)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
// Create some data. // Create some data.
f1 := database.Feature{ f1 := database.Feature{
@ -126,7 +126,7 @@ func TestNotification(t *testing.T) {
// Verify the renotify behaviour. // Verify the renotify behaviour.
if assert.Nil(t, datastore.SetNotificationNotified(notification.Name)) { if assert.Nil(t, datastore.SetNotificationNotified(notification.Name)) {
_, err := datastore.GetAvailableNotification(time.Second) _, err := datastore.GetAvailableNotification(time.Second)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
notificationB, err := datastore.GetAvailableNotification(20 * time.Millisecond) notificationB, err := datastore.GetAvailableNotification(20 * time.Millisecond)
@ -164,7 +164,7 @@ func TestNotification(t *testing.T) {
assert.Nil(t, datastore.DeleteNotification(notification.Name)) assert.Nil(t, datastore.DeleteNotification(notification.Name))
_, err = datastore.GetAvailableNotification(time.Millisecond) _, err = datastore.GetAvailableNotification(time.Millisecond)
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
} }
// Update a vulnerability and ensure that the old/new vulnerabilities are correct. // Update a vulnerability and ensure that the old/new vulnerabilities are correct.

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -34,8 +34,8 @@ import (
"github.com/coreos/clair/config" "github.com/coreos/clair/config"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/database/pgsql/migrations" "github.com/coreos/clair/database/pgsql/migrations"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
) )
var ( var (
@ -196,12 +196,12 @@ func openDatabase(registrableComponentConfig config.RegistrableComponentConfig)
func parseConnectionString(source string) (dbName string, pgSourceURL string, err error) { func parseConnectionString(source string) (dbName string, pgSourceURL string, err error) {
if source == "" { if source == "" {
return "", "", cerrors.NewBadRequestError("pgsql: no database connection string specified") return "", "", commonerr.NewBadRequestError("pgsql: no database connection string specified")
} }
sourceURL, err := url.Parse(source) sourceURL, err := url.Parse(source)
if err != nil { if err != nil {
return "", "", cerrors.NewBadRequestError("pgsql: database connection string is not a valid URL") return "", "", commonerr.NewBadRequestError("pgsql: database connection string is not a valid URL")
} }
dbName = strings.TrimPrefix(sourceURL.Path, "/") dbName = strings.TrimPrefix(sourceURL.Path, "/")
@ -280,7 +280,7 @@ func handleError(desc string, err error) error {
} }
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return cerrors.ErrNotFound return commonerr.ErrNotFound
} }
log.Errorf("%s: %v", desc, err) log.Errorf("%s: %v", desc, err)

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -23,8 +23,8 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/guregu/null/zero" "github.com/guregu/null/zero"
) )
@ -37,7 +37,7 @@ func (pgSQL *pgSQL) ListVulnerabilities(namespaceName string, limit int, startID
if err != nil { if err != nil {
return nil, -1, handleError("searchNamespace", err) return nil, -1, handleError("searchNamespace", err)
} else if id == 0 { } else if id == 0 {
return nil, -1, cerrors.ErrNotFound return nil, -1, commonerr.ErrNotFound
} }
// Query. // Query.
@ -130,7 +130,7 @@ func scanVulnerability(queryer Queryer, queryName string, vulnerabilityRow *sql.
} }
if vulnerability.ID == 0 { if vulnerability.ID == 0 {
return vulnerability, cerrors.ErrNotFound return vulnerability, commonerr.ErrNotFound
} }
// Query the FixedIn FeatureVersion now. // Query the FixedIn FeatureVersion now.
@ -195,12 +195,12 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability, on
// Verify parameters // Verify parameters
if vulnerability.Name == "" || vulnerability.Namespace.Name == "" { if vulnerability.Name == "" || vulnerability.Namespace.Name == "" {
return cerrors.NewBadRequestError("insertVulnerability needs at least the Name and the Namespace") return commonerr.NewBadRequestError("insertVulnerability needs at least the Name and the Namespace")
} }
if !onlyFixedIn && !vulnerability.Severity.IsValid() { if !onlyFixedIn && !vulnerability.Severity.IsValid() {
msg := fmt.Sprintf("could not insert a vulnerability that has an invalid Severity: %s", vulnerability.Severity) msg := fmt.Sprintf("could not insert a vulnerability that has an invalid Severity: %s", vulnerability.Severity)
log.Warning(msg) log.Warning(msg)
return cerrors.NewBadRequestError(msg) return commonerr.NewBadRequestError(msg)
} }
for i := 0; i < len(vulnerability.FixedIn); i++ { for i := 0; i < len(vulnerability.FixedIn); i++ {
fifv := &vulnerability.FixedIn[i] fifv := &vulnerability.FixedIn[i]
@ -212,7 +212,7 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability, on
} else if fifv.Feature.Namespace.Name != vulnerability.Namespace.Name { } else if fifv.Feature.Namespace.Name != vulnerability.Namespace.Name {
msg := "could not insert an invalid vulnerability that contains FixedIn FeatureVersion that are not in the same namespace as the Vulnerability" msg := "could not insert an invalid vulnerability that contains FixedIn FeatureVersion that are not in the same namespace as the Vulnerability"
log.Warning(msg) log.Warning(msg)
return cerrors.NewBadRequestError(msg) return commonerr.NewBadRequestError(msg)
} }
} }
@ -228,7 +228,7 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability, on
// Find existing vulnerability and its Vulnerability_FixedIn_Features (for update). // Find existing vulnerability and its Vulnerability_FixedIn_Features (for update).
existingVulnerability, err := findVulnerability(tx, vulnerability.Namespace.Name, vulnerability.Name, true) existingVulnerability, err := findVulnerability(tx, vulnerability.Namespace.Name, vulnerability.Name, true)
if err != nil && err != cerrors.ErrNotFound { if err != nil && err != commonerr.ErrNotFound {
tx.Rollback() tx.Rollback()
return err return err
} }
@ -237,7 +237,7 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability, on
// Because this call tries to update FixedIn FeatureVersion, import all other data from the // Because this call tries to update FixedIn FeatureVersion, import all other data from the
// existing one. // existing one.
if existingVulnerability.ID == 0 { if existingVulnerability.ID == 0 {
return cerrors.ErrNotFound return commonerr.ErrNotFound
} }
fixedIn := vulnerability.FixedIn fixedIn := vulnerability.FixedIn

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -37,7 +37,7 @@ func TestFindVulnerability(t *testing.T) {
// Find a vulnerability that does not exist. // Find a vulnerability that does not exist.
_, err = datastore.FindVulnerability("", "") _, err = datastore.FindVulnerability("", "")
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
// Find a normal vulnerability. // Find a normal vulnerability.
v1 := database.Vulnerability{ v1 := database.Vulnerability{
@ -93,15 +93,15 @@ func TestDeleteVulnerability(t *testing.T) {
// Delete non-existing Vulnerability. // Delete non-existing Vulnerability.
err = datastore.DeleteVulnerability("TestDeleteVulnerabilityNamespace1", "CVE-OPENSSL-1-DEB7") err = datastore.DeleteVulnerability("TestDeleteVulnerabilityNamespace1", "CVE-OPENSSL-1-DEB7")
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
err = datastore.DeleteVulnerability("debian:7", "TestDeleteVulnerabilityVulnerability1") err = datastore.DeleteVulnerability("debian:7", "TestDeleteVulnerabilityVulnerability1")
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
// Delete Vulnerability. // Delete Vulnerability.
err = datastore.DeleteVulnerability("debian:7", "CVE-OPENSSL-1-DEB7") err = datastore.DeleteVulnerability("debian:7", "CVE-OPENSSL-1-DEB7")
if assert.Nil(t, err) { if assert.Nil(t, err) {
_, err := datastore.FindVulnerability("debian:7", "CVE-OPENSSL-1-DEB7") _, err := datastore.FindVulnerability("debian:7", "CVE-OPENSSL-1-DEB7")
assert.Equal(t, cerrors.ErrNotFound, err) assert.Equal(t, commonerr.ErrNotFound, err)
} }
} }

View File

@ -35,7 +35,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/vulnmdsrc" "github.com/coreos/clair/ext/vulnmdsrc"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -79,7 +79,7 @@ func (a *appender) BuildCache(datastore database.Datastore) error {
if a.localPath == "" { if a.localPath == "" {
// Create a temporary folder to store the NVD data and create hashes struct. // Create a temporary folder to store the NVD data and create hashes struct.
if a.localPath, err = ioutil.TempDir(os.TempDir(), "nvd-data"); err != nil { if a.localPath, err = ioutil.TempDir(os.TempDir(), "nvd-data"); err != nil {
return cerrors.ErrFilesystem return commonerr.ErrFilesystem
} }
a.dataFeedHashes = make(map[string]string) a.dataFeedHashes = make(map[string]string)
@ -97,7 +97,7 @@ func (a *appender) BuildCache(datastore database.Datastore) error {
var nvd nvd var nvd nvd
if err = xml.NewDecoder(dataFeedReader).Decode(&nvd); err != nil { if err = xml.NewDecoder(dataFeedReader).Decode(&nvd); err != nil {
log.Errorf("could not decode NVD data feed '%s': %s", dataFeedName, err) log.Errorf("could not decode NVD data feed '%s': %s", dataFeedName, err)
return cerrors.ErrCouldNotParse return commonerr.ErrCouldNotParse
} }
// For each entry of this data feed: // For each entry of this data feed:
@ -179,14 +179,14 @@ func getDataFeeds(dataFeedHashes map[string]string, localPath string) (map[strin
r, err := http.Get(fmt.Sprintf(dataFeedURL, dataFeedName)) r, err := http.Get(fmt.Sprintf(dataFeedURL, dataFeedName))
if err != nil { if err != nil {
log.Errorf("could not download NVD data feed file '%s': %s", dataFeedName, err) log.Errorf("could not download NVD data feed file '%s': %s", dataFeedName, err)
return dataFeedReaders, dataFeedHashes, cerrors.ErrCouldNotDownload return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
} }
// Un-gzip it. // Un-gzip it.
gr, err := gzip.NewReader(r.Body) gr, err := gzip.NewReader(r.Body)
if err != nil { if err != nil {
log.Errorf("could not read NVD data feed file '%s': %s", dataFeedName, err) log.Errorf("could not read NVD data feed file '%s': %s", dataFeedName, err)
return dataFeedReaders, dataFeedHashes, cerrors.ErrCouldNotDownload return dataFeedReaders, dataFeedHashes, commonerr.ErrCouldNotDownload
} }
// Store it to a file at the same time if possible. // Store it to a file at the same time if possible.

View File

@ -31,8 +31,8 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/ext/vulnsrc" "github.com/coreos/clair/ext/vulnsrc"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -172,7 +172,7 @@ func (u *updater) pullRepository() (commit string, err error) {
if out, err := utils.Exec(u.repositoryLocalPath, "git", "clone", secdbGitURL, "."); err != nil { if out, err := utils.Exec(u.repositoryLocalPath, "git", "clone", secdbGitURL, "."); err != nil {
u.Clean() u.Clean()
log.Errorf("could not pull alpine-secdb repository: %s. output: %s", err, out) log.Errorf("could not pull alpine-secdb repository: %s. output: %s", err, out)
return "", cerrors.ErrCouldNotDownload return "", commonerr.ErrCouldNotDownload
} }
} else { } else {
// The repository exists and it needs to be refreshed via a pull. // The repository exists and it needs to be refreshed via a pull.

View File

@ -31,7 +31,7 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/ext/vulnsrc" "github.com/coreos/clair/ext/vulnsrc"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -69,7 +69,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo
r, err := http.Get(url) r, err := http.Get(url)
if err != nil { if err != nil {
log.Errorf("could not download Debian's update: %s", err) log.Errorf("could not download Debian's update: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, commonerr.ErrCouldNotDownload
} }
// Get the SHA-1 of the latest update's JSON data // Get the SHA-1 of the latest update's JSON data
@ -110,7 +110,7 @@ func buildResponse(jsonReader io.Reader, latestKnownHash string) (resp vulnsrc.U
err = json.NewDecoder(teedJSONReader).Decode(&data) err = json.NewDecoder(teedJSONReader).Decode(&data)
if err != nil { if err != nil {
log.Errorf("could not unmarshal Debian's JSON: %s", err) log.Errorf("could not unmarshal Debian's JSON: %s", err)
return resp, cerrors.ErrCouldNotParse return resp, commonerr.ErrCouldNotParse
} }
// Calculate the hash and skip updating if the hash has been seen before. // Calculate the hash and skip updating if the hash has been seen before.

View File

@ -29,7 +29,7 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm" "github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/ext/vulnsrc" "github.com/coreos/clair/ext/vulnsrc"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
) )
@ -103,7 +103,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo
r, err := http.Get(ovalURI) r, err := http.Get(ovalURI)
if err != nil { if err != nil {
log.Errorf("could not download Oracle's update list: %s", err) log.Errorf("could not download Oracle's update list: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, commonerr.ErrCouldNotDownload
} }
defer r.Body.Close() defer r.Body.Close()
@ -126,7 +126,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo
r, err := http.Get(ovalURI + elsaFilePrefix + strconv.Itoa(elsa) + ".xml") r, err := http.Get(ovalURI + elsaFilePrefix + strconv.Itoa(elsa) + ".xml")
if err != nil { if err != nil {
log.Errorf("could not download Oracle's update file: %s", err) log.Errorf("could not download Oracle's update file: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, commonerr.ErrCouldNotDownload
} }
// Parse the XML. // Parse the XML.
@ -160,7 +160,7 @@ func parseELSA(ovalReader io.Reader) (vulnerabilities []database.Vulnerability,
err = xml.NewDecoder(ovalReader).Decode(&ov) err = xml.NewDecoder(ovalReader).Decode(&ov)
if err != nil { if err != nil {
log.Errorf("could not decode Oracle's XML: %s", err) log.Errorf("could not decode Oracle's XML: %s", err)
err = cerrors.ErrCouldNotParse err = commonerr.ErrCouldNotParse
return return
} }

View File

@ -31,7 +31,7 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm" "github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/ext/vulnsrc" "github.com/coreos/clair/ext/vulnsrc"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -107,7 +107,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo
r, err := http.Get(ovalURI) r, err := http.Get(ovalURI)
if err != nil { if err != nil {
log.Errorf("could not download RHEL's update list: %s", err) log.Errorf("could not download RHEL's update list: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, commonerr.ErrCouldNotDownload
} }
// Get the list of RHSAs that we have to process. // Get the list of RHSAs that we have to process.
@ -129,7 +129,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo
r, err := http.Get(ovalURI + rhsaFilePrefix + strconv.Itoa(rhsa) + ".xml") r, err := http.Get(ovalURI + rhsaFilePrefix + strconv.Itoa(rhsa) + ".xml")
if err != nil { if err != nil {
log.Errorf("could not download RHEL's update file: %s", err) log.Errorf("could not download RHEL's update file: %s", err)
return resp, cerrors.ErrCouldNotDownload return resp, commonerr.ErrCouldNotDownload
} }
// Parse the XML. // Parse the XML.
@ -163,7 +163,7 @@ func parseRHSA(ovalReader io.Reader) (vulnerabilities []database.Vulnerability,
err = xml.NewDecoder(ovalReader).Decode(&ov) err = xml.NewDecoder(ovalReader).Decode(&ov)
if err != nil { if err != nil {
log.Errorf("could not decode RHEL's XML: %s", err) log.Errorf("could not decode RHEL's XML: %s", err)
err = cerrors.ErrCouldNotParse err = commonerr.ErrCouldNotParse
return return
} }

View File

@ -33,8 +33,8 @@ import (
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
"github.com/coreos/clair/ext/vulnsrc" "github.com/coreos/clair/ext/vulnsrc"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/utils/types" "github.com/coreos/clair/utils/types"
) )
@ -176,7 +176,7 @@ func (u *updater) pullRepository() (err error) {
// Branch repository. // Branch repository.
if out, err := utils.Exec(u.repositoryLocalPath, "bzr", "branch", "--use-existing-dir", trackerRepository, "."); err != nil { if out, err := utils.Exec(u.repositoryLocalPath, "bzr", "branch", "--use-existing-dir", trackerRepository, "."); err != nil {
log.Errorf("could not branch Ubuntu repository: %s. output: %s", err, out) log.Errorf("could not branch Ubuntu repository: %s. output: %s", err, out)
return cerrors.ErrCouldNotDownload return commonerr.ErrCouldNotDownload
} }
return nil return nil
@ -187,7 +187,7 @@ func (u *updater) pullRepository() (err error) {
os.RemoveAll(u.repositoryLocalPath) os.RemoveAll(u.repositoryLocalPath)
log.Errorf("could not pull Ubuntu repository: %s. output: %s", err, out) log.Errorf("could not pull Ubuntu repository: %s. output: %s", err, out)
return cerrors.ErrCouldNotDownload return commonerr.ErrCouldNotDownload
} }
return nil return nil
@ -197,12 +197,12 @@ func getRevisionNumber(pathToRepo string) (int, error) {
out, err := utils.Exec(pathToRepo, "bzr", "revno") out, err := utils.Exec(pathToRepo, "bzr", "revno")
if err != nil { if err != nil {
log.Errorf("could not get Ubuntu repository's revision number: %s. output: %s", err, out) log.Errorf("could not get Ubuntu repository's revision number: %s. output: %s", err, out)
return 0, cerrors.ErrCouldNotDownload return 0, commonerr.ErrCouldNotDownload
} }
revno, err := strconv.Atoi(strings.TrimSpace(string(out))) revno, err := strconv.Atoi(strings.TrimSpace(string(out)))
if err != nil { if err != nil {
log.Errorf("could not parse Ubuntu repository's revision number: %s. output: %s", err, out) log.Errorf("could not parse Ubuntu repository's revision number: %s. output: %s", err, out)
return 0, cerrors.ErrCouldNotDownload return 0, commonerr.ErrCouldNotDownload
} }
return revno, nil return revno, nil
} }
@ -255,7 +255,7 @@ func collectModifiedVulnerabilities(revision int, dbRevision, repositoryLocalPat
out, err := utils.Exec(repositoryLocalPath, "bzr", "log", "--verbose", "-r"+strconv.Itoa(dbRevisionInt+1)+"..", "-n0") out, err := utils.Exec(repositoryLocalPath, "bzr", "log", "--verbose", "-r"+strconv.Itoa(dbRevisionInt+1)+"..", "-n0")
if err != nil { if err != nil {
log.Errorf("could not get Ubuntu vulnerabilities repository logs: %s. output: %s", err, out) log.Errorf("could not get Ubuntu vulnerabilities repository logs: %s. output: %s", err, out)
return nil, cerrors.ErrCouldNotDownload return nil, commonerr.ErrCouldNotDownload
} }
scanner := bufio.NewScanner(bytes.NewReader(out)) scanner := bufio.NewScanner(bytes.NewReader(out))

View File

@ -28,8 +28,8 @@ import (
"github.com/coreos/clair/config" "github.com/coreos/clair/config"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/notification" "github.com/coreos/clair/ext/notification"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
) )
const ( const (
@ -127,7 +127,7 @@ func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoA
notification, err := datastore.GetAvailableNotification(renotifyInterval) notification, err := datastore.GetAvailableNotification(renotifyInterval)
if err != nil { if err != nil {
// There is no notification or an error occurred. // There is no notification or an error occurred.
if err != cerrors.ErrNotFound { if err != commonerr.ErrNotFound {
log.Warningf("could not get notification to send: %s", err) log.Warningf("could not get notification to send: %s", err)
} }

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -12,8 +12,9 @@
// 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 errors defines error types that are used in several modules // Package commonerr defines reusable error types common throughout the Clair
package errors // codebase.
package commonerr
import "errors" import "errors"

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -21,8 +21,8 @@ import (
"net/http" "net/http"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/pkg/tarutil" "github.com/coreos/clair/pkg/tarutil"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/worker" "github.com/coreos/clair/worker"
) )
@ -48,11 +48,11 @@ func WriteHTTPError(w http.ResponseWriter, httpStatus int, err error) {
if httpStatus == 0 { if httpStatus == 0 {
httpStatus = http.StatusInternalServerError httpStatus = http.StatusInternalServerError
// Try to guess the http status code from the error type // Try to guess the http status code from the error type
if _, isBadRequestError := err.(*cerrors.ErrBadRequest); isBadRequestError { if _, isBadRequestError := err.(*commonerr.ErrBadRequest); isBadRequestError {
httpStatus = http.StatusBadRequest httpStatus = http.StatusBadRequest
} else { } else {
switch err { switch err {
case cerrors.ErrNotFound: case commonerr.ErrNotFound:
httpStatus = http.StatusNotFound httpStatus = http.StatusNotFound
case database.ErrBackendException: case database.ErrBackendException:
httpStatus = http.StatusServiceUnavailable httpStatus = http.StatusServiceUnavailable

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -25,8 +25,8 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt" "github.com/coreos/clair/ext/versionfmt"
"github.com/coreos/clair/ext/versionfmt/rpm" "github.com/coreos/clair/ext/versionfmt/rpm"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -55,13 +55,13 @@ func (detector *RpmFeaturesDetector) Detect(data map[string][]byte) ([]database.
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
if err != nil { if err != nil {
log.Errorf("could not create temporary folder for RPM detection: %s", err) log.Errorf("could not create temporary folder for RPM detection: %s", err)
return []database.FeatureVersion{}, cerrors.ErrFilesystem return []database.FeatureVersion{}, commonerr.ErrFilesystem
} }
err = ioutil.WriteFile(tmpDir+"/Packages", f, 0700) err = ioutil.WriteFile(tmpDir+"/Packages", f, 0700)
if err != nil { if err != nil {
log.Errorf("could not create temporary file for RPM detection: %s", err) log.Errorf("could not create temporary file for RPM detection: %s", err)
return []database.FeatureVersion{}, cerrors.ErrFilesystem return []database.FeatureVersion{}, commonerr.ErrFilesystem
} }
// Query RPM // Query RPM

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -20,8 +20,8 @@ import (
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/pkg/commonerr"
"github.com/coreos/clair/utils" "github.com/coreos/clair/utils"
cerrors "github.com/coreos/clair/utils/errors"
"github.com/coreos/clair/worker/detectors" "github.com/coreos/clair/worker/detectors"
) )
@ -41,11 +41,11 @@ var (
// 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 = cerrors.NewBadRequestError("worker: OS and/or package manager are not supported") ErrUnsupported = commonerr.NewBadRequestError("worker: OS and/or package manager are not supported")
// ErrParentUnknown is the error that should be raised when a parent layer // ErrParentUnknown is the error that should be raised when a parent layer
// has yet to be processed for the current layer. // has yet to be processed for the current layer.
ErrParentUnknown = cerrors.NewBadRequestError("worker: parent layer is unknown, it must be processed first") ErrParentUnknown = commonerr.NewBadRequestError("worker: parent layer is unknown, it must be processed first")
) )
// Process detects the Namespace of a layer, the features it adds/removes, and // Process detects the Namespace of a layer, the features it adds/removes, and
@ -55,15 +55,15 @@ var (
func Process(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error { func Process(datastore database.Datastore, imageFormat, name, parentName, path string, headers map[string]string) error {
// Verify parameters. // Verify parameters.
if name == "" { if name == "" {
return cerrors.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")
} }
if path == "" { if path == "" {
return cerrors.NewBadRequestError("could not process a layer which does not have a path") return commonerr.NewBadRequestError("could not process a layer which does not have a path")
} }
if imageFormat == "" { if imageFormat == "" {
return cerrors.NewBadRequestError("could not process a layer which does not have a format") return commonerr.NewBadRequestError("could not process a layer which does not have a format")
} }
log.Debugf("layer %s: processing (Location: %s, Engine version: %d, Parent: %s, Format: %s)", log.Debugf("layer %s: processing (Location: %s, Engine version: %d, Parent: %s, Format: %s)",
@ -71,11 +71,11 @@ func Process(datastore database.Datastore, imageFormat, name, parentName, path s
// Check to see if the layer is already in the database. // Check to see if the layer is already in the database.
layer, err := datastore.FindLayer(name, false, false) layer, err := datastore.FindLayer(name, false, false)
if err != nil && err != cerrors.ErrNotFound { if err != nil && err != commonerr.ErrNotFound {
return err return err
} }
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
// New layer case. // New layer case.
layer = database.Layer{Name: name, EngineVersion: Version} layer = database.Layer{Name: name, EngineVersion: Version}
@ -83,10 +83,10 @@ func Process(datastore database.Datastore, imageFormat, name, parentName, path s
// We need to get it with its Features in order to diff them. // We need to get it with its Features in order to diff them.
if parentName != "" { if parentName != "" {
parent, err := datastore.FindLayer(parentName, true, false) parent, err := datastore.FindLayer(parentName, true, false)
if err != nil && err != cerrors.ErrNotFound { if err != nil && err != commonerr.ErrNotFound {
return err return err
} }
if err == cerrors.ErrNotFound { if err == commonerr.ErrNotFound {
log.Warningf("layer %s: the parent layer (%s) is unknown. it must be processed first", name, log.Warningf("layer %s: the parent layer (%s) is unknown. it must be processed first", name,
parentName) parentName)
return ErrParentUnknown return ErrParentUnknown

View File

@ -1,4 +1,4 @@
// Copyright 2015 clair authors // Copyright 2017 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import (
"github.com/coreos/clair/database" "github.com/coreos/clair/database"
"github.com/coreos/clair/ext/versionfmt/dpkg" "github.com/coreos/clair/ext/versionfmt/dpkg"
cerrors "github.com/coreos/clair/utils/errors" "github.com/coreos/clair/pkg/commonerr"
// Register the required detectors. // Register the required detectors.
_ "github.com/coreos/clair/worker/detectors/data/docker" _ "github.com/coreos/clair/worker/detectors/data/docker"
@ -57,7 +57,7 @@ func TestProcessWithDistUpgrade(t *testing.T) {
if layer, exists := datastore.layers[name]; exists { if layer, exists := datastore.layers[name]; exists {
return layer, nil return layer, nil
} }
return database.Layer{}, cerrors.ErrNotFound return database.Layer{}, commonerr.ErrNotFound
} }
// Create the list of FeatureVersions that should not been upgraded from one layer to another. // Create the list of FeatureVersions that should not been upgraded from one layer to another.