From abb901e4ab6222f710cdcd3fde32a5f20875dcad Mon Sep 17 00:00:00 2001 From: Brian Bland Date: Thu, 8 Jan 2015 17:10:32 -0800 Subject: [PATCH] Adds options map for storagedriver URLFor() method --- storage/cloudfrontlayerhandler.go | 2 +- storage/delegatelayerhandler.go | 3 ++- storagedriver/filesystem/driver.go | 2 +- storagedriver/inmemory/driver.go | 2 +- storagedriver/s3/s3.go | 13 +++++++++++-- storagedriver/storagedriver.go | 8 +++++--- storagedriver/testsuites/testsuites.go | 2 +- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/storage/cloudfrontlayerhandler.go b/storage/cloudfrontlayerhandler.go index 703c0f21..3afc4c0e 100644 --- a/storage/cloudfrontlayerhandler.go +++ b/storage/cloudfrontlayerhandler.go @@ -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 } diff --git a/storage/delegatelayerhandler.go b/storage/delegatelayerhandler.go index 34c8315b..26d6971d 100644 --- a/storage/delegatelayerhandler.go +++ b/storage/delegatelayerhandler.go @@ -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 } diff --git a/storagedriver/filesystem/driver.go b/storagedriver/filesystem/driver.go index cf52b383..2de7c163 100644 --- a/storagedriver/filesystem/driver.go +++ b/storagedriver/filesystem/driver.go @@ -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 } diff --git a/storagedriver/inmemory/driver.go b/storagedriver/inmemory/driver.go index 89692623..e3c63f74 100644 --- a/storagedriver/inmemory/driver.go +++ b/storagedriver/inmemory/driver.go @@ -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 } diff --git a/storagedriver/s3/s3.go b/storagedriver/s3/s3.go index 916a4287..f8a04645 100644 --- a/storagedriver/s3/s3.go +++ b/storagedriver/s3/s3.go @@ -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 { diff --git a/storagedriver/storagedriver.go b/storagedriver/storagedriver.go index f5a3ca00..d050d68f 100644 --- a/storagedriver/storagedriver.go +++ b/storagedriver/storagedriver.go @@ -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. diff --git a/storagedriver/testsuites/testsuites.go b/storagedriver/testsuites/testsuites.go index 63849019..486640c4 100644 --- a/storagedriver/testsuites/testsuites.go +++ b/storagedriver/testsuites/testsuites.go @@ -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 }