Adds support for content redirects for layer downloads

Includes a delegate implementation which redirects to the URL generated
by the storagedriver, and a cloudfront implementation.
Satisfies proposal #49
This commit is contained in:
Brian Bland 2015-01-08 16:55:40 -08:00
parent 65863802d7
commit 17915e1b01
9 changed files with 321 additions and 6 deletions

View file

@ -35,6 +35,9 @@ 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"`
}
@ -240,6 +243,58 @@ type NewRelicReporting struct {
Name string `yaml:"name"`
}
// LayerHandler defines the configuration for middleware layer serving
type LayerHandler map[string]Parameters
// Type returns the layerhandler type
func (layerHandler LayerHandler) Type() string {
// Return only key in this map
for k := range layerHandler {
return k
}
return ""
}
// Parameters returns the Parameters map for a LayerHandler configuration
func (layerHandler LayerHandler) Parameters() Parameters {
return layerHandler[layerHandler.Type()]
}
// UnmarshalYAML implements the yaml.Unmarshaler interface
// Unmarshals a single item map into a Storage or a string into a Storage type with no parameters
func (layerHandler *LayerHandler) UnmarshalYAML(unmarshal func(interface{}) error) error {
var storageMap map[string]Parameters
err := unmarshal(&storageMap)
if err == nil {
if len(storageMap) > 1 {
types := make([]string, 0, len(storageMap))
for k := range storageMap {
types = append(types, k)
}
return fmt.Errorf("Must provide exactly one layerhandler type. Provided: %v", types)
}
*layerHandler = storageMap
return nil
}
var storageType string
err = unmarshal(&storageType)
if err == nil {
*layerHandler = LayerHandler{storageType: Parameters{}}
return nil
}
return err
}
// MarshalYAML implements the yaml.Marshaler interface
func (layerHandler LayerHandler) MarshalYAML() (interface{}, error) {
if layerHandler.Parameters() == nil {
return layerHandler.Type(), nil
}
return map[string]Parameters(layerHandler), nil
}
// Parse parses an input configuration yaml document into a Configuration struct
// This should generally be capable of handling old configuration format versions
//