-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_list_buckets.go
46 lines (38 loc) · 1.1 KB
/
server_list_buckets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ls3
import (
"github.com/relvacode/ls3/exception"
"github.com/relvacode/ls3/idp"
"net/http"
"time"
)
// bucketCreationDate is a constant date where all filesystemProvider were "Created".
// We don't actually know when the bucket was created, but some API consumers can't open a missing date.
var bucketCreationDate = time.Date(2022, 01, 01, 00, 00, 00, 0, time.UTC)
func (s *Server) ListBuckets(ctx *RequestContext) *exception.Error {
type Bucket struct {
CreationDate time.Time
Name string
}
type ListAllMyBucketsResult struct {
Buckets struct {
Bucket []Bucket
}
}
if err := ctx.CheckAccess(idp.ListAllMyBuckets, "", idp.NullContext{}); err != nil {
return err
}
buckets, err := s.filesystemProvider.ListBuckets()
if err != nil {
return exception.ErrorFrom(err)
}
var result ListAllMyBucketsResult
result.Buckets.Bucket = make([]Bucket, 0, len(buckets))
for _, name := range buckets {
result.Buckets.Bucket = append(result.Buckets.Bucket, Bucket{
CreationDate: bucketCreationDate,
Name: name,
})
}
ctx.SendXML(http.StatusOK, &result)
return nil
}