Add `share` command leveraging new PresignedURL API from minio-go
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user