mirror of
https://github.com/minio/minio.git
synced 2025-01-23 12:43:16 -05:00
gateway-s3: vendor-update minio-go (#4220)
This commit is contained in:
parent
4aa65910e5
commit
e5b2e25caf
@ -16,18 +16,25 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"io"
|
||||
|
||||
minio "github.com/minio/minio-go"
|
||||
)
|
||||
|
||||
// AnonGetObject - Get object anonymously
|
||||
func (l *s3Gateway) AnonGetObject(bucket string, key string, startOffset int64, length int64, writer io.Writer) error {
|
||||
object, err := l.anonClient.GetObject(bucket, key)
|
||||
r := minio.NewGetReqHeaders()
|
||||
if err := r.SetRange(startOffset, startOffset+length-1); err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
object, _, err := l.anonClient.GetObject(bucket, key, r)
|
||||
if err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
|
||||
defer object.Close()
|
||||
|
||||
object.Seek(startOffset, io.SeekStart)
|
||||
if _, err := io.CopyN(writer, object, length); err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
@ -37,7 +44,8 @@ func (l *s3Gateway) AnonGetObject(bucket string, key string, startOffset int64,
|
||||
|
||||
// AnonGetObjectInfo - Get object info anonymously
|
||||
func (l *s3Gateway) AnonGetObjectInfo(bucket string, object string) (ObjectInfo, error) {
|
||||
oi, err := l.anonClient.StatObject(bucket, object)
|
||||
r := minio.NewHeadReqHeaders()
|
||||
oi, err := l.anonClient.StatObject(bucket, object, r)
|
||||
if err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"hash"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
@ -264,17 +262,17 @@ func fromMinioClientListBucketResult(bucket string, result minio.ListBucketResul
|
||||
// startOffset indicates the starting read location of the object.
|
||||
// length indicates the total length of the object.
|
||||
func (l *s3Gateway) GetObject(bucket string, key string, startOffset int64, length int64, writer io.Writer) error {
|
||||
object, err := l.Client.GetObject(bucket, key)
|
||||
r := minio.NewGetReqHeaders()
|
||||
if err := r.SetRange(startOffset, startOffset+length-1); err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
object, _, err := l.Client.GetObject(bucket, key, r)
|
||||
if err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
|
||||
defer object.Close()
|
||||
|
||||
if _, err := object.Seek(startOffset, io.SeekStart); err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
|
||||
if _, err := io.CopyN(writer, object, length); err != nil {
|
||||
return s3ToObjectError(traceError(err), bucket, key)
|
||||
}
|
||||
@ -301,7 +299,8 @@ func fromMinioClientObjectInfo(bucket string, oi minio.ObjectInfo) ObjectInfo {
|
||||
|
||||
// GetObjectInfo reads object info and replies back ObjectInfo
|
||||
func (l *s3Gateway) GetObjectInfo(bucket string, object string) (objInfo ObjectInfo, err error) {
|
||||
oi, err := l.Client.StatObject(bucket, object)
|
||||
r := minio.NewHeadReqHeaders()
|
||||
oi, err := l.Client.StatObject(bucket, object, r)
|
||||
if err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
}
|
||||
@ -311,34 +310,29 @@ func (l *s3Gateway) GetObjectInfo(bucket string, object string) (objInfo ObjectI
|
||||
|
||||
// PutObject creates a new object with the incoming data,
|
||||
func (l *s3Gateway) PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string, sha256sum string) (ObjectInfo, error) {
|
||||
var sha256Writer hash.Hash
|
||||
var sha256sumBytes []byte
|
||||
|
||||
sha256sumBytes := []byte{}
|
||||
|
||||
teeReader := data
|
||||
if sha256sum == "" {
|
||||
} else if b, err := hex.DecodeString(sha256sum); err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
} else {
|
||||
sha256sumBytes = b
|
||||
|
||||
sha256Writer = sha256.New()
|
||||
teeReader = io.TeeReader(data, sha256Writer)
|
||||
}
|
||||
|
||||
delete(metadata, "md5Sum")
|
||||
|
||||
oi, err := l.Client.PutObject(bucket, object, size, teeReader, nil, sha256sumBytes, toMinioClientMetadata(metadata))
|
||||
var err error
|
||||
if sha256sum != "" {
|
||||
sha256sumBytes, err = hex.DecodeString(sha256sum)
|
||||
if err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
}
|
||||
|
||||
if sha256sum != "" {
|
||||
newSHA256sum := hex.EncodeToString(sha256Writer.Sum(nil))
|
||||
if newSHA256sum != sha256sum {
|
||||
l.Client.RemoveObject(bucket, object)
|
||||
return ObjectInfo{}, traceError(SHA256Mismatch{})
|
||||
}
|
||||
|
||||
var md5sumBytes []byte
|
||||
md5sum := metadata["md5Sum"]
|
||||
if md5sum != "" {
|
||||
md5sumBytes, err = hex.DecodeString(md5sum)
|
||||
if err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
}
|
||||
delete(metadata, "md5Sum")
|
||||
}
|
||||
|
||||
oi, err := l.Client.PutObject(bucket, object, size, data, md5sumBytes, sha256sumBytes, toMinioClientMetadata(metadata))
|
||||
if err != nil {
|
||||
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
||||
}
|
||||
|
||||
return fromMinioClientObjectInfo(bucket, oi), nil
|
||||
|
7
vendor/github.com/minio/minio-go/api-error-response.go
generated
vendored
7
vendor/github.com/minio/minio-go/api-error-response.go
generated
vendored
@ -134,6 +134,13 @@ func httpRespToErrorResponse(resp *http.Response, bucketName, objectName string)
|
||||
Message: "Bucket not empty.",
|
||||
BucketName: bucketName,
|
||||
}
|
||||
case http.StatusPreconditionFailed:
|
||||
errResp = ErrorResponse{
|
||||
Code: "PreconditionFailed",
|
||||
Message: s3ErrorResponseMap["PreconditionFailed"],
|
||||
BucketName: bucketName,
|
||||
Key: objectName,
|
||||
}
|
||||
default:
|
||||
errResp = ErrorResponse{
|
||||
Code: resp.Status,
|
||||
|
7
vendor/github.com/minio/minio-go/api-get-object-file.go
generated
vendored
7
vendor/github.com/minio/minio-go/api-get-object-file.go
generated
vendored
@ -78,8 +78,13 @@ func (c Client) FGetObject(bucketName, objectName, filePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize get object request headers to set the
|
||||
// appropriate range offsets to read from.
|
||||
reqHeaders := NewGetReqHeaders()
|
||||
reqHeaders.SetRange(st.Size(), 0)
|
||||
|
||||
// Seek to current position for incoming reader.
|
||||
objectReader, objectStat, err := c.getObject(bucketName, objectName, st.Size(), 0)
|
||||
objectReader, objectStat, err := c.getObject(bucketName, objectName, reqHeaders)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
62
vendor/github.com/minio/minio-go/api-get-object.go
generated
vendored
62
vendor/github.com/minio/minio-go/api-get-object.go
generated
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2015, 2016 Minio, Inc.
|
||||
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2015, 2016, 2017 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -67,6 +67,7 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
var httpReader io.ReadCloser
|
||||
var objectInfo ObjectInfo
|
||||
var err error
|
||||
|
||||
// Create request channel.
|
||||
reqCh := make(chan getRequest)
|
||||
// Create response channel.
|
||||
@ -79,6 +80,9 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
defer close(reqCh)
|
||||
defer close(resCh)
|
||||
|
||||
// Used to verify if etag of object has changed since last read.
|
||||
var etag string
|
||||
|
||||
// Loop through the incoming control messages and read data.
|
||||
for {
|
||||
select {
|
||||
@ -97,16 +101,19 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
if req.isFirstReq {
|
||||
// First request is a Read/ReadAt.
|
||||
if req.isReadOp {
|
||||
reqHeaders := NewGetReqHeaders()
|
||||
// Differentiate between wanting the whole object and just a range.
|
||||
if req.isReadAt {
|
||||
// If this is a ReadAt request only get the specified range.
|
||||
// Range is set with respect to the offset and length of the buffer requested.
|
||||
// Do not set objectInfo from the first readAt request because it will not get
|
||||
// the whole object.
|
||||
httpReader, _, err = c.getObject(bucketName, objectName, req.Offset, int64(len(req.Buffer)))
|
||||
reqHeaders.SetRange(req.Offset, req.Offset+int64(len(req.Buffer))-1)
|
||||
httpReader, objectInfo, err = c.getObject(bucketName, objectName, reqHeaders)
|
||||
} else {
|
||||
reqHeaders.SetRange(req.Offset, 0)
|
||||
// First request is a Read request.
|
||||
httpReader, objectInfo, err = c.getObject(bucketName, objectName, req.Offset, 0)
|
||||
httpReader, objectInfo, err = c.getObject(bucketName, objectName, reqHeaders)
|
||||
}
|
||||
if err != nil {
|
||||
resCh <- getResponse{
|
||||
@ -114,6 +121,7 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
etag = objectInfo.ETag
|
||||
// Read at least firstReq.Buffer bytes, if not we have
|
||||
// reached our EOF.
|
||||
size, err := io.ReadFull(httpReader, req.Buffer)
|
||||
@ -140,13 +148,18 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
// Exit the go-routine.
|
||||
return
|
||||
}
|
||||
etag = objectInfo.ETag
|
||||
// Send back the first response.
|
||||
resCh <- getResponse{
|
||||
objectInfo: objectInfo,
|
||||
}
|
||||
}
|
||||
} else if req.settingObjectInfo { // Request is just to get objectInfo.
|
||||
objectInfo, err := c.StatObject(bucketName, objectName)
|
||||
reqHeaders := NewGetReqHeaders()
|
||||
if etag != "" {
|
||||
reqHeaders.SetMatchETag(etag)
|
||||
}
|
||||
objectInfo, err := c.statObject(bucketName, objectName, reqHeaders)
|
||||
if err != nil {
|
||||
resCh <- getResponse{
|
||||
Error: err,
|
||||
@ -166,6 +179,10 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
// new ones when they haven't been already.
|
||||
// All readAt requests are new requests.
|
||||
if req.DidOffsetChange || !req.beenRead {
|
||||
reqHeaders := NewGetReqHeaders()
|
||||
if etag != "" {
|
||||
reqHeaders.SetMatchETag(etag)
|
||||
}
|
||||
if httpReader != nil {
|
||||
// Close previously opened http reader.
|
||||
httpReader.Close()
|
||||
@ -173,9 +190,12 @@ func (c Client) GetObject(bucketName, objectName string) (*Object, error) {
|
||||
// If this request is a readAt only get the specified range.
|
||||
if req.isReadAt {
|
||||
// Range is set with respect to the offset and length of the buffer requested.
|
||||
httpReader, _, err = c.getObject(bucketName, objectName, req.Offset, int64(len(req.Buffer)))
|
||||
reqHeaders.SetRange(req.Offset, req.Offset+int64(len(req.Buffer))-1)
|
||||
httpReader, _, err = c.getObject(bucketName, objectName, reqHeaders)
|
||||
} else {
|
||||
httpReader, objectInfo, err = c.getObject(bucketName, objectName, req.Offset, 0)
|
||||
// Range is set with respect to the offset.
|
||||
reqHeaders.SetRange(req.Offset, 0)
|
||||
httpReader, objectInfo, err = c.getObject(bucketName, objectName, reqHeaders)
|
||||
}
|
||||
if err != nil {
|
||||
resCh <- getResponse{
|
||||
@ -230,8 +250,8 @@ type getResponse struct {
|
||||
objectInfo ObjectInfo // Used for the first request.
|
||||
}
|
||||
|
||||
// Object represents an open object. It implements Read, ReadAt,
|
||||
// Seeker, Close for a HTTP stream.
|
||||
// Object represents an open object. It implements
|
||||
// Reader, ReaderAt, Seeker, Closer for a HTTP stream.
|
||||
type Object struct {
|
||||
// Mutex.
|
||||
mutex *sync.Mutex
|
||||
@ -269,6 +289,12 @@ type Object struct {
|
||||
func (o *Object) doGetRequest(request getRequest) (getResponse, error) {
|
||||
o.reqCh <- request
|
||||
response := <-o.resCh
|
||||
|
||||
// Return any error to the top level.
|
||||
if response.Error != nil {
|
||||
return response, response.Error
|
||||
}
|
||||
|
||||
// This was the first request.
|
||||
if !o.isStarted {
|
||||
// The object has been operated on.
|
||||
@ -284,11 +310,6 @@ func (o *Object) doGetRequest(request getRequest) (getResponse, error) {
|
||||
if !o.beenRead {
|
||||
o.beenRead = response.didRead
|
||||
}
|
||||
// Return any error to the top level.
|
||||
if response.Error != nil {
|
||||
return response, response.Error
|
||||
}
|
||||
|
||||
// Data are ready on the wire, no need to reinitiate connection in lower level
|
||||
o.seekData = false
|
||||
|
||||
@ -594,7 +615,7 @@ func newObject(reqCh chan<- getRequest, resCh <-chan getResponse, doneCh chan<-
|
||||
//
|
||||
// For more information about the HTTP Range header.
|
||||
// go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
|
||||
func (c Client) getObject(bucketName, objectName string, offset, length int64) (io.ReadCloser, ObjectInfo, error) {
|
||||
func (c Client) getObject(bucketName, objectName string, reqHeaders RequestHeaders) (io.ReadCloser, ObjectInfo, error) {
|
||||
// Validate input arguments.
|
||||
if err := isValidBucketName(bucketName); err != nil {
|
||||
return nil, ObjectInfo{}, err
|
||||
@ -603,15 +624,10 @@ func (c Client) getObject(bucketName, objectName string, offset, length int64) (
|
||||
return nil, ObjectInfo{}, err
|
||||
}
|
||||
|
||||
// Set all the necessary reqHeaders.
|
||||
customHeader := make(http.Header)
|
||||
// Set ranges if length and offset are valid.
|
||||
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.
|
||||
if length > 0 && offset >= 0 {
|
||||
customHeader.Set("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
|
||||
} else if offset > 0 && length == 0 {
|
||||
customHeader.Set("Range", fmt.Sprintf("bytes=%d-", offset))
|
||||
} else if length < 0 && offset == 0 {
|
||||
customHeader.Set("Range", fmt.Sprintf("bytes=%d", length))
|
||||
for key, value := range reqHeaders.Header {
|
||||
customHeader[key] = value
|
||||
}
|
||||
|
||||
// Execute GET on objectName.
|
||||
@ -619,6 +635,7 @@ func (c Client) getObject(bucketName, objectName string, offset, length int64) (
|
||||
bucketName: bucketName,
|
||||
objectName: objectName,
|
||||
customHeader: customHeader,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, ObjectInfo{}, err
|
||||
@ -645,6 +662,7 @@ func (c Client) getObject(bucketName, objectName string, offset, length int64) (
|
||||
Region: resp.Header.Get("x-amz-bucket-region"),
|
||||
}
|
||||
}
|
||||
|
||||
// Get content-type.
|
||||
contentType := strings.TrimSpace(resp.Header.Get("Content-Type"))
|
||||
if contentType == "" {
|
||||
|
1
vendor/github.com/minio/minio-go/api-get-policy.go
generated
vendored
1
vendor/github.com/minio/minio-go/api-get-policy.go
generated
vendored
@ -81,6 +81,7 @@ func (c Client) getBucketPolicy(bucketName string) (policy.BucketAccessPolicy, e
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
|
||||
defer closeResponse(resp)
|
||||
|
6
vendor/github.com/minio/minio-go/api-list.go
generated
vendored
6
vendor/github.com/minio/minio-go/api-list.go
generated
vendored
@ -35,7 +35,7 @@ import (
|
||||
//
|
||||
func (c Client) ListBuckets() ([]BucketInfo, error) {
|
||||
// Execute GET on service.
|
||||
resp, err := c.executeMethod("GET", requestMetadata{})
|
||||
resp, err := c.executeMethod("GET", requestMetadata{contentSHA256Bytes: emptySHA256})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -213,6 +213,7 @@ func (c Client) listObjectsV2Query(bucketName, objectPrefix, continuationToken s
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -383,6 +384,7 @@ func (c Client) listObjectsQuery(bucketName, objectPrefix, objectMarker, delimit
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -561,6 +563,7 @@ func (c Client) listMultipartUploadsQuery(bucketName, keyMarker, uploadIDMarker,
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -679,6 +682,7 @@ func (c Client) listObjectPartsQuery(bucketName, objectName, uploadID string, pa
|
||||
bucketName: bucketName,
|
||||
objectName: objectName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
|
2
vendor/github.com/minio/minio-go/api-notification.go
generated
vendored
2
vendor/github.com/minio/minio-go/api-notification.go
generated
vendored
@ -49,6 +49,7 @@ func (c Client) getBucketNotification(bucketName string) (BucketNotification, er
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
|
||||
defer closeResponse(resp)
|
||||
@ -172,6 +173,7 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even
|
||||
resp, err := c.executeMethod("GET", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
if err != nil {
|
||||
continue
|
||||
|
1
vendor/github.com/minio/minio-go/api-put-bucket.go
generated
vendored
1
vendor/github.com/minio/minio-go/api-put-bucket.go
generated
vendored
@ -274,6 +274,7 @@ func (c Client) removeBucketPolicy(bucketName string) error {
|
||||
resp, err := c.executeMethod("DELETE", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
|
3
vendor/github.com/minio/minio-go/api-remove.go
generated
vendored
3
vendor/github.com/minio/minio-go/api-remove.go
generated
vendored
@ -36,6 +36,7 @@ func (c Client) RemoveBucket(bucketName string) error {
|
||||
// Execute DELETE on bucket.
|
||||
resp, err := c.executeMethod("DELETE", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -66,6 +67,7 @@ func (c Client) RemoveObject(bucketName, objectName string) error {
|
||||
resp, err := c.executeMethod("DELETE", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
objectName: objectName,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -251,6 +253,7 @@ func (c Client) abortMultipartUpload(bucketName, objectName, uploadID string) er
|
||||
bucketName: bucketName,
|
||||
objectName: objectName,
|
||||
queryValues: urlValues,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
|
23
vendor/github.com/minio/minio-go/api-stat.go
generated
vendored
23
vendor/github.com/minio/minio-go/api-stat.go
generated
vendored
@ -35,6 +35,7 @@ func (c Client) BucketExists(bucketName string) (bool, error) {
|
||||
// Execute HEAD on bucketName.
|
||||
resp, err := c.executeMethod("HEAD", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -85,11 +86,31 @@ func (c Client) StatObject(bucketName, objectName string) (ObjectInfo, error) {
|
||||
if err := isValidObjectName(objectName); err != nil {
|
||||
return ObjectInfo{}, err
|
||||
}
|
||||
reqHeaders := NewHeadReqHeaders()
|
||||
return c.statObject(bucketName, objectName, reqHeaders)
|
||||
}
|
||||
|
||||
// Lower level API for statObject supporting pre-conditions and range headers.
|
||||
func (c Client) statObject(bucketName, objectName string, reqHeaders RequestHeaders) (ObjectInfo, error) {
|
||||
// Input validation.
|
||||
if err := isValidBucketName(bucketName); err != nil {
|
||||
return ObjectInfo{}, err
|
||||
}
|
||||
if err := isValidObjectName(objectName); err != nil {
|
||||
return ObjectInfo{}, err
|
||||
}
|
||||
|
||||
customHeader := make(http.Header)
|
||||
for k, v := range reqHeaders.Header {
|
||||
customHeader[k] = v
|
||||
}
|
||||
|
||||
// Execute HEAD on objectName.
|
||||
resp, err := c.executeMethod("HEAD", requestMetadata{
|
||||
bucketName: bucketName,
|
||||
objectName: objectName,
|
||||
contentSHA256Bytes: emptySHA256,
|
||||
customHeader: customHeader,
|
||||
})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@ -122,6 +143,7 @@ func (c Client) StatObject(bucketName, objectName string) (ObjectInfo, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse Last-Modified has http time format.
|
||||
date, err := time.Parse(http.TimeFormat, resp.Header.Get("Last-Modified"))
|
||||
if err != nil {
|
||||
@ -135,6 +157,7 @@ func (c Client) StatObject(bucketName, objectName string) (ObjectInfo, error) {
|
||||
Region: resp.Header.Get("x-amz-bucket-region"),
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch content type if any present.
|
||||
contentType := strings.TrimSpace(resp.Header.Get("Content-Type"))
|
||||
if contentType == "" {
|
||||
|
18
vendor/github.com/minio/minio-go/api.go
generated
vendored
18
vendor/github.com/minio/minio-go/api.go
generated
vendored
@ -654,27 +654,23 @@ func (c Client) newRequest(method string, metadata requestMetadata) (req *http.R
|
||||
return req, nil
|
||||
} // Sign the request for all authenticated requests.
|
||||
|
||||
if c.signature.isV2() {
|
||||
switch {
|
||||
case c.signature.isV2():
|
||||
// Add signature version '2' authorization header.
|
||||
req = s3signer.SignV2(*req, c.accessKeyID, c.secretAccessKey)
|
||||
} else if c.signature.isV4() || c.signature.isStreamingV4() &&
|
||||
method != "PUT" {
|
||||
case c.signature.isStreamingV4() && method == "PUT":
|
||||
req = s3signer.StreamingSignV4(req, c.accessKeyID,
|
||||
c.secretAccessKey, location, metadata.contentLength, time.Now().UTC())
|
||||
default:
|
||||
// Set sha256 sum for signature calculation only with signature version '4'.
|
||||
shaHeader := unsignedPayload
|
||||
if !c.secure {
|
||||
if metadata.contentSHA256Bytes == nil {
|
||||
shaHeader = hex.EncodeToString(sum256([]byte{}))
|
||||
} else {
|
||||
if len(metadata.contentSHA256Bytes) > 0 {
|
||||
shaHeader = hex.EncodeToString(metadata.contentSHA256Bytes)
|
||||
}
|
||||
}
|
||||
req.Header.Set("X-Amz-Content-Sha256", shaHeader)
|
||||
|
||||
// Add signature version '4' authorization header.
|
||||
req = s3signer.SignV4(*req, c.accessKeyID, c.secretAccessKey, location)
|
||||
} else if c.signature.isStreamingV4() {
|
||||
req = s3signer.StreamingSignV4(req, c.accessKeyID,
|
||||
c.secretAccessKey, location, metadata.contentLength, time.Now().UTC())
|
||||
}
|
||||
|
||||
// Return request.
|
||||
|
13
vendor/github.com/minio/minio-go/core.go
generated
vendored
13
vendor/github.com/minio/minio-go/core.go
generated
vendored
@ -98,3 +98,16 @@ func (c Core) GetBucketPolicy(bucket string) (policy.BucketAccessPolicy, error)
|
||||
func (c Core) PutBucketPolicy(bucket string, bucketPolicy policy.BucketAccessPolicy) error {
|
||||
return c.putBucketPolicy(bucket, bucketPolicy)
|
||||
}
|
||||
|
||||
// GetObject is a lower level API implemented to support reading
|
||||
// partial objects and also downloading objects with special conditions
|
||||
// matching etag, modtime etc.
|
||||
func (c Core) GetObject(bucketName, objectName string, reqHeaders RequestHeaders) (io.ReadCloser, ObjectInfo, error) {
|
||||
return c.getObject(bucketName, objectName, reqHeaders)
|
||||
}
|
||||
|
||||
// StatObject is a lower level API implemented to support special
|
||||
// conditions matching etag, modtime on a request.
|
||||
func (c Core) StatObject(bucketName, objectName string, reqHeaders RequestHeaders) (ObjectInfo, error) {
|
||||
return c.statObject(bucketName, objectName, reqHeaders)
|
||||
}
|
||||
|
BIN
vendor/github.com/minio/minio-go/my-testfile
generated
vendored
Normal file
BIN
vendor/github.com/minio/minio-go/my-testfile
generated
vendored
Normal file
Binary file not shown.
105
vendor/github.com/minio/minio-go/request-headers.go
generated
vendored
Normal file
105
vendor/github.com/minio/minio-go/request-headers.go
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2016 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package minio
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RequestHeaders - implement methods for setting special
|
||||
// request headers for GET, HEAD object operations.
|
||||
// http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html
|
||||
type RequestHeaders struct {
|
||||
http.Header
|
||||
}
|
||||
|
||||
// NewGetReqHeaders - initializes a new request headers for GET request.
|
||||
func NewGetReqHeaders() RequestHeaders {
|
||||
return RequestHeaders{
|
||||
Header: make(http.Header),
|
||||
}
|
||||
}
|
||||
|
||||
// NewHeadReqHeaders - initializes a new request headers for HEAD request.
|
||||
func NewHeadReqHeaders() RequestHeaders {
|
||||
return RequestHeaders{
|
||||
Header: make(http.Header),
|
||||
}
|
||||
}
|
||||
|
||||
// SetMatchETag - set match etag.
|
||||
func (c RequestHeaders) SetMatchETag(etag string) error {
|
||||
if etag == "" {
|
||||
return ErrInvalidArgument("ETag cannot be empty.")
|
||||
}
|
||||
c.Set("If-Match", etag)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetMatchETagExcept - set match etag except.
|
||||
func (c RequestHeaders) SetMatchETagExcept(etag string) error {
|
||||
if etag == "" {
|
||||
return ErrInvalidArgument("ETag cannot be empty.")
|
||||
}
|
||||
c.Set("If-None-Match", etag)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUnmodified - set unmodified time since.
|
||||
func (c RequestHeaders) SetUnmodified(modTime time.Time) error {
|
||||
if modTime.IsZero() {
|
||||
return ErrInvalidArgument("Modified since cannot be empty.")
|
||||
}
|
||||
c.Set("If-Unmodified-Since", modTime.Format(http.TimeFormat))
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetModified - set modified time since.
|
||||
func (c RequestHeaders) SetModified(modTime time.Time) error {
|
||||
if modTime.IsZero() {
|
||||
return ErrInvalidArgument("Modified since cannot be empty.")
|
||||
}
|
||||
c.Set("If-Modified-Since", modTime.Format(http.TimeFormat))
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetRange - set the start and end offset of the object to be read.
|
||||
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference.
|
||||
func (c RequestHeaders) SetRange(start, end int64) error {
|
||||
switch {
|
||||
case start <= 0 && end < 0:
|
||||
// Read everything until the 'end'. `bytes=-N`
|
||||
c.Set("Range", fmt.Sprintf("bytes=%d", end))
|
||||
case start > 0 && end == 0:
|
||||
// Read everything starting from offset 'start'. `bytes=N-`
|
||||
c.Set("Range", fmt.Sprintf("bytes=%d-", start))
|
||||
case start > 0 && end > 0 && end >= start:
|
||||
// Read everything starting at 'start' till the 'end'. `bytes=N-M`
|
||||
c.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end))
|
||||
case start == 0 && end == 0:
|
||||
// Client attempting to read the whole file.
|
||||
return nil
|
||||
}
|
||||
// All other cases such as
|
||||
// bytes=-N-
|
||||
// bytes=N-M where M < N
|
||||
// These return error and are not supported.
|
||||
return ErrInvalidArgument(fmt.Sprintf("Invalid range start and end specified bytes=%d-%d",
|
||||
start, end))
|
||||
}
|
2
vendor/github.com/minio/minio-go/signature-type.go
generated
vendored
2
vendor/github.com/minio/minio-go/signature-type.go
generated
vendored
@ -27,6 +27,8 @@ const (
|
||||
SignatureV4Streaming
|
||||
)
|
||||
|
||||
var emptySHA256 = sum256(nil)
|
||||
|
||||
// isV2 - is signature SignatureV2?
|
||||
func (s SignatureType) isV2() bool {
|
||||
return s == SignatureV2
|
||||
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@ -216,10 +216,10 @@
|
||||
"revisionTime": "2016-02-29T08:42:30-08:00"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "rtVzxCyARW7zRG1jUf3K7o9vyt0=",
|
||||
"checksumSHA1": "E0n14tprPsyG3s4MXxZmLrcaNm4=",
|
||||
"path": "github.com/minio/minio-go",
|
||||
"revision": "5297a818b482fa329b3dc1a3926e3c4c6fb5d459",
|
||||
"revisionTime": "2017-04-26T18:23:05Z"
|
||||
"revision": "fe31943bd4638093653a6a584dc1c6c6487e06c9",
|
||||
"revisionTime": "2017-05-02T08:16:08Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "lsxCcRcNUDxhQyO999SOdvKzzfM=",
|
||||
|
Loading…
x
Reference in New Issue
Block a user