Adds options map for storagedriver URLFor() method
This commit is contained in:
parent
17915e1b01
commit
abb901e4ab
7 changed files with 22 additions and 10 deletions
|
@ -90,7 +90,7 @@ func (lh *cloudFrontLayerHandler) Resolve(layer Layer) (http.Handler, error) {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/distribution/storagedriver"
|
"github.com/docker/distribution/storagedriver"
|
||||||
|
@ -42,7 +43,7 @@ func (lh *delegateLayerHandler) urlFor(layer Layer) (string, error) {
|
||||||
return "", err
|
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 {
|
if err != nil {
|
||||||
return "", err
|
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.
|
// 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.
|
// 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
|
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.
|
// 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.
|
// 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
|
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.
|
// 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.
|
// 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) {
|
if !storagedriver.PathRegexp.MatchString(path) {
|
||||||
return "", storagedriver.InvalidPathError{Path: 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 {
|
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 recursively deletes all objects stored at "path" and its subpaths.
|
||||||
Delete(path string) error
|
Delete(path string) error
|
||||||
|
|
||||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
// URLFor returns a URL which may be used to retrieve the content stored at
|
||||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
// the given path, possibly using the given options.
|
||||||
URLFor(path string) (string, error)
|
// 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.
|
// 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)
|
err := suite.StorageDriver.PutContent(filename, contents)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
url, err := suite.StorageDriver.URLFor(filename)
|
url, err := suite.StorageDriver.URLFor(filename, nil)
|
||||||
if err == storagedriver.ErrUnsupportedMethod {
|
if err == storagedriver.ErrUnsupportedMethod {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue