worker: detect the status code when downloading a layer and expect 2XX.
This commit is contained in:
parent
6aa501f18e
commit
343ce39865
@ -19,12 +19,14 @@ package detectors
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
cerrors "github.com/coreos/clair/utils/errors"
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
)
|
||||
|
||||
// The DataDetector interface defines a way to detect the required data from input path
|
||||
@ -38,6 +40,8 @@ type DataDetector interface {
|
||||
var (
|
||||
dataDetectorsLock sync.Mutex
|
||||
dataDetectors = make(map[string]DataDetector)
|
||||
|
||||
log = capnslog.NewPackageLogger("github.com/coreos/clair", "detectors")
|
||||
)
|
||||
|
||||
// RegisterDataDetector provides a way to dynamically register an implementation of a
|
||||
@ -70,6 +74,14 @@ func DetectData(path string, format string, toExtract []string, maxFileSize int6
|
||||
if err != nil {
|
||||
return nil, cerrors.ErrCouldNotDownload
|
||||
}
|
||||
if err != nil {
|
||||
log.Warningf("could not download layer: %s", err)
|
||||
return nil, cerrors.ErrCouldNotDownload
|
||||
}
|
||||
if math.Floor(float64(r.StatusCode/100)) != 2 {
|
||||
log.Warningf("could not download layer: got status code %d, expected 2XX", r.StatusCode)
|
||||
return nil, cerrors.ErrCouldNotDownload
|
||||
}
|
||||
layerReader = r.Body
|
||||
} else {
|
||||
layerReader, err = os.Open(path)
|
||||
|
Loading…
Reference in New Issue
Block a user