From e5bc26c75ae39691bd8ec70290e5d83a30fe1672 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Fri, 20 May 2016 13:05:49 +0530 Subject: [PATCH] Removed setting of http.Client Timeout for mc (#1720) * Removed setting of http.Client Timeout for mc Fixes #1719 * Moved mcDefaultTransport closer to use * Set ResponseHeaderTimeout to 3 secs * Vendored in changes from github.com/minio/minio-go * Fixed CI build errors due to API changes, post vendoring * Fixed unit tests w.r.t the change from insecure to secure in minio.NewV{2,4} API --- client-s3.go | 30 +++- vendor/github.com/minio/minio-go/API.md | 98 ++++++------ vendor/github.com/minio/minio-go/README.md | 11 +- .../minio/minio-go/api-presigned.go | 47 +++--- .../minio-go/api-put-object-multipart.go | 2 +- .../minio/minio-go/api-put-object.go | 146 ++++++++++-------- vendor/github.com/minio/minio-go/api.go | 38 ++--- vendor/github.com/minio/minio-go/utils.go | 6 +- vendor/vendor.json | 8 +- 9 files changed, 209 insertions(+), 177 deletions(-) diff --git a/client-s3.go b/client-s3.go index 65400186..7bc279c2 100644 --- a/client-s3.go +++ b/client-s3.go @@ -20,6 +20,7 @@ import ( "errors" "hash/fnv" "io" + "net" "net/http" "net/url" "os" @@ -54,9 +55,9 @@ func newFactory() func(config *Config) (Client, *probe.Error) { // Creates a parsed URL. targetURL := newClientURL(config.HostURL) // By default enable HTTPs. - inSecure := false + secure := true if targetURL.Scheme == "http" { - inSecure = true + secure = false } // Instantiate s3 @@ -96,10 +97,10 @@ func newFactory() func(config *Config) (Client, *probe.Error) { var e error if strings.ToUpper(config.Signature) == "S3V2" { // if Signature version '2' use NewV2 directly. - api, e = minio.NewV2(hostName, config.AccessKey, config.SecretKey, inSecure) + api, e = minio.NewV2(hostName, config.AccessKey, config.SecretKey, secure) } else { // if Signature version '4' use NewV4 directly. - api, e = minio.NewV4(hostName, config.AccessKey, config.SecretKey, inSecure) + api, e = minio.NewV4(hostName, config.AccessKey, config.SecretKey, secure) } if e != nil { return nil, probe.NewError(e) @@ -120,9 +121,22 @@ func newFactory() func(config *Config) (Client, *probe.Error) { } // Set custom transport. api.SetCustomTransport(transport) + } else { + // We are using our own http.Transport value to have timeouts different from default + // where necessary. + mcDefaultTransport := http.Transport{ + Proxy: http.ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 10 * time.Second, + //Default ExpectContinueTimeout is 1sec + ExpectContinueTimeout: 3 * time.Second, + ResponseHeaderTimeout: 3 * time.Second, + } + api.SetCustomTransport(&mcDefaultTransport) } - // ListObjects on a prefix with 10 million entries takes around 8 minutes. - api.SetClientTimeout(8 * time.Minute) // Store the new api object. s3Clnt.api = api @@ -754,7 +768,7 @@ func (c *s3Client) ShareDownload(expires time.Duration) (string, *probe.Error) { if e != nil { return "", probe.NewError(e) } - return presignedURL, nil + return presignedURL.String(), nil } // ShareUpload - get data for presigned post http form upload. @@ -780,6 +794,6 @@ func (c *s3Client) ShareUpload(isRecursive bool, expires time.Duration, contentT return nil, probe.NewError(e) } } - m, e := c.api.PresignedPostPolicy(p) + _, m, e := c.api.PresignedPostPolicy(p) return m, probe.NewError(e) } diff --git a/vendor/github.com/minio/minio-go/API.md b/vendor/github.com/minio/minio-go/API.md index 24429d83..d73a469a 100644 --- a/vendor/github.com/minio/minio-go/API.md +++ b/vendor/github.com/minio/minio-go/API.md @@ -12,7 +12,8 @@ import ( ) func main() { - s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false) + secure := true // Make HTTPS requests by default. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", secure) if err !!= nil { fmt.Println(err) return @@ -60,10 +61,10 @@ s3Client can be used to perform operations on S3 storage. APIs are described bel ### Bucket operations --------------------------------------- -#### MakeBucket(bucketName, location) +#### MakeBucket(bucketName string, location string) error Create a new bucket. -__Arguments__ +__Parameters__ * `bucketName` _string_ - Name of the bucket. * `location` _string_ - region valid values are _us-west-1_, _us-west-2_, _eu-west-1_, _eu-central-1_, _ap-southeast-1_, _ap-northeast-1_, _ap-southeast-2_, _sa-east-1_ @@ -78,10 +79,10 @@ fmt.Println("Successfully created mybucket.") ``` --------------------------------------- -#### ListBuckets() -List all buckets. +#### ListBuckets() ([]BucketInfo, error) +Lists all buckets. -`bucketList` emits bucket with the format: +`bucketList` lists bucket in the format: * `bucket.Name` _string_: bucket name * `bucket.CreationDate` time.Time : date when bucket was created @@ -98,10 +99,10 @@ for _, bucket := range buckets { ``` --------------------------------------- -#### BucketExists(bucketName) +#### BucketExists(bucketName string) error Check if bucket exists. -__Arguments__ +__Parameters__ * `bucketName` _string_ : name of the bucket __Example__ @@ -114,10 +115,10 @@ if err != nil { ``` --------------------------------------- -#### RemoveBucket(bucketName) +#### RemoveBucket(bucketName string) error Remove a bucket. -__Arguments__ +__Parameters__ * `bucketName` _string_ : name of the bucket __Example__ @@ -130,16 +131,16 @@ if err != nil { ``` --------------------------------------- -#### GetBucketPolicy(bucketName, objectPrefix) +#### GetBucketPolicy(bucketName string, objectPrefix string) error Get access permissions on a bucket or a prefix. -__Arguments__ +__Parameters__ * `bucketName` _string_ : name of the bucket * `objectPrefix` _string_ : name of the object prefix __Example__ ```go -bucketPolicy, err := s3Client.GetBucketPolicy("mybucket") +bucketPolicy, err := s3Client.GetBucketPolicy("mybucket", "") if err != nil { fmt.Println(err) return @@ -148,13 +149,13 @@ fmt.Println("Access permissions for mybucket is", bucketPolicy) ``` --------------------------------------- -#### SetBucketPolicy(bucketname, objectPrefix, policy) +#### SetBucketPolicy(bucketname string, objectPrefix string, policy BucketPolicy) error Set access permissions on bucket or an object prefix. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectPrefix` _string_ : name of the object prefix -* `policy` _BucketPolicy_: policy can be _non_, _readonly_, _readwrite_, _writeonly_ +* `policy` _BucketPolicy_: policy can be _BucketPolicyNone_, _BucketPolicyReadOnly_, _BucketPolicyReadWrite_, _BucketPolicyWriteOnly_ __Example__ ```go @@ -166,10 +167,10 @@ if err != nil { ``` --------------------------------------- -#### RemoveBucketPolicy(bucketname, objectPrefix) +#### RemoveBucketPolicy(bucketname string, objectPrefix string) error Remove existing permissions on bucket or an object prefix. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectPrefix` _string_ : name of the object prefix @@ -184,10 +185,10 @@ if err != nil { --------------------------------------- -#### ListObjects(bucketName, prefix, recursive, doneCh) +#### ListObjects(bucketName string, prefix string, recursive bool, doneCh chan struct{}) <-chan ObjectInfo List objects in a bucket. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectPrefix` _string_: the prefix of the objects that should be listed * `recursive` _bool_: `true` indicates recursive style listing and `false` indicates directory style listing delimited by '/' @@ -222,10 +223,10 @@ for object := range objectCh { --------------------------------------- -#### ListIncompleteUploads(bucketName, prefix, recursive) +#### ListIncompleteUploads(bucketName string, prefix string, recursive bool, doneCh chan struct{}) <-chan ObjectMultipartInfo List partially uploaded objects in a bucket. -__Arguments__ +__Parameters__ * `bucketname` _string_: name of the bucket * `prefix` _string_: prefix of the object names that are partially uploaded * `recursive` bool: directory style listing when false, recursive listing when true @@ -259,15 +260,15 @@ for multiPartObject := range multiPartObjectCh { --------------------------------------- ### Object operations -#### GetObject(bucketName, objectName) +#### GetObject(bucketName string, objectName string) *Object Download an object. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object __Return Value__ -* `object` _*minio.Object_ : _minio.Object_ represents object reader. +* `object` _*Object_ : _Object_ represents object reader. __Example__ ```go @@ -285,10 +286,10 @@ if _, err := io.Copy(localFile, object); err != nil { --------------------------------------- --------------------------------------- -#### FGetObject(bucketName, objectName, filePath) +#### FGetObject(bucketName string, objectName string, filePath string) error Callback is called with `error` in case of error or `null` in case of success -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object * `filePath` _string_: path to which the object data will be written to @@ -303,11 +304,10 @@ if err != nil { ``` --------------------------------------- -#### PutObject(bucketName, objectName, reader, contentType) -Upload an object. +#### PutObject(bucketName string, objectName string, reader io.Reader, contentType string) (n int, err error) +Upload contents from `io.Reader` to objectName. -Uploading a stream -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object * `reader` _io.Reader_: Any golang object implementing io.Reader @@ -331,10 +331,10 @@ if err != nil { --------------------------------------- -#### CopyObject(bucketName, objectName, objectSource, conditions) +#### CopyObject(bucketName string, objectName string, objectSource string, conditions CopyConditions) error Copy a source object into a new object with the provided name in the provided bucket. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object * `objectSource` _string_: name of the object source. @@ -367,10 +367,10 @@ if err != nil { --------------------------------------- -#### FPutObject(bucketName, objectName, filePath, contentType) +#### FPutObject(bucketName string, objectName string, filePath string, contentType string) error Uploads the object using contents from a file -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object * `filePath` _string_: file path of the file to be uploaded @@ -386,10 +386,10 @@ if err != nil { ``` --------------------------------------- -#### StatObject(bucketName, objectName) +#### StatObject(bucketName string, objectName string) (ObjectInfo, error) Get metadata of an object. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object @@ -411,10 +411,10 @@ fmt.Println(objInfo) ``` --------------------------------------- -#### RemoveObject(bucketName, objectName) +#### RemoveObject(bucketName string, objectName string) error Remove an object. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object @@ -428,10 +428,10 @@ if err != nil { ``` --------------------------------------- -#### RemoveIncompleteUpload(bucketName, objectName) +#### RemoveIncompleteUpload(bucketName string, objectName string) error Remove an partially uploaded object. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object @@ -447,14 +447,14 @@ if err != nil { ### Presigned operations --------------------------------------- -#### PresignedGetObject(bucketName, objectName, expiry) +#### PresignedGetObject(bucketName, objectName string, expiry time.Duration, reqParams url.Values) (*url.URL, error) Generate a presigned URL for GET. -__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket. * `objectName` _string_: name of the object. * `expiry` _time.Duration_: expiry in seconds. - `reqParams` _url.Values_ : additional response header overrides supports _response-expires_, _response-content-type_, _response-cache-control_, _response-content-disposition_ +* `reqParams` _url.Values_ : additional response header overrides supports _response-expires_, _response-content-type_, _response-cache-control_, _response-content-disposition_ __Example__ ```go @@ -472,13 +472,13 @@ if err != nil { --------------------------------------- -#### PresignedPutObject(bucketName, objectName, expiry) +#### PresignedPutObject(bucketName string, objectName string, expiry time.Duration) (*url.URL, error) Generate a presigned URL for PUT.
NOTE: you can upload to S3 only with specified object name.
-__Arguments__ +__Parameters__ * `bucketName` _string_: name of the bucket * `objectName` _string_: name of the object * `expiry` _time.Duration_: expiry in seconds @@ -495,7 +495,7 @@ if err != nil { ---------------------------------------
-#### PresignedPostPolicy +#### PresignedPostPolicy(policy PostPolicy) (*url.URL, map[string]string, error) PresignedPostPolicy we can provide policies specifying conditions restricting what you want to allow in a POST request, such as bucket name where objects can be uploaded, key name prefixes that you want to allow for the object being created and more. @@ -518,7 +518,7 @@ policy.SetContentLengthRange(1024, 1024*1024) ``` Get the POST form key/value object: ```go -formData, err := s3Client.PresignedPostPolicy(policy) +url, formData, err := s3Client.PresignedPostPolicy(policy) if err != nil { fmt.Println(err) return @@ -532,5 +532,5 @@ for k, v := range m { fmt.Printf("-F %s=%s ", k, v) } fmt.Printf("-F file=@/etc/bash.bashrc ") -fmt.Printf("https://my-bucketname.s3.amazonaws.com\n") +fmt.Printf("%s\n", url) ``` diff --git a/vendor/github.com/minio/minio-go/README.md b/vendor/github.com/minio/minio-go/README.md index 3db4f7b8..88b977f6 100644 --- a/vendor/github.com/minio/minio-go/README.md +++ b/vendor/github.com/minio/minio-go/README.md @@ -40,12 +40,13 @@ import ( ) func main() { - // Requests are always secure (HTTPS) by default. Set insecure=true to enable insecure (HTTP) access. + // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. // This boolean value is the last argument for New(). // New returns an Amazon S3 compatible client object. API copatibality (v2 or v4) is automatically // determined based on the Endpoint value. - s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", false) + secure := true // Defaults to HTTPS requests. + s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESS-KEY-HERE", "YOUR-SECRET-KEY-HERE", secure) if err != nil { log.Fatalln(err) } @@ -85,9 +86,9 @@ func main() { * [FGetObject(bucketName, objectName, filePath) error](examples/s3/fgetobject.go) ### Presigned Operations. -* [PresignedGetObject(bucketName, objectName, time.Duration, url.Values) (string, error)](examples/s3/presignedgetobject.go) -* [PresignedPutObject(bucketName, objectName, time.Duration) (string, error)](examples/s3/presignedputobject.go) -* [PresignedPostPolicy(NewPostPolicy()) (map[string]string, error)](examples/s3/presignedpostpolicy.go) +* [PresignedGetObject(bucketName, objectName, time.Duration, url.Values) (*url.URL, error)](examples/s3/presignedgetobject.go) +* [PresignedPutObject(bucketName, objectName, time.Duration) (*url.URL, error)](examples/s3/presignedputobject.go) +* [PresignedPostPolicy(NewPostPolicy()) (*url.URL, map[string]string, error)](examples/s3/presignedpostpolicy.go) ### Bucket Policy Operations. * [SetBucketPolicy(bucketName, objectPrefix, BucketPolicy) error](examples/s3/setbucketpolicy.go) diff --git a/vendor/github.com/minio/minio-go/api-presigned.go b/vendor/github.com/minio/minio-go/api-presigned.go index 5d1ab7bb..83e9cde8 100644 --- a/vendor/github.com/minio/minio-go/api-presigned.go +++ b/vendor/github.com/minio/minio-go/api-presigned.go @@ -33,19 +33,19 @@ var supportedGetReqParams = map[string]struct{}{ // presignURL - Returns a presigned URL for an input 'method'. // Expires maximum is 7days - ie. 604800 and minimum is 1. -func (c Client) presignURL(method string, bucketName string, objectName string, expires time.Duration, reqParams url.Values) (urlStr string, err error) { +func (c Client) presignURL(method string, bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { // Input validation. if method == "" { - return "", ErrInvalidArgument("method cannot be empty.") + return nil, ErrInvalidArgument("method cannot be empty.") } if err := isValidBucketName(bucketName); err != nil { - return "", err + return nil, err } if err := isValidObjectName(objectName); err != nil { - return "", err + return nil, err } if err := isValidExpiry(expires); err != nil { - return "", err + return nil, err } // Convert expires into seconds. @@ -63,7 +63,7 @@ func (c Client) presignURL(method string, bucketName string, objectName string, // Verify if input map has unsupported params, if yes exit. for k := range reqParams { if _, ok := supportedGetReqParams[k]; !ok { - return "", ErrInvalidArgument(k + " unsupported request parameter for presigned GET.") + return nil, ErrInvalidArgument(k + " unsupported request parameter for presigned GET.") } } // Save the request parameters to be used in presigning for @@ -75,43 +75,48 @@ func (c Client) presignURL(method string, bucketName string, objectName string, // Since expires is set newRequest will presign the request. req, err := c.newRequest(method, reqMetadata) if err != nil { - return "", err + return nil, err } - return req.URL.String(), nil + return req.URL, nil } // PresignedGetObject - Returns a presigned URL to access an object // without credentials. Expires maximum is 7days - ie. 604800 and // minimum is 1. Additionally you can override a set of response // headers using the query parameters. -func (c Client) PresignedGetObject(bucketName string, objectName string, expires time.Duration, reqParams url.Values) (url string, err error) { +func (c Client) PresignedGetObject(bucketName string, objectName string, expires time.Duration, reqParams url.Values) (u *url.URL, err error) { return c.presignURL("GET", bucketName, objectName, expires, reqParams) } // PresignedPutObject - Returns a presigned URL to upload an object without credentials. // Expires maximum is 7days - ie. 604800 and minimum is 1. -func (c Client) PresignedPutObject(bucketName string, objectName string, expires time.Duration) (url string, err error) { +func (c Client) PresignedPutObject(bucketName string, objectName string, expires time.Duration) (u *url.URL, err error) { return c.presignURL("PUT", bucketName, objectName, expires, nil) } -// PresignedPostPolicy - Returns POST form data to upload an object at a location. -func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { +// PresignedPostPolicy - Returns POST urlString, form data to upload an object. +func (c Client) PresignedPostPolicy(p *PostPolicy) (u *url.URL, formData map[string]string, err error) { // Validate input arguments. if p.expiration.IsZero() { - return nil, errors.New("Expiration time must be specified") + return nil, nil, errors.New("Expiration time must be specified") } if _, ok := p.formData["key"]; !ok { - return nil, errors.New("object key must be specified") + return nil, nil, errors.New("object key must be specified") } if _, ok := p.formData["bucket"]; !ok { - return nil, errors.New("bucket name must be specified") + return nil, nil, errors.New("bucket name must be specified") } bucketName := p.formData["bucket"] // Fetch the bucket location. location, err := c.getBucketLocation(bucketName) if err != nil { - return nil, err + return nil, nil, err + } + + u, err = c.makeTargetURL(bucketName, "", location, nil) + if err != nil { + return nil, nil, err } // Keep time. @@ -129,7 +134,7 @@ func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { } // Sign the policy. p.formData["signature"] = postPresignSignatureV2(policyBase64, c.secretAccessKey) - return p.formData, nil + return u, p.formData, nil } // Add date policy. @@ -138,7 +143,7 @@ func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { condition: "$x-amz-date", value: t.Format(iso8601DateFormat), }); err != nil { - return nil, err + return nil, nil, err } // Add algorithm policy. @@ -147,7 +152,7 @@ func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { condition: "$x-amz-algorithm", value: signV4Algorithm, }); err != nil { - return nil, err + return nil, nil, err } // Add a credential policy. @@ -157,7 +162,7 @@ func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { condition: "$x-amz-credential", value: credential, }); err != nil { - return nil, err + return nil, nil, err } // Get base64 encoded policy. @@ -168,5 +173,5 @@ func (c Client) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) { p.formData["x-amz-credential"] = credential p.formData["x-amz-date"] = t.Format(iso8601DateFormat) p.formData["x-amz-signature"] = postPresignSignatureV4(policyBase64, t, c.secretAccessKey, location) - return p.formData, nil + return u, p.formData, nil } diff --git a/vendor/github.com/minio/minio-go/api-put-object-multipart.go b/vendor/github.com/minio/minio-go/api-put-object-multipart.go index be96ad23..1b2b4488 100644 --- a/vendor/github.com/minio/minio-go/api-put-object-multipart.go +++ b/vendor/github.com/minio/minio-go/api-put-object-multipart.go @@ -42,7 +42,7 @@ import ( // is where each part is re-downloaded, checksummed and verified // before upload. func (c Client) putObjectMultipart(bucketName, objectName string, reader io.Reader, size int64, contentType string, progress io.Reader) (n int64, err error) { - if size > 0 && size >= minPartSize { + if size > 0 && size > minPartSize { // Verify if reader is *os.File, then use file system functionalities. if isFile(reader) { return c.putObjectMultipartFromFile(bucketName, objectName, reader.(*os.File), size, contentType, progress) diff --git a/vendor/github.com/minio/minio-go/api-put-object.go b/vendor/github.com/minio/minio-go/api-put-object.go index 10390c6c..39b7931a 100644 --- a/vendor/github.com/minio/minio-go/api-put-object.go +++ b/vendor/github.com/minio/minio-go/api-put-object.go @@ -27,78 +27,94 @@ import ( "strings" ) +// toInt - converts go value to its integer representation based +// on the value kind if it is an integer. +func toInt(value reflect.Value) (size int64) { + size = -1 + if value.IsValid() { + switch value.Kind() { + case reflect.Int: + fallthrough + case reflect.Int8: + fallthrough + case reflect.Int16: + fallthrough + case reflect.Int32: + fallthrough + case reflect.Int64: + size = value.Int() + } + } + return size +} + // getReaderSize - Determine the size of Reader if available. func getReaderSize(reader io.Reader) (size int64, err error) { - var result []reflect.Value size = -1 - if reader != nil { - // Verify if there is a method by name 'Size'. - lenFn := reflect.ValueOf(reader).MethodByName("Size") - if lenFn.IsValid() { - if lenFn.Kind() == reflect.Func { - // Call the 'Size' function and save its return value. - result = lenFn.Call([]reflect.Value{}) - if len(result) == 1 { - lenValue := result[0] - if lenValue.IsValid() { - switch lenValue.Kind() { - case reflect.Int: - fallthrough - case reflect.Int8: - fallthrough - case reflect.Int16: - fallthrough - case reflect.Int32: - fallthrough - case reflect.Int64: - size = lenValue.Int() - } + if reader == nil { + return -1, nil + } + // Verify if there is a method by name 'Size'. + sizeFn := reflect.ValueOf(reader).MethodByName("Size") + // Verify if there is a method by name 'Len'. + lenFn := reflect.ValueOf(reader).MethodByName("Len") + if sizeFn.IsValid() { + if sizeFn.Kind() == reflect.Func { + // Call the 'Size' function and save its return value. + result := sizeFn.Call([]reflect.Value{}) + if len(result) == 1 { + size = toInt(result[0]) + } + } + } else if lenFn.IsValid() { + if lenFn.Kind() == reflect.Func { + // Call the 'Len' function and save its return value. + result := lenFn.Call([]reflect.Value{}) + if len(result) == 1 { + size = toInt(result[0]) + } + } + } else { + // Fallback to Stat() method, two possible Stat() structs exist. + switch v := reader.(type) { + case *os.File: + var st os.FileInfo + st, err = v.Stat() + if err != nil { + // Handle this case specially for "windows", + // certain files for example 'Stdin', 'Stdout' and + // 'Stderr' it is not allowed to fetch file information. + if runtime.GOOS == "windows" { + if strings.Contains(err.Error(), "GetFileInformationByHandle") { + return -1, nil } } + return } - } else { - // Fallback to Stat() method, two possible Stat() structs - // exist. - switch v := reader.(type) { - case *os.File: - var st os.FileInfo - st, err = v.Stat() - if err != nil { - // Handle this case specially for "windows", - // certain files for example 'Stdin', 'Stdout' and - // 'Stderr' it is not allowed to fetch file information. - if runtime.GOOS == "windows" { - if strings.Contains(err.Error(), "GetFileInformationByHandle") { - return -1, nil - } - } - return - } - // Ignore if input is a directory, throw an error. - if st.Mode().IsDir() { - return -1, ErrInvalidArgument("Input file cannot be a directory.") - } - // Ignore 'Stdin', 'Stdout' and 'Stderr', since they - // represent *os.File type but internally do not - // implement Seekable calls. Ignore them and treat - // them like a stream with unknown length. - switch st.Name() { - case "stdin": - fallthrough - case "stdout": - fallthrough - case "stderr": - return - } - size = st.Size() - case *Object: - var st ObjectInfo - st, err = v.Stat() - if err != nil { - return - } - size = st.Size + // Ignore if input is a directory, throw an error. + if st.Mode().IsDir() { + return -1, ErrInvalidArgument("Input file cannot be a directory.") } + // Ignore 'Stdin', 'Stdout' and 'Stderr', since they + // represent *os.File type but internally do not + // implement Seekable calls. Ignore them and treat + // them like a stream with unknown length. + switch st.Name() { + case "stdin": + fallthrough + case "stdout": + fallthrough + case "stderr": + return + } + size = st.Size() + case *Object: + var st ObjectInfo + st, err = v.Stat() + if err != nil { + return + } + size = st.Size } } // Returns the size here. diff --git a/vendor/github.com/minio/minio-go/api.go b/vendor/github.com/minio/minio-go/api.go index 93c0a6d2..2051a68c 100644 --- a/vendor/github.com/minio/minio-go/api.go +++ b/vendor/github.com/minio/minio-go/api.go @@ -84,8 +84,8 @@ const ( // NewV2 - instantiate minio client with Amazon S3 signature version // '2' compatibility. -func NewV2(endpoint string, accessKeyID, secretAccessKey string, insecure bool) (*Client, error) { - clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, insecure) +func NewV2(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, secure) if err != nil { return nil, err } @@ -96,8 +96,8 @@ func NewV2(endpoint string, accessKeyID, secretAccessKey string, insecure bool) // NewV4 - instantiate minio client with Amazon S3 signature version // '4' compatibility. -func NewV4(endpoint string, accessKeyID, secretAccessKey string, insecure bool) (*Client, error) { - clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, insecure) +func NewV4(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, secure) if err != nil { return nil, err } @@ -108,8 +108,8 @@ func NewV4(endpoint string, accessKeyID, secretAccessKey string, insecure bool) // New - instantiate minio client Client, adds automatic verification // of signature. -func New(endpoint string, accessKeyID, secretAccessKey string, insecure bool) (*Client, error) { - clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, insecure) +func New(endpoint string, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { + clnt, err := privateNew(endpoint, accessKeyID, secretAccessKey, secure) if err != nil { return nil, err } @@ -148,9 +148,9 @@ func (r *lockedRandSource) Seed(seed int64) { r.lk.Unlock() } -func privateNew(endpoint, accessKeyID, secretAccessKey string, insecure bool) (*Client, error) { +func privateNew(endpoint, accessKeyID, secretAccessKey string, secure bool) (*Client, error) { // construct endpoint. - endpointURL, err := getEndpointURL(endpoint, insecure) + endpointURL, err := getEndpointURL(endpoint, secure) if err != nil { return nil, err } @@ -168,10 +168,6 @@ func privateNew(endpoint, accessKeyID, secretAccessKey string, insecure bool) (* // Instantiate http client and bucket location cache. clnt.httpClient = &http.Client{ - // Setting a sensible time out of 2minutes to wait for response - // headers. Request is pro-actively cancelled after 2minutes - // if no response was received from server. - Timeout: 2 * time.Minute, Transport: http.DefaultTransport, } @@ -220,13 +216,6 @@ func (c *Client) SetCustomTransport(customHTTPTransport http.RoundTripper) { } } -// SetClientTimeout - set http client timeout. -func (c *Client) SetClientTimeout(timeout time.Duration) { - if c.httpClient != nil { - c.httpClient.Timeout = timeout - } -} - // TraceOn - enable HTTP tracing. func (c *Client) TraceOn(outputStream io.Writer) { // if outputStream is nil then default to os.Stdout. @@ -568,10 +557,15 @@ func (c Client) newRequest(method string, metadata requestMetadata) (req *http.R req.Body = ioutil.NopCloser(metadata.contentBody) } - // set 'Expect' header for the request. - req.Header.Set("Expect", "100-continue") + // FIXEM: Enable this when Google Cloud Storage properly supports 100-continue. + // Skip setting 'expect' header for Google Cloud Storage, there + // are some known issues - https://github.com/restic/restic/issues/520 + if !isGoogleEndpoint(c.endpointURL) { + // Set 'Expect' header for the request. + req.Header.Set("Expect", "100-continue") + } - // set 'User-Agent' header for the request. + // Set 'User-Agent' header for the request. c.setUserAgent(req) // Set all headers. diff --git a/vendor/github.com/minio/minio-go/utils.go b/vendor/github.com/minio/minio-go/utils.go index 10466584..90c6a95d 100644 --- a/vendor/github.com/minio/minio-go/utils.go +++ b/vendor/github.com/minio/minio-go/utils.go @@ -63,7 +63,7 @@ func sumHMAC(key []byte, data []byte) []byte { } // getEndpointURL - construct a new endpoint. -func getEndpointURL(endpoint string, inSecure bool) (*url.URL, error) { +func getEndpointURL(endpoint string, secure bool) (*url.URL, error) { if strings.Contains(endpoint, ":") { host, _, err := net.SplitHostPort(endpoint) if err != nil { @@ -79,9 +79,9 @@ func getEndpointURL(endpoint string, inSecure bool) (*url.URL, error) { return nil, ErrInvalidArgument(msg) } } - // if inSecure is true, use 'http' scheme. + // If secure is false, use 'http' scheme. scheme := "https" - if inSecure { + if !secure { scheme = "http" } diff --git a/vendor/vendor.json b/vendor/vendor.json index af0c53ac..83e3ee66 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -43,9 +43,10 @@ "revisionTime": "2015-10-24T22:24:27-07:00" }, { + "checksumSHA1": "AAF7RJL0VyzNA2Sraqc3frechJA=", "path": "github.com/minio/minio-go", - "revision": "04bf6717de35ba1ef94613ddf97be157f6396974", - "revisionTime": "2016-04-25T01:09:41-07:00" + "revision": "ec61681ad172f3f0818685a20c535c2f1a7de2ac", + "revisionTime": "2016-05-19T11:05:51Z" }, { "path": "github.com/minio/minio/pkg/atomic", @@ -92,5 +93,6 @@ "revision": "11d3bc7aa68e238947792f30573146a3231fc0f1", "revisionTime": "2015-07-29T10:04:31+02:00" } - ] + ], + "rootPath": "github.com/minio/mc" }