Fixes tests, moves layerhandler in config file

This commit is contained in:
Brian Bland 2015-01-08 17:29:22 -08:00
parent abb901e4ab
commit cc3c648f44
3 changed files with 16 additions and 10 deletions

View file

@ -24,6 +24,9 @@ type Configuration struct {
// used to gate requests.
Auth Auth `yaml:"auth"`
// LayerHandler specifies a middleware for serving image layers.
LayerHandler LayerHandler `yaml:"layerhandler"`
// Reporting is the configuration for error reporting
Reporting Reporting `yaml:"reporting"`
@ -35,9 +38,6 @@ type Configuration struct {
// Secret specifies the secret key which HMAC tokens are created with.
Secret string `yaml:"secret"`
// LayerHandler specifies a middleware for serving image layers.
LayerHandler LayerHandler `yaml:"layerhandler"`
} `yaml:"http"`
}
@ -290,7 +290,11 @@ func (layerHandler *LayerHandler) UnmarshalYAML(unmarshal func(interface{}) erro
// MarshalYAML implements the yaml.Marshaler interface
func (layerHandler LayerHandler) MarshalYAML() (interface{}, error) {
if layerHandler.Parameters() == nil {
return layerHandler.Type(), nil
t := layerHandler.Type()
if t == "" {
return nil, nil
}
return t, nil
}
return map[string]Parameters(layerHandler), nil
}

View file

@ -78,10 +78,10 @@ func NewApp(configuration configuration.Configuration) *App {
app.accessController = accessController
}
layerHandlerType := configuration.HTTP.LayerHandler.Type()
layerHandlerType := configuration.LayerHandler.Type()
if layerHandlerType != "" {
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.HTTP.LayerHandler.Parameters(), driver)
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.LayerHandler.Parameters(), driver)
if err != nil {
panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err))
}

View file

@ -58,10 +58,12 @@ func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
}
defer layer.Close()
handler, err := lh.layerHandler.Resolve(layer)
if handler != nil {
handler.ServeHTTP(w, r)
return
if lh.layerHandler != nil {
handler, _ := lh.layerHandler.Resolve(layer)
if handler != nil {
handler.ServeHTTP(w, r)
return
}
}
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)