Merge pull request #710 from harshavardhana/pr_out_update_to_new_changes_in_minio_go_library_and_make_related_modifications_in_mc
Update to new changes in minio-go library and make related modifications in mc
This commit is contained in:
Generated
+1
-1
@@ -32,7 +32,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio-go",
|
||||
"Rev": "388953f651449b2f1dd6d5b489ff2e6afbe7b901"
|
||||
"Rev": "b09ed5ab53f445d9dcee76b24154f075e9468cbb"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio/pkg/iodine",
|
||||
|
||||
-5
@@ -1,8 +1,3 @@
|
||||
### Setup your minio-go Github Repository
|
||||
Fork [minio-go upstream](https://github.com/minio/minio-go/fork) source repository to your own personal repository.
|
||||
```sh
|
||||
$ godep get https://github.com/$USER_ID/minio-go
|
||||
```
|
||||
|
||||
### Developer Guidelines
|
||||
|
||||
|
||||
+6
-8
@@ -1,21 +1,19 @@
|
||||
# Minimal object storage library in Go
|
||||
|
||||
[](https://travis-ci.org/minio/minio-go)
|
||||
# Minimal object storage library in Go [](https://travis-ci.org/minio/minio-go)
|
||||
|
||||
## Install
|
||||
|
||||
```go
|
||||
# go get github.com/minio/minio-go
|
||||
```sh
|
||||
$ go get github.com/minio/minio-go
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
[Minimal object storage library in Go](http://godoc.org/github.com/minio/minio-go)
|
||||
Documentation for minimal object storage library http://godoc.org/github.com/minio/minio-go
|
||||
|
||||
## Join Community
|
||||
## Join The Community
|
||||
* Community hangout on Gitter [](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
* Ask questions on Quora [](http://www.quora.com/Minio)
|
||||
|
||||
## Contribute
|
||||
|
||||
[Contribute to minimal object storage library](./CONTRIBUTING.md)
|
||||
[Contributors Guide](./CONTRIBUTING.md)
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Minimal object storage library (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.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
// BucketACL - bucket level access control
|
||||
type BucketACL string
|
||||
|
||||
// different types of ACL's currently supported for buckets
|
||||
const (
|
||||
bucketPrivate = BucketACL("private")
|
||||
bucketReadOnly = BucketACL("public-read")
|
||||
bucketPublic = BucketACL("public-read-write")
|
||||
bucketAuthenticated = BucketACL("authenticated-read")
|
||||
)
|
||||
|
||||
// String printer helper
|
||||
func (b BucketACL) String() string {
|
||||
if string(b) == "" {
|
||||
return "private"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// isValidBucketACL - is provided acl string supported
|
||||
func (b BucketACL) isValidBucketACL() bool {
|
||||
switch true {
|
||||
case b.isPrivate():
|
||||
fallthrough
|
||||
case b.isReadOnly():
|
||||
fallthrough
|
||||
case b.isPublic():
|
||||
fallthrough
|
||||
case b.isAuthenticated():
|
||||
return true
|
||||
case b.String() == "private":
|
||||
// by default its "private"
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// IsPrivate - is acl Private
|
||||
func (b BucketACL) isPrivate() bool {
|
||||
return b == bucketPrivate
|
||||
}
|
||||
|
||||
// IsPublicRead - is acl PublicRead
|
||||
func (b BucketACL) isReadOnly() bool {
|
||||
return b == bucketReadOnly
|
||||
}
|
||||
|
||||
// IsPublicReadWrite - is acl PublicReadWrite
|
||||
func (b BucketACL) isPublic() bool {
|
||||
return b == bucketPublic
|
||||
}
|
||||
|
||||
// IsAuthenticated - is acl AuthenticatedRead
|
||||
func (b BucketACL) isAuthenticated() bool {
|
||||
return b == bucketAuthenticated
|
||||
}
|
||||
+144
-94
@@ -18,6 +18,7 @@ package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
@@ -34,58 +35,56 @@ type API interface {
|
||||
|
||||
// Object Read/Write/Stat operations
|
||||
ObjectAPI
|
||||
|
||||
// MultipartManagementAPI - cancel, list multiparts and active sessions
|
||||
MultipartManagementAPI
|
||||
}
|
||||
|
||||
// BucketAPI - bucket specific Read/Write/Stat interface
|
||||
type BucketAPI interface {
|
||||
MakeBucket(bucket, acl, location string) error
|
||||
SetBucketACL(bucket, acl string) error
|
||||
StatBucket(bucket string) error
|
||||
DeleteBucket(bucket string) error
|
||||
MakeBucket(bucket string, cannedACL BucketACL, location string) error
|
||||
BucketExists(bucket string) error
|
||||
RemoveBucket(bucket string) error
|
||||
SetBucketACL(bucket string, cannedACL BucketACL) error
|
||||
GetBucketACL(bucket string) (BucketACL, error)
|
||||
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectOnChannel
|
||||
ListBuckets() <-chan BucketOnChannel
|
||||
ListBuckets() <-chan BucketStatCh
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectStatCh
|
||||
|
||||
// Drop all incomplete uploads
|
||||
DropAllIncompleteUploads(bucket string) <-chan error
|
||||
}
|
||||
|
||||
// ObjectAPI - object specific Read/Write/Stat interface
|
||||
type ObjectAPI interface {
|
||||
GetObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectMetadata, error)
|
||||
GetObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectStat, error)
|
||||
PutObject(bucket, object string, size uint64, data io.Reader) error
|
||||
StatObject(bucket, object string) (*ObjectMetadata, error)
|
||||
DeleteObject(bucket, object string) error
|
||||
StatObject(bucket, object string) (*ObjectStat, error)
|
||||
RemoveObject(bucket, object string) error
|
||||
|
||||
// Drop all incomplete uploads for a given prefix
|
||||
DropIncompleteUploads(bucket, prefix string) <-chan error
|
||||
}
|
||||
|
||||
// MultipartManagementAPI - multi parts management API
|
||||
type MultipartManagementAPI interface {
|
||||
MultipartAbort(bucket, prefix string) <-chan error
|
||||
MultipartAbortAll(bucket string) <-chan error
|
||||
}
|
||||
|
||||
// BucketOnChannel - bucket metadata over read channel
|
||||
type BucketOnChannel struct {
|
||||
Data *BucketMetadata
|
||||
// BucketStatCh - bucket metadata over read channel
|
||||
type BucketStatCh struct {
|
||||
Data *BucketStat
|
||||
Err error
|
||||
}
|
||||
|
||||
// ObjectOnChannel - object metadata over read channel
|
||||
type ObjectOnChannel struct {
|
||||
Data *ObjectMetadata
|
||||
// ObjectStatCh - object metadata over read channel
|
||||
type ObjectStatCh struct {
|
||||
Data *ObjectStat
|
||||
Err error
|
||||
}
|
||||
|
||||
// BucketMetadata container for bucket metadata
|
||||
type BucketMetadata struct {
|
||||
// BucketStat container for bucket metadata
|
||||
type BucketStat struct {
|
||||
// The name of the bucket.
|
||||
Name string
|
||||
// Date the bucket was created.
|
||||
CreationDate time.Time
|
||||
}
|
||||
|
||||
// ObjectMetadata container for object metadata
|
||||
type ObjectMetadata struct {
|
||||
// ObjectStat container for object metadata
|
||||
type ObjectStat struct {
|
||||
ETag string
|
||||
Key string
|
||||
LastModified time.Time
|
||||
@@ -192,7 +191,7 @@ func New(config *Config) API {
|
||||
//
|
||||
// Additionally it also takes range arguments to download the specified range bytes of an object.
|
||||
// For more information about the HTTP Range header, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
|
||||
func (a *api) GetObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectMetadata, error) {
|
||||
func (a *api) GetObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectStat, error) {
|
||||
if strings.TrimSpace(object) == "" {
|
||||
return nil, nil, errors.New("object name cannot be empty")
|
||||
}
|
||||
@@ -278,29 +277,29 @@ func (a *api) newObjectUpload(bucket, object string, size uint64, data io.Reader
|
||||
return nil
|
||||
}
|
||||
|
||||
type partOnChannel struct {
|
||||
type partCh struct {
|
||||
Data *partMetadata
|
||||
Err error
|
||||
}
|
||||
|
||||
func (a *api) listObjectPartsRecursive(bucket, object, uploadID string) <-chan partOnChannel {
|
||||
partCh := make(chan partOnChannel)
|
||||
func (a *api) listObjectPartsRecursive(bucket, object, uploadID string) <-chan partCh {
|
||||
partCh := make(chan partCh)
|
||||
go a.listObjectPartsRecursiveInRoutine(bucket, object, uploadID, partCh)
|
||||
return partCh
|
||||
}
|
||||
|
||||
func (a *api) listObjectPartsRecursiveInRoutine(bucket, object, uploadID string, partCh chan partOnChannel) {
|
||||
defer close(partCh)
|
||||
func (a *api) listObjectPartsRecursiveInRoutine(bucket, object, uploadID string, ch chan partCh) {
|
||||
defer close(ch)
|
||||
listObjectPartsResult, err := a.listObjectParts(bucket, object, uploadID, 0, 1000)
|
||||
if err != nil {
|
||||
partCh <- partOnChannel{
|
||||
ch <- partCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, uploadedPart := range listObjectPartsResult.Part {
|
||||
partCh <- partOnChannel{
|
||||
ch <- partCh{
|
||||
Data: uploadedPart,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -311,14 +310,14 @@ func (a *api) listObjectPartsRecursiveInRoutine(bucket, object, uploadID string,
|
||||
}
|
||||
listObjectPartsResult, err = a.listObjectParts(bucket, object, uploadID, listObjectPartsResult.NextPartNumberMarker, 1000)
|
||||
if err != nil {
|
||||
partCh <- partOnChannel{
|
||||
ch <- partCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, uploadedPart := range listObjectPartsResult.Part {
|
||||
partCh <- partOnChannel{
|
||||
ch <- partCh{
|
||||
Data: uploadedPart,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -354,29 +353,29 @@ func (a *api) continueObjectUpload(bucket, object, uploadID string, size uint64,
|
||||
return nil
|
||||
}
|
||||
|
||||
type multiPartUploadOnChannel struct {
|
||||
type multiPartUploadCh struct {
|
||||
Data *upload
|
||||
Err error
|
||||
}
|
||||
|
||||
func (a *api) listMultipartUploadsRecursive(bucket, prefix string) <-chan multiPartUploadOnChannel {
|
||||
ch := make(chan multiPartUploadOnChannel)
|
||||
func (a *api) listMultipartUploadsRecursive(bucket, prefix string) <-chan multiPartUploadCh {
|
||||
ch := make(chan multiPartUploadCh)
|
||||
go a.listMultipartUploadsRecursiveInRoutine(bucket, prefix, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (a *api) listMultipartUploadsRecursiveInRoutine(bucket, prefix string, ch chan multiPartUploadOnChannel) {
|
||||
func (a *api) listMultipartUploadsRecursiveInRoutine(bucket, prefix string, ch chan multiPartUploadCh) {
|
||||
defer close(ch)
|
||||
listMultipartUploadsResult, err := a.listMultipartUploads(bucket, "", "", prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadOnChannel{
|
||||
ch <- multiPartUploadCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, upload := range listMultipartUploadsResult.Upload {
|
||||
ch <- multiPartUploadOnChannel{
|
||||
ch <- multiPartUploadCh{
|
||||
Data: upload,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -388,14 +387,14 @@ func (a *api) listMultipartUploadsRecursiveInRoutine(bucket, prefix string, ch c
|
||||
listMultipartUploadsResult, err = a.listMultipartUploads(bucket,
|
||||
listMultipartUploadsResult.NextKeyMarker, listMultipartUploadsResult.NextUploadIDMarker, prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadOnChannel{
|
||||
ch <- multiPartUploadCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, upload := range listMultipartUploadsResult.Upload {
|
||||
ch <- multiPartUploadOnChannel{
|
||||
ch <- multiPartUploadCh{
|
||||
Data: upload,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -449,8 +448,13 @@ func (a *api) PutObject(bucket, object string, size uint64, data io.Reader) erro
|
||||
return errors.New("Unexpected control flow")
|
||||
}
|
||||
|
||||
// RemoveObject deletes an object from a bucket
|
||||
func (a *api) RemoveObject(bucket, object string) error {
|
||||
return a.deleteObject(bucket, object)
|
||||
}
|
||||
|
||||
// StatObject verify if object exists and you have permission to access it
|
||||
func (a *api) StatObject(bucket, object string) (*ObjectMetadata, error) {
|
||||
func (a *api) StatObject(bucket, object string) (*ObjectStat, error) {
|
||||
if strings.TrimSpace(object) == "" {
|
||||
return nil, errors.New("object name cannot be empty")
|
||||
}
|
||||
@@ -480,61 +484,108 @@ func (a *api) DeleteObject(bucket, object string) error {
|
||||
// different ACLs and Location one can set them properly.
|
||||
//
|
||||
// ACL valid values
|
||||
// ------------------
|
||||
// private - owner gets full access [DEFAULT]
|
||||
// public-read - owner gets full access, others get read access
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// ------------------
|
||||
//
|
||||
// private - owner gets full access [default]
|
||||
// public-read - owner gets full access, all others get read access
|
||||
// public-read-write - owner gets full access, all others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
//
|
||||
// Location valid values
|
||||
// ------------------
|
||||
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
|
||||
// Default - US standard
|
||||
func (a *api) MakeBucket(bucket, acl, location string) error {
|
||||
return a.putBucket(bucket, acl, location)
|
||||
//
|
||||
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
|
||||
// Default - US standard
|
||||
func (a *api) MakeBucket(bucket string, acl BucketACL, location string) error {
|
||||
if !acl.isValidBucketACL() {
|
||||
return fmt.Errorf("%s", "Invalid bucket ACL")
|
||||
}
|
||||
if _, ok := Regions[location]; !ok {
|
||||
if location != "" {
|
||||
return fmt.Errorf("%s", "Invalid bucket Location")
|
||||
}
|
||||
}
|
||||
return a.putBucket(bucket, string(acl), location)
|
||||
}
|
||||
|
||||
// SetBucketACL set the permissions on an existing bucket using access control lists (ACL)
|
||||
//
|
||||
// Currently supported are:
|
||||
// ------------------
|
||||
// private - owner gets full access
|
||||
// public-read - owner gets full access, others get read access
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// ------------------
|
||||
func (a *api) SetBucketACL(bucket, acl string) error {
|
||||
return a.putBucketACL(bucket, acl)
|
||||
// For example
|
||||
//
|
||||
// private - owner gets full access [default]
|
||||
// public-read - owner gets full access, all others get read access
|
||||
// public-read-write - owner gets full access, all others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a *api) SetBucketACL(bucket string, acl BucketACL) error {
|
||||
if !acl.isValidBucketACL() {
|
||||
return fmt.Errorf("%s", "Invalid bucket ACL")
|
||||
}
|
||||
return a.putBucketACL(bucket, string(acl))
|
||||
}
|
||||
|
||||
// StatBucket verify if bucket exists and you have permission to access it
|
||||
func (a *api) StatBucket(bucket string) error {
|
||||
// GetBucketACL get the permissions on an existing bucket
|
||||
//
|
||||
// Returned values are:
|
||||
//
|
||||
// private - owner gets full access
|
||||
// public-read - owner gets full access, others get read access
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a *api) GetBucketACL(bucket string) (BucketACL, error) {
|
||||
policy, err := a.getBucketACL(bucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if policy.AccessControlList.Grant == nil {
|
||||
return "", fmt.Errorf("%s", "Unexpected error")
|
||||
}
|
||||
switch {
|
||||
case policy.AccessControlList.Grant.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" &&
|
||||
policy.AccessControlList.Grant.Permission == "WRITE":
|
||||
return BucketACL("public-read-write"), nil
|
||||
case policy.AccessControlList.Grant.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" &&
|
||||
policy.AccessControlList.Grant.Permission == "READ":
|
||||
return BucketACL("public-read"), nil
|
||||
case policy.AccessControlList.Grant.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" &&
|
||||
policy.AccessControlList.Grant.Permission == "READ":
|
||||
return BucketACL("authenticated-read"), nil
|
||||
case policy.AccessControlList.Grant.Grantee.URI == "" &&
|
||||
policy.AccessControlList.Grant.Permission == "FULL_CONTROL":
|
||||
return BucketACL("private"), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// BucketExists verify if bucket exists and you have permission to access it
|
||||
func (a *api) BucketExists(bucket string) error {
|
||||
return a.headBucket(bucket)
|
||||
}
|
||||
|
||||
// DeleteBucket deletes the bucket named in the URI
|
||||
// RemoveBucket deletes the bucket named in the URI
|
||||
// NOTE: -
|
||||
// All objects (including all object versions and delete markers)
|
||||
// in the bucket must be deleted before successfully attempting this request
|
||||
func (a *api) DeleteBucket(bucket string) error {
|
||||
func (a *api) RemoveBucket(bucket string) error {
|
||||
return a.deleteBucket(bucket)
|
||||
}
|
||||
|
||||
// listObjectsInRoutine is an internal goroutine function called for listing objects
|
||||
// This function feeds data into channel
|
||||
func (a *api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectOnChannel) {
|
||||
func (a *api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectStatCh) {
|
||||
defer close(ch)
|
||||
switch {
|
||||
case recursive == true:
|
||||
listBucketResult, err := a.listObjects(bucket, "", prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, object := range listBucketResult.Contents {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: object,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -545,14 +596,14 @@ func (a *api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch cha
|
||||
}
|
||||
listBucketResult, err = a.listObjects(bucket, listBucketResult.Marker, prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, object := range listBucketResult.Contents {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: object,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -562,23 +613,23 @@ func (a *api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch cha
|
||||
default:
|
||||
listBucketResult, err := a.listObjects(bucket, "", prefix, "/", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, object := range listBucketResult.Contents {
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: object,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
for _, prefix := range listBucketResult.CommonPrefixes {
|
||||
object := new(ObjectMetadata)
|
||||
object := new(ObjectStat)
|
||||
object.Key = prefix.Prefix
|
||||
object.Size = 0
|
||||
ch <- ObjectOnChannel{
|
||||
ch <- ObjectStatCh{
|
||||
Data: object,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -601,26 +652,26 @@ func (a *api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch cha
|
||||
// fmt.Println(message.Data)
|
||||
// }
|
||||
//
|
||||
func (a *api) ListObjects(bucket string, prefix string, recursive bool) <-chan ObjectOnChannel {
|
||||
ch := make(chan ObjectOnChannel)
|
||||
func (a *api) ListObjects(bucket string, prefix string, recursive bool) <-chan ObjectStatCh {
|
||||
ch := make(chan ObjectStatCh)
|
||||
go a.listObjectsInRoutine(bucket, prefix, recursive, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
// listBucketsInRoutine is an internal go routine function called for listing buckets
|
||||
// This function feeds data into channel
|
||||
func (a *api) listBucketsInRoutine(ch chan BucketOnChannel) {
|
||||
func (a *api) listBucketsInRoutine(ch chan BucketStatCh) {
|
||||
defer close(ch)
|
||||
listAllMyBucketListResults, err := a.listBuckets()
|
||||
if err != nil {
|
||||
ch <- BucketOnChannel{
|
||||
ch <- BucketStatCh{
|
||||
Data: nil,
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, bucket := range listAllMyBucketListResults.Buckets.Bucket {
|
||||
ch <- BucketOnChannel{
|
||||
ch <- BucketStatCh{
|
||||
Data: bucket,
|
||||
Err: nil,
|
||||
}
|
||||
@@ -640,13 +691,13 @@ func (a *api) listBucketsInRoutine(ch chan BucketOnChannel) {
|
||||
// fmt.Println(message.Data)
|
||||
// }
|
||||
//
|
||||
func (a *api) ListBuckets() <-chan BucketOnChannel {
|
||||
ch := make(chan BucketOnChannel)
|
||||
func (a *api) ListBuckets() <-chan BucketStatCh {
|
||||
ch := make(chan BucketStatCh)
|
||||
go a.listBucketsInRoutine(ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (a *api) multipartAbortInRoutine(bucket, prefix string, errorCh chan error) {
|
||||
func (a *api) dropIncompleteUploadsInRoutine(bucket, prefix string, errorCh chan error) {
|
||||
defer close(errorCh)
|
||||
listMultipartUploadsResult, err := a.listMultipartUploads(bucket, "", "", prefix, "", 1000)
|
||||
if err != nil {
|
||||
@@ -682,7 +733,6 @@ func (a *api) multipartAbortInRoutine(bucket, prefix string, errorCh chan error)
|
||||
errorCh <- nil
|
||||
}
|
||||
|
||||
/// MultipartManagement operations cancel and list
|
||||
//
|
||||
//
|
||||
// NOTE:
|
||||
@@ -690,14 +740,14 @@ func (a *api) multipartAbortInRoutine(bucket, prefix string, errorCh chan error)
|
||||
// requests are allowed for multipart API
|
||||
//
|
||||
|
||||
// MultipartAbort - abort a specific in progress active multipart upload, request requires uploadID
|
||||
func (a *api) MultipartAbort(bucket, prefix string) <-chan error {
|
||||
// DropIncompleteUploads - abort a specific in progress active multipart upload
|
||||
func (a *api) DropIncompleteUploads(bucket, prefix string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.multipartAbortInRoutine(bucket, prefix, errorCh)
|
||||
go a.dropIncompleteUploadsInRoutine(bucket, prefix, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
func (a *api) multipartAbortAllInRoutine(bucket string, errorCh chan error) {
|
||||
func (a *api) dropAllIncompleteUploadsInRoutine(bucket string, errorCh chan error) {
|
||||
defer close(errorCh)
|
||||
listMultipartUploadsResult, err := a.listMultipartUploads(bucket, "", "", "", "", 1000)
|
||||
if err != nil {
|
||||
@@ -733,9 +783,9 @@ func (a *api) multipartAbortAllInRoutine(bucket string, errorCh chan error) {
|
||||
errorCh <- nil
|
||||
}
|
||||
|
||||
// MultipartAbortAll - abort all inprogress active multipart uploads
|
||||
func (a *api) MultipartAbortAll(bucket string) <-chan error {
|
||||
// DropAllIncompleteUploads - abort all inprogress active multipart uploads
|
||||
func (a *api) DropAllIncompleteUploads(bucket string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.multipartAbortAllInRoutine(bucket, errorCh)
|
||||
go a.dropAllIncompleteUploadsInRoutine(bucket, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
Generated
Vendored
+9
@@ -37,6 +37,15 @@ func (h bucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
response := []byte("<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-20T23:05:09.230Z</CreationDate></Bucket></Buckets><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></ListAllMyBucketsResult>")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
||||
w.Write(response)
|
||||
case r.URL.Path == "/bucket":
|
||||
_, ok := r.URL.Query()["acl"]
|
||||
if ok {
|
||||
response := []byte("<AccessControlPolicy><Owner><ID>75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a</ID><DisplayName>CustomersName@amazon.com</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a</ID><DisplayName>CustomersName@amazon.com</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
||||
w.Write(response)
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
case r.URL.Path == "/bucket":
|
||||
response := []byte("<ListBucketResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Contents><ETag>259d04a13802ae09c7e41be50ccc6baa</ETag><Key>object</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Delimiter></Delimiter><EncodingType></EncodingType><IsTruncated>false</IsTruncated><Marker></Marker><MaxKeys>1000</MaxKeys><Name>testbucket</Name><NextMarker></NextMarker><Prefix></Prefix></ListBucketResult>")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
||||
+28
-5
@@ -34,6 +34,21 @@ func ExampleGetPartSize_second() {
|
||||
// Output: 5368709120
|
||||
}
|
||||
|
||||
func TestACLTypes(t *testing.T) {
|
||||
want := map[string]bool{
|
||||
"private": true,
|
||||
"public-read": true,
|
||||
"public-read-write": true,
|
||||
"authenticated-read": true,
|
||||
"invalid": false,
|
||||
}
|
||||
for acl, ok := range want {
|
||||
if BucketACL(acl).isValidBucketACL() != ok {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMustGetEndpoint(t *testing.T) {
|
||||
conf := new(Config)
|
||||
conf.Region = "us-east-1"
|
||||
@@ -87,12 +102,12 @@ func TestBucketOperations(t *testing.T) {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
|
||||
err = a.StatBucket("bucket")
|
||||
err = a.BucketExists("bucket")
|
||||
if err != nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
|
||||
err = a.StatBucket("bucket1")
|
||||
err = a.BucketExists("bucket1")
|
||||
if err == nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
@@ -105,6 +120,14 @@ func TestBucketOperations(t *testing.T) {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
|
||||
acl, err := a.GetBucketACL("bucket")
|
||||
if err != nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
if !acl.isPrivate() {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
for b := range a.ListBuckets() {
|
||||
if b.Err != nil {
|
||||
t.Fatalf(b.Err.Error())
|
||||
@@ -123,12 +146,12 @@ func TestBucketOperations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = a.DeleteBucket("bucket")
|
||||
err = a.RemoveBucket("bucket")
|
||||
if err != nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
|
||||
err = a.DeleteBucket("bucket1")
|
||||
err = a.RemoveBucket("bucket1")
|
||||
if err == nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
@@ -179,7 +202,7 @@ func TestObjectOperations(t *testing.T) {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
err = a.DeleteObject("bucket", "object")
|
||||
err = a.RemoveObject("bucket", "object")
|
||||
if err != nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
+89
-44
@@ -152,6 +152,45 @@ func (a *lowLevelAPI) putBucketACL(bucket, acl string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getBucketACLRequest wrapper creates a new getBucketACL request
|
||||
func (a *lowLevelAPI) getBucketRequestACL(bucket string) (*request, error) {
|
||||
op := &operation{
|
||||
HTTPServer: a.config.MustGetEndpoint(),
|
||||
HTTPMethod: "GET",
|
||||
HTTPPath: "/" + bucket + "?acl",
|
||||
}
|
||||
req, err := newRequest(op, a.config, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getBucketACL get the acl information on an existing bucket
|
||||
func (a *lowLevelAPI) getBucketACL(bucket string) (*accessControlPolicy, error) {
|
||||
req, err := a.getBucketRequestACL(bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, responseToError(resp)
|
||||
}
|
||||
}
|
||||
accessControlPolicy := new(accessControlPolicy)
|
||||
decoder := xml.NewDecoder(resp.Body)
|
||||
err = decoder.Decode(accessControlPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return accessControlPolicy, nil
|
||||
}
|
||||
|
||||
// getBucketLocationRequest wrapper creates a new getBucketLocation request
|
||||
func (a *lowLevelAPI) getBucketLocationRequest(bucket string) (*request, error) {
|
||||
op := &operation{
|
||||
@@ -366,7 +405,7 @@ func (a *lowLevelAPI) putObjectRequest(bucket, object string, size int64, body i
|
||||
// putObject - add an object to a bucket
|
||||
//
|
||||
// You must have WRITE permissions on a bucket to add an object to it.
|
||||
func (a *lowLevelAPI) putObject(bucket, object string, size int64, body io.ReadSeeker) (*ObjectMetadata, error) {
|
||||
func (a *lowLevelAPI) putObject(bucket, object string, size int64, body io.ReadSeeker) (*ObjectStat, error) {
|
||||
req, err := a.putObjectRequest(bucket, object, size, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -381,7 +420,7 @@ func (a *lowLevelAPI) putObject(bucket, object string, size int64, body io.ReadS
|
||||
return nil, responseToError(resp)
|
||||
}
|
||||
}
|
||||
metadata := new(ObjectMetadata)
|
||||
metadata := new(ObjectStat)
|
||||
metadata.ETag = strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes
|
||||
return metadata, nil
|
||||
}
|
||||
@@ -416,7 +455,7 @@ func (a *lowLevelAPI) getObjectRequest(bucket, object string, offset, length uin
|
||||
//
|
||||
// Additionally it also takes range arguments to download the specified range bytes of an object.
|
||||
// For more information about the HTTP Range header, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
|
||||
func (a *lowLevelAPI) getObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectMetadata, error) {
|
||||
func (a *lowLevelAPI) getObject(bucket, object string, offset, length uint64) (io.ReadCloser, *ObjectStat, error) {
|
||||
req, err := a.getObjectRequest(bucket, object, offset, length)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -441,17 +480,50 @@ func (a *lowLevelAPI) getObject(bucket, object string, offset, length uint64) (i
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
objectmetadata := new(ObjectMetadata)
|
||||
objectmetadata.ETag = md5sum
|
||||
objectmetadata.Key = object
|
||||
objectmetadata.Size = resp.ContentLength
|
||||
objectmetadata.LastModified = date
|
||||
objectstat := new(ObjectStat)
|
||||
objectstat.ETag = md5sum
|
||||
objectstat.Key = object
|
||||
objectstat.Size = resp.ContentLength
|
||||
objectstat.LastModified = date
|
||||
|
||||
// do not close body here, caller will close
|
||||
return resp.Body, objectmetadata, nil
|
||||
return resp.Body, objectstat, nil
|
||||
}
|
||||
|
||||
// headObjectRequest wrapper creates a new HeadObject request
|
||||
// deleteObjectRequest wrapper creates a new deleteObject request
|
||||
func (a *lowLevelAPI) deleteObjectRequest(bucket, object string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.MustGetEndpoint(),
|
||||
HTTPMethod: "DELETE",
|
||||
HTTPPath: "/" + bucket + "/" + encodedObject,
|
||||
}
|
||||
return newRequest(op, a.config, nil)
|
||||
}
|
||||
|
||||
// deleteObject deletes a given object from a bucket
|
||||
func (a *lowLevelAPI) deleteObject(bucket, object string) error {
|
||||
req, err := a.deleteObjectRequest(bucket, object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// headObjectRequest wrapper creates a new headObject request
|
||||
func (a *lowLevelAPI) headObjectRequest(bucket, object string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
@@ -466,7 +538,7 @@ func (a *lowLevelAPI) headObjectRequest(bucket, object string) (*request, error)
|
||||
}
|
||||
|
||||
// headObject - retrieves metadata from an object without returning the object itself
|
||||
func (a *lowLevelAPI) headObject(bucket, object string) (*ObjectMetadata, error) {
|
||||
func (a *lowLevelAPI) headObject(bucket, object string) (*ObjectStat, error) {
|
||||
req, err := a.headObjectRequest(bucket, object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -493,39 +565,12 @@ func (a *lowLevelAPI) headObject(bucket, object string) (*ObjectMetadata, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectmetadata := new(ObjectMetadata)
|
||||
objectmetadata.ETag = md5sum
|
||||
objectmetadata.Key = object
|
||||
objectmetadata.Size = size
|
||||
objectmetadata.LastModified = date
|
||||
return objectmetadata, nil
|
||||
}
|
||||
|
||||
// deleteObjectRequest wrapper creates a new DeleteObject request
|
||||
func (a *lowLevelAPI) deleteObjectRequest(bucket, object string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.MustGetEndpoint(),
|
||||
HTTPMethod: "DELETE",
|
||||
HTTPPath: "/" + bucket + "/" + encodedObject,
|
||||
}
|
||||
return newRequest(op, a.config, nil)
|
||||
}
|
||||
|
||||
// deleteObject removes the object
|
||||
func (a *lowLevelAPI) deleteObject(bucket, object string) error {
|
||||
req, err := a.deleteObjectRequest(bucket, object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return resp.Body.Close()
|
||||
objectstat := new(ObjectStat)
|
||||
objectstat.ETag = md5sum
|
||||
objectstat.Key = object
|
||||
objectstat.Size = size
|
||||
objectstat.LastModified = date
|
||||
return objectstat, nil
|
||||
}
|
||||
|
||||
/// Service Operations
|
||||
|
||||
+23
-3
@@ -22,7 +22,7 @@ import "time"
|
||||
type listAllMyBucketsResult struct {
|
||||
// Container for one or more buckets.
|
||||
Buckets struct {
|
||||
Bucket []*BucketMetadata
|
||||
Bucket []*BucketStat
|
||||
}
|
||||
Owner owner
|
||||
}
|
||||
@@ -40,8 +40,8 @@ type commonPrefix struct {
|
||||
|
||||
// listBucketResult container for ListObjects response
|
||||
type listBucketResult struct {
|
||||
CommonPrefixes []*commonPrefix // A response can contain CommonPrefixes only if you specify a delimiter
|
||||
Contents []*ObjectMetadata // Metadata about each object returned
|
||||
CommonPrefixes []*commonPrefix // A response can contain CommonPrefixes only if you specify a delimiter
|
||||
Contents []*ObjectStat // Metadata about each object returned
|
||||
Delimiter string
|
||||
|
||||
// Encoding type used to encode object keys in the response.
|
||||
@@ -157,3 +157,23 @@ type completeMultipartUpload struct {
|
||||
type createBucketConfiguration struct {
|
||||
Location string `xml:"LocationConstraint"`
|
||||
}
|
||||
|
||||
type grantee struct {
|
||||
ID string
|
||||
DisplayName string
|
||||
EmailAddress string
|
||||
Type string
|
||||
URI string
|
||||
}
|
||||
|
||||
type grant struct {
|
||||
Grantee grantee
|
||||
Permission string
|
||||
}
|
||||
|
||||
type accessControlPolicy struct {
|
||||
Owner owner
|
||||
AccessControlList struct {
|
||||
Grant *grant
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -37,8 +37,8 @@ type errorResponse struct {
|
||||
Code string
|
||||
Message string
|
||||
Resource string
|
||||
RequestID string
|
||||
HostID string
|
||||
RequestID string `xml:"RequestId"`
|
||||
HostID string `xml:"HostId"`
|
||||
}
|
||||
|
||||
// responseToError returns a new encoded ErrorResponse structure
|
||||
@@ -52,6 +52,22 @@ func responseToError(res *http.Response) error {
|
||||
return respError
|
||||
}
|
||||
|
||||
// GetCode get underlying error code for example: "MissingSecurityHeader"
|
||||
func (e errorResponse) GetCode() string {
|
||||
return e.Code
|
||||
}
|
||||
|
||||
// GetRequestID get request id useful in debugging
|
||||
func (e errorResponse) GetRequestID() string {
|
||||
return e.RequestID
|
||||
}
|
||||
|
||||
// XML send raw xml marshalled as string
|
||||
func (e errorResponse) XML() string {
|
||||
b, _ := xml.Marshal(&e)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Error formats HTTP error string
|
||||
func (e errorResponse) Error() string {
|
||||
return e.Message
|
||||
|
||||
+3
-3
@@ -129,7 +129,7 @@ func (c *s3Client) MakeBucket() error {
|
||||
return iodine.New(InvalidQueryURL{URL: c.hostURL.String()}, nil)
|
||||
}
|
||||
// location string is intentionally left out
|
||||
err := c.api.MakeBucket(bucket, "private", "")
|
||||
err := c.api.MakeBucket(bucket, s3.BucketACL("private"), "")
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (c *s3Client) SetBucketACL(acl string) error {
|
||||
if object != "" {
|
||||
return iodine.New(InvalidQueryURL{URL: c.hostURL.String()}, nil)
|
||||
}
|
||||
err := c.api.SetBucketACL(bucket, acl)
|
||||
err := c.api.SetBucketACL(bucket, s3.BucketACL(acl))
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (c *s3Client) Stat() (*client.Content, error) {
|
||||
objectMetadata.Type = os.FileMode(0664)
|
||||
return objectMetadata, nil
|
||||
}
|
||||
err := c.api.StatBucket(bucket)
|
||||
err := c.api.BucketExists(bucket)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user