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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2017-05-02 21:46:39 -04:00
|
|
|
import (
|
2017-05-04 23:03:56 -04:00
|
|
|
"encoding/hex"
|
2017-05-02 21:46:39 -04:00
|
|
|
"io"
|
|
|
|
|
|
|
|
minio "github.com/minio/minio-go"
|
|
|
|
)
|
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-05-15 03:52:33 -04:00
|
|
|
func (l *s3Objects) AnonPutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string, sha256sum string) (ObjectInfo, error) {
|
2017-05-04 23:03:56 -04:00
|
|
|
var sha256sumBytes []byte
|
|
|
|
|
|
|
|
var err error
|
|
|
|
if sha256sum != "" {
|
|
|
|
sha256sumBytes, err = hex.DecodeString(sha256sum)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var md5sumBytes []byte
|
2017-05-14 15:05:51 -04:00
|
|
|
md5sum := metadata["etag"]
|
2017-05-04 23:03:56 -04:00
|
|
|
if md5sum != "" {
|
|
|
|
md5sumBytes, err = hex.DecodeString(md5sum)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
|
|
|
}
|
2017-05-14 15:05:51 -04:00
|
|
|
delete(metadata, "etag")
|
2017-05-04 23:03:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
oi, err := l.anonClient.PutObject(bucket, object, size, data, md5sumBytes, sha256sumBytes, toMinioClientMetadata(metadata))
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromMinioClientObjectInfo(bucket, oi), nil
|
|
|
|
}
|
|
|
|
|
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-05-02 21:46:39 -04:00
|
|
|
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)
|
2017-04-27 14:26:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return s3ToObjectError(traceError(err), bucket, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer object.Close()
|
|
|
|
|
|
|
|
if _, err := io.CopyN(writer, object, length); err != nil {
|
|
|
|
return s3ToObjectError(traceError(err), bucket, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnonGetObjectInfo - Get object info anonymously
|
2017-05-15 03:52:33 -04:00
|
|
|
func (l *s3Objects) AnonGetObjectInfo(bucket string, object string) (ObjectInfo, error) {
|
2017-05-02 21:46:39 -04:00
|
|
|
r := minio.NewHeadReqHeaders()
|
|
|
|
oi, err := l.anonClient.StatObject(bucket, object, r)
|
2017-04-27 14:26:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, s3ToObjectError(traceError(err), bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromMinioClientObjectInfo(bucket, oi), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnonListObjects - List objects anonymously
|
2017-05-15 03:52:33 -04:00
|
|
|
func (l *s3Objects) AnonListObjects(bucket string, prefix string, marker string, delimiter string, maxKeys int) (ListObjectsInfo, error) {
|
2017-04-27 14:26:00 -04:00
|
|
|
result, err := l.anonClient.ListObjects(bucket, prefix, marker, delimiter, maxKeys)
|
|
|
|
if err != nil {
|
|
|
|
return ListObjectsInfo{}, s3ToObjectError(traceError(err), bucket)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromMinioClientListBucketResult(bucket, result), nil
|
|
|
|
}
|
|
|
|
|
2017-06-17 01:17:00 -04:00
|
|
|
// AnonListObjectsV2 - List objects in V2 mode, anonymously
|
|
|
|
func (l *s3Objects) AnonListObjectsV2(bucket, prefix, continuationToken string, fetchOwner bool, delimiter string, maxKeys int) (ListObjectsV2Info, error) {
|
|
|
|
result, err := l.anonClient.ListObjectsV2(bucket, prefix, continuationToken, fetchOwner, delimiter, maxKeys)
|
|
|
|
if err != nil {
|
|
|
|
return ListObjectsV2Info{}, s3ToObjectError(traceError(err), bucket)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromMinioClientListBucketV2Result(bucket, result), nil
|
|
|
|
}
|
|
|
|
|
2017-04-27 14:26:00 -04:00
|
|
|
// AnonGetBucketInfo - Get bucket metadata anonymously.
|
2017-05-15 03:52:33 -04:00
|
|
|
func (l *s3Objects) AnonGetBucketInfo(bucket string) (BucketInfo, error) {
|
2017-04-27 14:26:00 -04:00
|
|
|
if exists, err := l.anonClient.BucketExists(bucket); err != nil {
|
|
|
|
return BucketInfo{}, s3ToObjectError(traceError(err), bucket)
|
|
|
|
} else if !exists {
|
|
|
|
return BucketInfo{}, traceError(BucketNotFound{Bucket: bucket})
|
|
|
|
}
|
|
|
|
|
|
|
|
buckets, err := l.anonClient.ListBuckets()
|
|
|
|
if err != nil {
|
|
|
|
return BucketInfo{}, s3ToObjectError(traceError(err), bucket)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, bi := range buckets {
|
|
|
|
if bi.Name != bucket {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return BucketInfo{
|
|
|
|
Name: bi.Name,
|
|
|
|
Created: bi.CreationDate,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return BucketInfo{}, traceError(BucketNotFound{Bucket: bucket})
|
|
|
|
}
|