fix s3 ListAllMyBucketsResult to work with s3cmd

This commit is contained in:
Chris Lu
2019-01-02 11:36:29 -08:00
parent 43db7ac123
commit 3339325334
3 changed files with 20 additions and 20 deletions

View File

@@ -3,10 +3,13 @@ package s3api
import ( import (
"context" "context"
"fmt" "fmt"
"math"
"net/http" "net/http"
"os" "os"
"time" "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/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@@ -17,37 +20,38 @@ var (
OS_GID = uint32(os.Getgid()) 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) { 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 { if err != nil {
writeErrorResponse(w, ErrInternalError, r.URL) writeErrorResponse(w, ErrInternalError, r.URL)
return return
} }
var buckets []ListAllMyBucketsEntry var buckets []*s3.Bucket
for _, entry := range entries { for _, entry := range entries {
if entry.IsDirectory { if entry.IsDirectory {
buckets = append(buckets, ListAllMyBucketsEntry{ buckets = append(buckets, &s3.Bucket{
Name: entry.Name, Name: aws.String(entry.Name),
CreationDate: time.Unix(entry.Attributes.Crtime, 0), CreationDate: aws.Time(time.Unix(entry.Attributes.Crtime, 0)),
}) })
} }
} }
response = ListAllMyBucketsResponse{ response = ListAllMyBucketsResult{
ListAllMyBucketsResponse: ListAllMyBucketsResult{ Owner: &s3.Owner{
Owner: CanonicalUser{ ID: aws.String(""),
ID: "", DisplayName: aws.String(""),
DisplayName: "",
},
Buckets: ListAllMyBucketsList{
Bucket: buckets,
},
}, },
Buckets: buckets,
} }
writeSuccessResponseXML(w, encodeResponse(response)) writeSuccessResponseXML(w, encodeResponse(response))

View File

@@ -77,6 +77,7 @@ func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType
} }
w.WriteHeader(statusCode) w.WriteHeader(statusCode)
if response != nil { if response != nil {
glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response))
w.Write(response) w.Write(response)
w.(http.Flusher).Flush() w.(http.Flusher).Flush()
} }

View File

@@ -539,11 +539,6 @@ type ListAllMyBucketsResponse struct {
ListAllMyBucketsResponse ListAllMyBucketsResult `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResponse"` 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 { type ListBucket struct {
Bucket string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Bucket"` 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"` Prefix string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Prefix,omitempty"`