Add `share` command leveraging new PresignedURL API from minio-go

This commit is contained in:
Harshavardhana
2015-08-06 21:52:53 -07:00
parent 8c1805d2e9
commit c36ed96f26
11 changed files with 363 additions and 27 deletions
+1
View File
@@ -35,6 +35,7 @@ type Client interface {
SetBucketACL(acl string) *probe.Error
// Object operations
PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error)
GetObject(offset, length int64) (body io.ReadCloser, size int64, err *probe.Error)
PutObject(size int64, data io.Reader) *probe.Error
+9
View File
@@ -95,6 +95,15 @@ type GenericObjectError struct {
Object string
}
// ObjectAlreadyExists - typed return for MethodNotAllowed
type ObjectAlreadyExists struct {
Object string
}
func (e ObjectAlreadyExists) Error() string {
return "Object #" + e.Object + " already exists."
}
// ObjectNotFound - object requested does not exist
type ObjectNotFound GenericObjectError
+5
View File
@@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"io/ioutil"
@@ -121,6 +122,10 @@ func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) {
}
}
func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) {
return "", probe.New(client.APINotImplemented{API: "PresignedGetObject"})
}
// GetObject download an full or part object from bucket
// getobject returns a reader, length and nil for no errors
// with errors getobject will return nil reader, length and typed errors
+9 -8
View File
@@ -101,13 +101,14 @@ func (c *s3Client) GetObject(offset, length int64) (io.ReadCloser, int64, *probe
return reader, metadata.Size, nil
}
// ObjectAlreadyExists - typed return for MethodNotAllowed
type ObjectAlreadyExists struct {
Object string
}
func (e ObjectAlreadyExists) Error() string {
return "Object #" + e.Object + " already exists."
// PresignedGetObject - get a presigned usable get object url to share
func (c *s3Client) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) {
bucket, object := c.url2BucketAndObject()
presignedURL, err := c.api.PresignedGetPartialObject(bucket, object, expires, offset, length)
if err != nil {
return "", probe.New(err)
}
return presignedURL, nil
}
// PutObject - put object
@@ -121,7 +122,7 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
errResponse := minio.ToErrorResponse(err)
if errResponse != nil {
if errResponse.Code == "MethodNotAllowed" {
return probe.New(ObjectAlreadyExists{Object: object})
return probe.New(client.ObjectAlreadyExists{Object: object})
}
}
return probe.New(err)