2015-10-17 22:17:33 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2015 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.
|
|
|
|
*/
|
|
|
|
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
package main
|
2015-10-17 22:17:33 -04:00
|
|
|
|
|
|
|
import (
|
2016-02-06 21:22:50 -05:00
|
|
|
"io/ioutil"
|
2015-10-17 22:17:33 -04:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/disk"
|
2016-02-10 19:40:09 -05:00
|
|
|
"github.com/minio/minio/pkg/probe"
|
2015-10-17 22:17:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
/// Bucket Operations
|
|
|
|
|
2016-02-06 04:36:43 -05:00
|
|
|
// DeleteBucket - delete a bucket.
|
2015-10-17 22:17:33 -04:00
|
|
|
func (fs Filesystem) DeleteBucket(bucket string) *probe.Error {
|
2016-02-06 04:36:43 -05:00
|
|
|
// Verify bucket is valid.
|
2015-12-07 16:39:18 -05:00
|
|
|
if !IsValidBucketName(bucket) {
|
2015-10-17 22:17:33 -04:00
|
|
|
return probe.NewError(BucketNameInvalid{Bucket: bucket})
|
|
|
|
}
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
bucket = getActualBucketname(fs.path, bucket)
|
2015-10-17 22:17:33 -04:00
|
|
|
bucketDir := filepath.Join(fs.path, bucket)
|
2016-03-07 02:54:43 -05:00
|
|
|
if e := os.Remove(bucketDir); e != nil {
|
|
|
|
// Error if there was no bucket in the first place.
|
2016-01-25 02:03:38 -05:00
|
|
|
if os.IsNotExist(e) {
|
2015-11-01 23:56:54 -05:00
|
|
|
return probe.NewError(BucketNotFound{Bucket: bucket})
|
|
|
|
}
|
2016-01-25 20:57:19 -05:00
|
|
|
// On windows the string is slightly different, handle it here.
|
|
|
|
if strings.Contains(e.Error(), "directory is not empty") {
|
|
|
|
return probe.NewError(BucketNotEmpty{Bucket: bucket})
|
|
|
|
}
|
|
|
|
// Hopefully for all other operating systems, this is
|
|
|
|
// assumed to be consistent.
|
2016-01-25 02:03:38 -05:00
|
|
|
if strings.Contains(e.Error(), "directory not empty") {
|
2015-10-17 22:17:33 -04:00
|
|
|
return probe.NewError(BucketNotEmpty{Bucket: bucket})
|
|
|
|
}
|
2016-01-25 02:03:38 -05:00
|
|
|
return probe.NewError(e)
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-04 23:40:58 -05:00
|
|
|
// ListBuckets - Get service.
|
2016-03-11 19:31:24 -05:00
|
|
|
func (fs Filesystem) ListBuckets() ([]BucketInfo, *probe.Error) {
|
2016-02-06 21:22:50 -05:00
|
|
|
files, e := ioutil.ReadDir(fs.path)
|
|
|
|
if e != nil {
|
2016-03-11 19:31:24 -05:00
|
|
|
return []BucketInfo{}, probe.NewError(e)
|
2016-01-25 02:03:38 -05:00
|
|
|
}
|
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
|
|
|
var buckets []BucketInfo
|
2015-10-17 22:17:33 -04:00
|
|
|
for _, file := range files {
|
|
|
|
if !file.IsDir() {
|
2016-02-06 04:36:43 -05:00
|
|
|
// If not directory, ignore all file types.
|
2015-10-17 22:17:33 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-02-06 04:36:43 -05:00
|
|
|
// If directories are found with odd names, skip them.
|
2016-01-25 02:03:38 -05:00
|
|
|
dirName := strings.ToLower(file.Name())
|
2016-03-07 22:02:36 -05:00
|
|
|
if !IsValidBucketName(dirName) {
|
2016-02-06 04:36:43 -05:00
|
|
|
continue
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
|
|
|
bucket := BucketInfo{
|
2016-01-25 02:03:38 -05:00
|
|
|
Name: dirName,
|
2015-10-17 22:17:33 -04:00
|
|
|
Created: file.ModTime(),
|
|
|
|
}
|
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
|
|
|
buckets = append(buckets, bucket)
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
2016-02-04 23:40:58 -05:00
|
|
|
// Remove duplicated entries.
|
objectAPI: Fix object API interface, remove unnecessary structs.
ObjectAPI changes.
```
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, *probe.Error)
ListMultipartUploads(bucket, objectPrefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, *probe.Error)
ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (ObjectInfo, *probe.Error)
```
2016-04-03 04:34:20 -04:00
|
|
|
buckets = removeDuplicateBuckets(buckets)
|
|
|
|
return buckets, nil
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
|
|
|
|
2016-02-04 23:40:58 -05:00
|
|
|
// removeDuplicateBuckets - remove duplicate buckets.
|
2016-03-11 19:31:24 -05:00
|
|
|
func removeDuplicateBuckets(buckets []BucketInfo) []BucketInfo {
|
2016-02-19 19:04:29 -05:00
|
|
|
length := len(buckets) - 1
|
|
|
|
for i := 0; i < length; i++ {
|
|
|
|
for j := i + 1; j <= length; j++ {
|
|
|
|
if buckets[i].Name == buckets[j].Name {
|
|
|
|
if buckets[i].Created.Sub(buckets[j].Created) > 0 {
|
|
|
|
buckets[i] = buckets[length]
|
|
|
|
} else {
|
|
|
|
buckets[j] = buckets[length]
|
|
|
|
}
|
|
|
|
buckets = buckets[0:length]
|
|
|
|
length--
|
|
|
|
j--
|
|
|
|
}
|
2016-02-04 23:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
2016-02-19 19:04:29 -05:00
|
|
|
return buckets
|
2016-02-04 23:40:58 -05:00
|
|
|
}
|
|
|
|
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-03 19:46:56 -05:00
|
|
|
// MakeBucket - PUT Bucket
|
|
|
|
func (fs Filesystem) MakeBucket(bucket string) *probe.Error {
|
2016-01-25 02:03:38 -05:00
|
|
|
di, err := disk.GetInfo(fs.path)
|
2015-10-17 22:17:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return probe.NewError(err)
|
|
|
|
}
|
|
|
|
|
2016-02-04 23:40:58 -05:00
|
|
|
// Remove 5% from total space for cumulative disk space used for
|
|
|
|
// journalling, inodes etc.
|
2016-01-25 02:03:38 -05:00
|
|
|
availableDiskSpace := (float64(di.Free) / (float64(di.Total) - (0.05 * float64(di.Total)))) * 100
|
2015-10-19 13:29:54 -04:00
|
|
|
if int64(availableDiskSpace) <= fs.minFreeDisk {
|
2015-10-17 22:17:33 -04:00
|
|
|
return probe.NewError(RootPathFull{Path: fs.path})
|
|
|
|
}
|
|
|
|
|
2016-02-06 04:36:43 -05:00
|
|
|
// Verify if bucket is valid.
|
2015-12-07 16:39:18 -05:00
|
|
|
if !IsValidBucketName(bucket) {
|
2015-10-17 22:17:33 -04:00
|
|
|
return probe.NewError(BucketNameInvalid{Bucket: bucket})
|
|
|
|
}
|
|
|
|
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
bucket = getActualBucketname(fs.path, bucket)
|
2015-10-17 22:17:33 -04:00
|
|
|
bucketDir := filepath.Join(fs.path, bucket)
|
2016-01-25 02:03:38 -05:00
|
|
|
if _, e := os.Stat(bucketDir); e == nil {
|
|
|
|
return probe.NewError(BucketExists{Bucket: bucket})
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
|
|
|
|
2016-02-04 23:40:58 -05:00
|
|
|
// Make bucket.
|
2016-01-25 02:03:38 -05:00
|
|
|
if e := os.Mkdir(bucketDir, 0700); e != nil {
|
2015-10-17 22:17:33 -04:00
|
|
|
return probe.NewError(err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
// getActualBucketname - will convert incoming bucket names to
|
|
|
|
// corresponding actual bucketnames on the backend in a platform
|
2016-02-04 23:40:58 -05:00
|
|
|
// compatible way for all operating systems.
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
func getActualBucketname(fsPath, bucket string) string {
|
|
|
|
fd, e := os.Open(fsPath)
|
|
|
|
if e != nil {
|
|
|
|
return bucket
|
|
|
|
}
|
|
|
|
buckets, e := fd.Readdirnames(-1)
|
2016-02-04 23:40:58 -05:00
|
|
|
if e != nil {
|
2016-01-25 02:03:38 -05:00
|
|
|
return bucket
|
|
|
|
}
|
|
|
|
for _, b := range buckets {
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
// Verify if lowercase version of the bucket is equal
|
|
|
|
// to the incoming bucket, then use the proper name.
|
|
|
|
if strings.ToLower(b) == bucket {
|
|
|
|
return b
|
2016-01-25 02:03:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bucket
|
|
|
|
}
|
|
|
|
|
2016-03-11 19:31:24 -05:00
|
|
|
// GetBucketInfo - get bucket metadata.
|
|
|
|
func (fs Filesystem) GetBucketInfo(bucket string) (BucketInfo, *probe.Error) {
|
2015-12-07 16:39:18 -05:00
|
|
|
if !IsValidBucketName(bucket) {
|
2016-03-11 19:31:24 -05:00
|
|
|
return BucketInfo{}, probe.NewError(BucketNameInvalid{Bucket: bucket})
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
bucket = getActualBucketname(fs.path, bucket)
|
2016-02-04 23:40:58 -05:00
|
|
|
// Get bucket path.
|
2015-10-17 22:17:33 -04:00
|
|
|
bucketDir := filepath.Join(fs.path, bucket)
|
2016-01-25 02:03:38 -05:00
|
|
|
fi, e := os.Stat(bucketDir)
|
|
|
|
if e != nil {
|
2016-02-04 23:40:58 -05:00
|
|
|
// Check if bucket exists.
|
2016-01-25 02:03:38 -05:00
|
|
|
if os.IsNotExist(e) {
|
2016-03-11 19:31:24 -05:00
|
|
|
return BucketInfo{}, probe.NewError(BucketNotFound{Bucket: bucket})
|
2015-11-01 23:56:54 -05:00
|
|
|
}
|
2016-03-11 19:31:24 -05:00
|
|
|
return BucketInfo{}, probe.NewError(e)
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|
2016-03-11 19:31:24 -05:00
|
|
|
bucketMetadata := BucketInfo{}
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-03 19:46:56 -05:00
|
|
|
bucketMetadata.Name = fi.Name()
|
|
|
|
bucketMetadata.Created = fi.ModTime()
|
|
|
|
return bucketMetadata, nil
|
2015-10-17 22:17:33 -04:00
|
|
|
}
|