From 3339325334b37f86fb7d7b16a85c2f3ab6f89aca Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 2 Jan 2019 11:36:29 -0800 Subject: [PATCH] fix s3 ListAllMyBucketsResult to work with s3cmd --- weed/s3api/s3api_bucket_handlers.go | 34 ++++++++++++++++------------- weed/s3api/s3api_handlers.go | 1 + weed/s3api/s3api_xsd_generated.go | 5 ----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index df9abd451..1d319e354 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -3,10 +3,13 @@ package s3api import ( "context" "fmt" + "math" "net/http" "os" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/s3" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/gorilla/mux" @@ -17,37 +20,38 @@ var ( OS_GID = uint32(os.Getgid()) ) +type ListAllMyBucketsResult struct { + Buckets []*s3.Bucket `xml:"Buckets>Bucket"` + Owner *s3.Owner +} + func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Request) { - var response ListAllMyBucketsResponse + var response ListAllMyBucketsResult - entries, err := s3a.list(s3a.option.BucketsPath, "", "", false, 0) + entries, err := s3a.list(s3a.option.BucketsPath, "", "", false, math.MaxInt32) if err != nil { writeErrorResponse(w, ErrInternalError, r.URL) return } - var buckets []ListAllMyBucketsEntry + var buckets []*s3.Bucket for _, entry := range entries { if entry.IsDirectory { - buckets = append(buckets, ListAllMyBucketsEntry{ - Name: entry.Name, - CreationDate: time.Unix(entry.Attributes.Crtime, 0), + buckets = append(buckets, &s3.Bucket{ + Name: aws.String(entry.Name), + CreationDate: aws.Time(time.Unix(entry.Attributes.Crtime, 0)), }) } } - response = ListAllMyBucketsResponse{ - ListAllMyBucketsResponse: ListAllMyBucketsResult{ - Owner: CanonicalUser{ - ID: "", - DisplayName: "", - }, - Buckets: ListAllMyBucketsList{ - Bucket: buckets, - }, + response = ListAllMyBucketsResult{ + Owner: &s3.Owner{ + ID: aws.String(""), + DisplayName: aws.String(""), }, + Buckets: buckets, } writeSuccessResponseXML(w, encodeResponse(response)) diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.go index 281fc9000..286398310 100644 --- a/weed/s3api/s3api_handlers.go +++ b/weed/s3api/s3api_handlers.go @@ -77,6 +77,7 @@ func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType } w.WriteHeader(statusCode) if response != nil { + glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response)) w.Write(response) w.(http.Flusher).Flush() } diff --git a/weed/s3api/s3api_xsd_generated.go b/weed/s3api/s3api_xsd_generated.go index 915b74ec4..df07f3fea 100644 --- a/weed/s3api/s3api_xsd_generated.go +++ b/weed/s3api/s3api_xsd_generated.go @@ -539,11 +539,6 @@ type ListAllMyBucketsResponse struct { ListAllMyBucketsResponse ListAllMyBucketsResult `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResponse"` } -type ListAllMyBucketsResult struct { - Owner CanonicalUser `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Owner"` - Buckets ListAllMyBucketsList `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Buckets"` -} - type ListBucket struct { Bucket string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Bucket"` Prefix string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Prefix,omitempty"`