2017-04-27 14:26:00 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
package s3
|
2017-04-27 14:26:00 -04:00
|
|
|
|
2017-05-02 21:46:39 -04:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
miniogo "github.com/minio/minio-go"
|
2017-11-25 14:58:29 -05:00
|
|
|
"github.com/minio/minio/pkg/errors"
|
2017-10-22 01:30:34 -04:00
|
|
|
"github.com/minio/minio/pkg/hash"
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
minio "github.com/minio/minio/cmd"
|
2017-05-02 21:46:39 -04:00
|
|
|
)
|
2017-04-27 14:26:00 -04:00
|
|
|
|
2017-05-04 23:03:56 -04:00
|
|
|
// AnonPutObject creates a new object anonymously with the incoming data,
|
2017-12-05 20:58:09 -05:00
|
|
|
func (l *s3Objects) AnonPutObject(bucket string, object string, data *hash.Reader, metadata map[string]string) (objInfo minio.ObjectInfo, e error) {
|
2017-12-21 20:27:33 -05:00
|
|
|
oi, err := l.anonClient.PutObject(bucket, object, data, data.Size(), data.MD5Base64String(), data.SHA256HexString(), minio.ToMinioClientMetadata(metadata))
|
2017-05-04 23:03:56 -04:00
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return objInfo, minio.ErrorRespToObjectError(errors.Trace(err), bucket, object)
|
2017-05-04 23:03:56 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.FromMinioClientObjectInfo(bucket, oi), nil
|
2017-05-04 23:03:56 -04:00
|
|
|
}
|
|
|
|
|
2017-04-27 14:26:00 -04:00
|
|
|
// AnonGetObject - Get object anonymously
|
2017-05-15 03:52:33 -04:00
|
|
|
func (l *s3Objects) AnonGetObject(bucket string, key string, startOffset int64, length int64, writer io.Writer) error {
|
2017-12-05 20:58:09 -05:00
|
|
|
opts := miniogo.GetObjectOptions{}
|
2017-10-03 13:38:25 -04:00
|
|
|
if err := opts.SetRange(startOffset, startOffset+length-1); err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.ErrorRespToObjectError(errors.Trace(err), bucket, key)
|
2017-05-02 21:46:39 -04:00
|
|
|
}
|
2017-10-03 13:38:25 -04:00
|
|
|
object, _, err := l.anonClient.GetObject(bucket, key, opts)
|
2017-04-27 14:26:00 -04:00
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.ErrorRespToObjectError(errors.Trace(err), bucket, key)
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
defer object.Close()
|
|
|
|
|
|
|
|
if _, err := io.CopyN(writer, object, length); err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.ErrorRespToObjectError(errors.Trace(err), bucket, key)
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnonGetObjectInfo - Get object info anonymously
|
2017-12-05 20:58:09 -05:00
|
|
|
func (l *s3Objects) AnonGetObjectInfo(bucket string, object string) (objInfo minio.ObjectInfo, e error) {
|
|
|
|
oi, err := l.anonClient.StatObject(bucket, object, miniogo.StatObjectOptions{})
|
2017-04-27 14:26:00 -04:00
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return objInfo, minio.ErrorRespToObjectError(errors.Trace(err), bucket, object)
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.FromMinioClientObjectInfo(bucket, oi), nil
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// AnonListObjects - List objects anonymously
|
2017-12-05 20:58:09 -05:00
|
|
|
func (l *s3Objects) AnonListObjects(bucket string, prefix string, marker string, delimiter string, maxKeys int) (loi minio.ListObjectsInfo, e error) {
|
2017-04-27 14:26:00 -04:00
|
|
|
result, err := l.anonClient.ListObjects(bucket, prefix, marker, delimiter, maxKeys)
|
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return loi, minio.ErrorRespToObjectError(errors.Trace(err), bucket)
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.FromMinioClientListBucketResult(bucket, result), nil
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
2017-06-17 01:17:00 -04:00
|
|
|
// AnonListObjectsV2 - List objects in V2 mode, anonymously
|
2017-12-05 20:58:09 -05:00
|
|
|
func (l *s3Objects) AnonListObjectsV2(bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (loi minio.ListObjectsV2Info, e error) {
|
2017-06-17 01:17:00 -04:00
|
|
|
result, err := l.anonClient.ListObjectsV2(bucket, prefix, continuationToken, fetchOwner, delimiter, maxKeys)
|
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return loi, minio.ErrorRespToObjectError(errors.Trace(err), bucket)
|
2017-06-17 01:17:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.FromMinioClientListBucketV2Result(bucket, result), nil
|
2017-06-17 01:17:00 -04:00
|
|
|
}
|
|
|
|
|
2017-04-27 14:26:00 -04:00
|
|
|
// AnonGetBucketInfo - Get bucket metadata anonymously.
|
2017-12-05 20:58:09 -05:00
|
|
|
func (l *s3Objects) AnonGetBucketInfo(bucket string) (bi minio.BucketInfo, e error) {
|
2017-04-27 14:26:00 -04:00
|
|
|
if exists, err := l.anonClient.BucketExists(bucket); err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return bi, minio.ErrorRespToObjectError(errors.Trace(err), bucket)
|
2017-04-27 14:26:00 -04:00
|
|
|
} else if !exists {
|
2017-12-05 20:58:09 -05:00
|
|
|
return bi, errors.Trace(minio.BucketNotFound{Bucket: bucket})
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
buckets, err := l.anonClient.ListBuckets()
|
|
|
|
if err != nil {
|
2017-12-05 20:58:09 -05:00
|
|
|
return bi, minio.ErrorRespToObjectError(errors.Trace(err), bucket)
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, bi := range buckets {
|
|
|
|
if bi.Name != bucket {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.BucketInfo{
|
2017-04-27 14:26:00 -04:00
|
|
|
Name: bi.Name,
|
|
|
|
Created: bi.CreationDate,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return bi, errors.Trace(minio.BucketNotFound{Bucket: bucket})
|
2017-04-27 14:26:00 -04:00
|
|
|
}
|