diff --git a/globals.go b/globals.go index b5c3cd62..d7ab87ab 100644 --- a/globals.go +++ b/globals.go @@ -19,7 +19,7 @@ package main var ( globalQuietFlag = false // Quiet flag set via command line - globalMimicFlag = false // Unix flag set via command line + globalMimicFlag = false // Unix flag set via command line globalJSONFlag = false // Json flag set via command line globalDebugFlag = false // Debug flag set via command line diff --git a/pkg/client/client.go b/pkg/client/client.go index 19927c7e..adc56938 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -35,7 +35,7 @@ type Client interface { SetBucketACL(acl string) *probe.Error // Object operations - PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) + Share(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 diff --git a/pkg/client/errors.go b/pkg/client/errors.go index 7fcc77bb..cf0c016c 100644 --- a/pkg/client/errors.go +++ b/pkg/client/errors.go @@ -22,11 +22,12 @@ import "strconv" // APINotImplemented - api not implemented type APINotImplemented struct { - API string + API string + APIType string } func (e APINotImplemented) Error() string { - return "API not implemented: " + e.API + return "‘" + e.API + "’ feature " + "is not implemented for ‘" + e.APIType + "’" } // UnexpectedError - unexpected error diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index a167c6b2..82b38fe1 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -122,8 +122,8 @@ func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) { } } -func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) { - return "", probe.NewError(client.APINotImplemented{API: "PresignedGetObject"}) +func (f *fsClient) Share(expires time.Duration, offset, length int64) (string, *probe.Error) { + return "", probe.NewError(client.APINotImplemented{API: "Share", APIType: "filesystem"}) } // GetObject download an full or part object from bucket diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 289311e3..2e66ce80 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -101,8 +101,8 @@ func (c *s3Client) GetObject(offset, length int64) (io.ReadCloser, int64, *probe return reader, metadata.Size, nil } -// PresignedGetObject - get a presigned usable get object url to share -func (c *s3Client) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) { +// Share - get a usable get object url to share +func (c *s3Client) Share(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 { diff --git a/print-structs.go b/print-structs.go index 50a7d510..e30c09d1 100644 --- a/print-structs.go +++ b/print-structs.go @@ -166,7 +166,7 @@ func (s MirrorMessage) String() string { // ShareMessage container for share messages type ShareMessage struct { Version string `json:"version"` - Expires time.Duration `json:"expires"` + Expires time.Duration `json:"expire-seconds"` PresignedURL string `json:"presigned-url"` } diff --git a/share-main.go b/share-main.go index a6f17813..3e53c1c0 100644 --- a/share-main.go +++ b/share-main.go @@ -31,13 +31,13 @@ import ( // Help message. var shareCmd = cli.Command{ Name: "share", - Usage: "Share presigned URLs from cloud storage", + Usage: "Share documents via URL", Action: mainShare, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} TARGET DURATION {{if .Description}} + mc {{.Name}} TARGET [DURATION=s|m|h|d] {{if .Description}} DESCRIPTION: {{.Description}}{{end}}{{if .Flags}} @@ -47,11 +47,14 @@ FLAGS: {{end}}{{ end }} EXAMPLES: - 1. Generate presigned url for an object, with expiration of 10minutes - $ mc {{.Name}} url https://s3.amazonaws.com/backup/2006-Mar-1/backup.tar.gz 10m + 1. Generate URL for sharing, with a default expiry of 7 days. + $ mc {{.Name}} https://s3.amazonaws.com/backup/2006-Mar-1/backup.tar.gz - 2. Generate presigned url for all objects at given path, with expiration of 20minutes - $ mc {{.Name}} url https://s3.amazonaws.com/backup... 20m + 2. Generate URL for sharing, with an expiry of 10 minutes. + $ mc {{.Name}} https://s3.amazonaws.com/backup/2006-Mar-1/backup.tar.gz 10m + + 3. Generate list of URLs for sharing a folder recursively, with expiration of 1 hour each. + $ mc {{.Name}} https://s3.amazonaws.com/backup... 1h `, } @@ -109,7 +112,7 @@ func doShareCmd(targetURL string, recursive bool, expires time.Duration) *probe. if err != nil { return err.Trace() } - presignedURL, err := newClnt.PresignedGetObject(expires, 0, 0) + presignedURL, err := newClnt.Share(expires, 0, 0) if err != nil { return err.Trace() }