Adds options map for storagedriver URLFor() method
This commit is contained in:
parent
17915e1b01
commit
abb901e4ab
@ -90,7 +90,7 @@ func (lh *cloudFrontLayerHandler) Resolve(layer Layer) (http.Handler, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfURL, err := lh.cloudfront.CannedSignedURL(layerURL.Path, "", time.Now().Add(time.Minute))
|
||||
cfURL, err := lh.cloudfront.CannedSignedURL(layerURL.Path, "", time.Now().Add(20*time.Minute))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/storagedriver"
|
||||
@ -42,7 +43,7 @@ func (lh *delegateLayerHandler) urlFor(layer Layer) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
layerURL, err := lh.storageDriver.URLFor(blobPath)
|
||||
layerURL, err := lh.storageDriver.URLFor(blobPath, map[string]interface{}{"expires": time.Now().Add(20 * time.Minute)})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ func (d *Driver) Delete(subPath string) error {
|
||||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *Driver) URLFor(path string) (string, error) {
|
||||
func (d *Driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
return "", storagedriver.ErrUnsupportedMethod
|
||||
}
|
||||
|
||||
|
@ -254,6 +254,6 @@ func (d *Driver) Delete(path string) error {
|
||||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *Driver) URLFor(path string) (string, error) {
|
||||
func (d *Driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
return "", storagedriver.ErrUnsupportedMethod
|
||||
}
|
||||
|
@ -582,12 +582,21 @@ func (d *Driver) Delete(path string) error {
|
||||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *Driver) URLFor(path string) (string, error) {
|
||||
func (d *Driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return "", storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return d.Bucket.SignedURL(d.s3Path(path), time.Now().Add(24*time.Hour)), nil
|
||||
expiresTime := time.Now().Add(20 * time.Minute)
|
||||
expires, ok := options["expires"]
|
||||
if ok {
|
||||
et, ok := expires.(time.Time)
|
||||
if ok {
|
||||
expiresTime = et
|
||||
}
|
||||
}
|
||||
|
||||
return d.Bucket.SignedURL(d.s3Path(path), expiresTime), nil
|
||||
}
|
||||
|
||||
func (d *Driver) s3Path(path string) string {
|
||||
|
@ -71,9 +71,11 @@ type StorageDriver interface {
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
Delete(path string) error
|
||||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
URLFor(path string) (string, error)
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at
|
||||
// the given path, possibly using the given options.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver
|
||||
// implementations.
|
||||
URLFor(path string, options map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
// PathRegexp is the regular expression which each file path must match.
|
||||
|
@ -592,7 +592,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
url, err := suite.StorageDriver.URLFor(filename)
|
||||
url, err := suite.StorageDriver.URLFor(filename, nil)
|
||||
if err == storagedriver.ErrUnsupportedMethod {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user