Support versionId in SignedURL func

15 views
Skip to first unread message

Nima Jalali

unread,
Nov 20, 2013, 7:28:44 PM11/20/13
to go...@googlegroups.com
I have versioning enabled on my s3 bucket and would like to generate a SignedURL to access a specific version of a file. To do this the s3 API requires adding an additional request parameter "versionId".

The current SignedURL function doesn't expose the params field so I cannot set versionId.

To support this we would need to change the function definition of SignedURL, adding "versionId string". This would break current implementations that use SignedURL()

or

Create another function, possible SignedVersionedURL, with specific support for versioning. This would allow current implementations to keep working without changes.

Implementation of option 1 below:

// SignedURL returns a signed URL that allows anyone holding the URL
// to retrieve the object at path. The signature is valid until expires.
func (b *Bucket) SignedURL(path, versionId string, expires time.Time) string {
params := url.Values{"Expires": {strconv.FormatInt(expires.Unix(), 10)}}
if len(versionId) != 0 {
params.Add("versionId", versionId)
}
req := &request{
bucket: b.Name,
path:   path,
params: params,
}
err := b.S3.prepare(req)
if err != nil {
panic(err)
}
u, err := req.url()
if err != nil {
panic(err)
}
return u.String()
}

Thoughts?
Reply all
Reply to author
Forward
0 new messages