Merge pull request #995 from harshavardhana/improve-share

Improve share command
This commit is contained in:
Harshavardhana
2015-08-12 17:01:12 -07:00
7 changed files with 20 additions and 16 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+3 -2
View File
@@ -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
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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"`
}
+10 -7
View File
@@ -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()
}