From bdd5d356227b7fd8c98da0bf79caf464ea856b27 Mon Sep 17 00:00:00 2001 From: Andrey Kostov Date: Wed, 14 Jan 2015 11:31:11 -0800 Subject: [PATCH] Add functionality to make a url signed for a HEAD request to S4 driver --- storagedriver/s3/s3.go | 11 ++++++++++- storagedriver/testsuites/testsuites.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/storagedriver/s3/s3.go b/storagedriver/s3/s3.go index 69f34877..991f2b00 100644 --- a/storagedriver/s3/s3.go +++ b/storagedriver/s3/s3.go @@ -642,6 +642,15 @@ func (d *Driver) URLFor(path string, options map[string]interface{}) (string, er return "", storagedriver.InvalidPathError{Path: path} } + methodString := "GET" + method, ok := options["method"] + if ok { + methodString, ok = method.(string) + if !ok || (methodString != "GET" && methodString != "HEAD") { + return "", storagedriver.ErrUnsupportedMethod + } + } + expiresTime := time.Now().Add(20 * time.Minute) expires, ok := options["expiry"] if ok { @@ -651,7 +660,7 @@ func (d *Driver) URLFor(path string, options map[string]interface{}) (string, er } } - return d.Bucket.SignedURL(d.s3Path(path), expiresTime), nil + return d.Bucket.SignedURLWithMethod(methodString, d.s3Path(path), expiresTime, nil, nil), nil } func (d *Driver) s3Path(path string) string { diff --git a/storagedriver/testsuites/testsuites.go b/storagedriver/testsuites/testsuites.go index 486640c4..c3229fcc 100644 --- a/storagedriver/testsuites/testsuites.go +++ b/storagedriver/testsuites/testsuites.go @@ -605,6 +605,16 @@ func (suite *DriverSuite) TestURLFor(c *check.C) { read, err := ioutil.ReadAll(response.Body) c.Assert(err, check.IsNil) c.Assert(read, check.DeepEquals, contents) + + url, err = suite.StorageDriver.URLFor(filename, map[string]interface{}{"method": "HEAD"}) + if err == storagedriver.ErrUnsupportedMethod { + return + } + c.Assert(err, check.IsNil) + + response, err = http.Head(url) + c.Assert(response.StatusCode, check.Equals, 200) + c.Assert(response.ContentLength, check.Equals, int64(32)) } // TestDeleteNonexistent checks that removing a nonexistent key fails.