Fixes tests, moves layerhandler in config file
This commit is contained in:
parent
abb901e4ab
commit
cc3c648f44
3 changed files with 16 additions and 10 deletions
|
@ -24,6 +24,9 @@ type Configuration struct {
|
||||||
// used to gate requests.
|
// used to gate requests.
|
||||||
Auth Auth `yaml:"auth"`
|
Auth Auth `yaml:"auth"`
|
||||||
|
|
||||||
|
// LayerHandler specifies a middleware for serving image layers.
|
||||||
|
LayerHandler LayerHandler `yaml:"layerhandler"`
|
||||||
|
|
||||||
// Reporting is the configuration for error reporting
|
// Reporting is the configuration for error reporting
|
||||||
Reporting Reporting `yaml:"reporting"`
|
Reporting Reporting `yaml:"reporting"`
|
||||||
|
|
||||||
|
@ -35,9 +38,6 @@ type Configuration struct {
|
||||||
|
|
||||||
// Secret specifies the secret key which HMAC tokens are created with.
|
// Secret specifies the secret key which HMAC tokens are created with.
|
||||||
Secret string `yaml:"secret"`
|
Secret string `yaml:"secret"`
|
||||||
|
|
||||||
// LayerHandler specifies a middleware for serving image layers.
|
|
||||||
LayerHandler LayerHandler `yaml:"layerhandler"`
|
|
||||||
} `yaml:"http"`
|
} `yaml:"http"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,11 @@ func (layerHandler *LayerHandler) UnmarshalYAML(unmarshal func(interface{}) erro
|
||||||
// MarshalYAML implements the yaml.Marshaler interface
|
// MarshalYAML implements the yaml.Marshaler interface
|
||||||
func (layerHandler LayerHandler) MarshalYAML() (interface{}, error) {
|
func (layerHandler LayerHandler) MarshalYAML() (interface{}, error) {
|
||||||
if layerHandler.Parameters() == nil {
|
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
|
return map[string]Parameters(layerHandler), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,10 +78,10 @@ func NewApp(configuration configuration.Configuration) *App {
|
||||||
app.accessController = accessController
|
app.accessController = accessController
|
||||||
}
|
}
|
||||||
|
|
||||||
layerHandlerType := configuration.HTTP.LayerHandler.Type()
|
layerHandlerType := configuration.LayerHandler.Type()
|
||||||
|
|
||||||
if layerHandlerType != "" {
|
if layerHandlerType != "" {
|
||||||
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.HTTP.LayerHandler.Parameters(), driver)
|
lh, err := storage.GetLayerHandler(layerHandlerType, configuration.LayerHandler.Parameters(), driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err))
|
panic(fmt.Sprintf("unable to configure layer handler (%s): %v", layerHandlerType, err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,12 @@ func (lh *layerHandler) GetLayer(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer layer.Close()
|
defer layer.Close()
|
||||||
|
|
||||||
handler, err := lh.layerHandler.Resolve(layer)
|
if lh.layerHandler != nil {
|
||||||
if handler != nil {
|
handler, _ := lh.layerHandler.Resolve(layer)
|
||||||
handler.ServeHTTP(w, r)
|
if handler != nil {
|
||||||
return
|
handler.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)
|
http.ServeContent(w, r, layer.Digest().String(), layer.CreatedAt(), layer)
|
||||||
|
|
Loading…
Reference in a new issue