|
|
@ -130,6 +130,9 @@ func (b byBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name } |
|
|
|
|
|
|
|
|
|
|
|
// ListBuckets returns a list of buckets
|
|
|
|
// ListBuckets returns a list of buckets
|
|
|
|
func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error) { |
|
|
|
func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error) { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return nil, iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
buckets, err := d.donut.ListBuckets() |
|
|
|
buckets, err := d.donut.ListBuckets() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -151,6 +154,9 @@ func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error) |
|
|
|
|
|
|
|
|
|
|
|
// CreateBucket creates a new bucket
|
|
|
|
// CreateBucket creates a new bucket
|
|
|
|
func (d donutDriver) CreateBucket(bucketName, acl string) error { |
|
|
|
func (d donutDriver) CreateBucket(bucketName, acl string) error { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucketACL(acl) { |
|
|
|
if !drivers.IsValidBucketACL(acl) { |
|
|
|
return iodine.New(drivers.InvalidACL{ACL: acl}, nil) |
|
|
|
return iodine.New(drivers.InvalidACL{ACL: acl}, nil) |
|
|
|
} |
|
|
|
} |
|
|
@ -172,6 +178,9 @@ func (d donutDriver) CreateBucket(bucketName, acl string) error { |
|
|
|
|
|
|
|
|
|
|
|
// GetBucketMetadata retrieves an bucket's metadata
|
|
|
|
// GetBucketMetadata retrieves an bucket's metadata
|
|
|
|
func (d donutDriver) GetBucketMetadata(bucketName string) (drivers.BucketMetadata, error) { |
|
|
|
func (d donutDriver) GetBucketMetadata(bucketName string) (drivers.BucketMetadata, error) { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return drivers.BucketMetadata{}, iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return drivers.BucketMetadata{}, drivers.BucketNameInvalid{Bucket: bucketName} |
|
|
|
return drivers.BucketMetadata{}, drivers.BucketNameInvalid{Bucket: bucketName} |
|
|
|
} |
|
|
|
} |
|
|
@ -197,8 +206,11 @@ func (d donutDriver) GetBucketMetadata(bucketName string) (drivers.BucketMetadat |
|
|
|
|
|
|
|
|
|
|
|
// SetBucketMetadata sets bucket's metadata
|
|
|
|
// SetBucketMetadata sets bucket's metadata
|
|
|
|
func (d donutDriver) SetBucketMetadata(bucketName, acl string) error { |
|
|
|
func (d donutDriver) SetBucketMetadata(bucketName, acl string) error { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return drivers.BucketNameInvalid{Bucket: bucketName} |
|
|
|
return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.TrimSpace(acl) == "" { |
|
|
|
if strings.TrimSpace(acl) == "" { |
|
|
|
acl = "private" |
|
|
|
acl = "private" |
|
|
@ -214,6 +226,9 @@ func (d donutDriver) SetBucketMetadata(bucketName, acl string) error { |
|
|
|
|
|
|
|
|
|
|
|
// GetObject retrieves an object and writes it to a writer
|
|
|
|
// GetObject retrieves an object and writes it to a writer
|
|
|
|
func (d donutDriver) GetObject(target io.Writer, bucketName, objectName string) (int64, error) { |
|
|
|
func (d donutDriver) GetObject(target io.Writer, bucketName, objectName string) (int64, error) { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return 0, iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return 0, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
return 0, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
@ -233,6 +248,9 @@ func (d donutDriver) GetObject(target io.Writer, bucketName, objectName string) |
|
|
|
|
|
|
|
|
|
|
|
// GetPartialObject retrieves an object range and writes it to a writer
|
|
|
|
// GetPartialObject retrieves an object range and writes it to a writer
|
|
|
|
func (d donutDriver) GetPartialObject(w io.Writer, bucketName, objectName string, start, length int64) (int64, error) { |
|
|
|
func (d donutDriver) GetPartialObject(w io.Writer, bucketName, objectName string, start, length int64) (int64, error) { |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return 0, iodine.New(drivers.InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
// TODO more efficient get partial object with proper donut support
|
|
|
|
// TODO more efficient get partial object with proper donut support
|
|
|
|
errParams := map[string]string{ |
|
|
|
errParams := map[string]string{ |
|
|
|
"bucketName": bucketName, |
|
|
|
"bucketName": bucketName, |
|
|
@ -283,18 +301,21 @@ func (d donutDriver) GetObjectMetadata(bucketName, objectName string) (drivers.O |
|
|
|
"bucketName": bucketName, |
|
|
|
"bucketName": bucketName, |
|
|
|
"objectName": objectName, |
|
|
|
"objectName": objectName, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.InternalError{}, errParams) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, errParams) |
|
|
|
} |
|
|
|
} |
|
|
|
if !drivers.IsValidObjectName(objectName) || strings.TrimSpace(objectName) == "" { |
|
|
|
if !drivers.IsValidObjectName(objectName) || strings.TrimSpace(objectName) == "" { |
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNameInvalid{Object: objectName}, nil) |
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNameInvalid{Object: objectName}, errParams) |
|
|
|
} |
|
|
|
} |
|
|
|
metadata, err := d.donut.GetObjectMetadata(bucketName, objectName) |
|
|
|
metadata, err := d.donut.GetObjectMetadata(bucketName, objectName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return drivers.ObjectMetadata{}, drivers.ObjectNotFound{ |
|
|
|
return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNotFound{ |
|
|
|
Bucket: bucketName, |
|
|
|
Bucket: bucketName, |
|
|
|
Object: objectName, |
|
|
|
Object: objectName, |
|
|
|
} |
|
|
|
}, errParams) |
|
|
|
} |
|
|
|
} |
|
|
|
created, err := time.Parse(time.RFC3339Nano, metadata["created"]) |
|
|
|
created, err := time.Parse(time.RFC3339Nano, metadata["created"]) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -327,6 +348,9 @@ func (d donutDriver) ListObjects(bucketName string, resources drivers.BucketReso |
|
|
|
errParams := map[string]string{ |
|
|
|
errParams := map[string]string{ |
|
|
|
"bucketName": bucketName, |
|
|
|
"bucketName": bucketName, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return nil, drivers.BucketResourcesMetadata{}, iodine.New(drivers.InternalError{}, errParams) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return nil, drivers.BucketResourcesMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
return nil, drivers.BucketResourcesMetadata{}, iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
@ -375,6 +399,9 @@ func (d donutDriver) CreateObject(bucketName, objectName, contentType, expectedM |
|
|
|
"objectName": objectName, |
|
|
|
"objectName": objectName, |
|
|
|
"contentType": contentType, |
|
|
|
"contentType": contentType, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if d.donut == nil { |
|
|
|
|
|
|
|
return "", iodine.New(drivers.InternalError{}, errParams) |
|
|
|
|
|
|
|
} |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
if !drivers.IsValidBucket(bucketName) || strings.Contains(bucketName, ".") { |
|
|
|
return "", iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
return "", iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|