You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. package s3api
  2. import (
  3. "net/http"
  4. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "time"
  7. "context"
  8. "fmt"
  9. )
  10. func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
  11. var response ListAllMyBucketsResponse
  12. err := s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  13. request := &filer_pb.ListEntriesRequest{
  14. Directory: "/buckets",
  15. }
  16. glog.V(4).Infof("read directory: %v", request)
  17. resp, err := client.ListEntries(context.Background(), request)
  18. if err != nil {
  19. return fmt.Errorf("list buckets: %v", err)
  20. }
  21. var buckets []ListAllMyBucketsEntry
  22. for _, entry := range resp.Entries {
  23. if entry.IsDirectory {
  24. buckets = append(buckets, ListAllMyBucketsEntry{
  25. Name: entry.Name,
  26. CreationDate: time.Unix(entry.Attributes.Crtime, 0),
  27. })
  28. }
  29. }
  30. response = ListAllMyBucketsResponse{
  31. ListAllMyBucketsResponse: ListAllMyBucketsResult{
  32. Owner: CanonicalUser{
  33. ID: "",
  34. DisplayName: "",
  35. },
  36. Buckets: ListAllMyBucketsList{
  37. Bucket: buckets,
  38. },
  39. },
  40. }
  41. return nil
  42. })
  43. if err != nil {
  44. writeErrorResponse(w, ErrInternalError, r.URL)
  45. return
  46. }
  47. writeSuccessResponseXML(w, encodeResponse(response))
  48. }