forked from pachyderm/pachyderm
/
root.go
59 lines (48 loc) · 1.2 KB
/
root.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package s3
import (
"fmt"
"net/http"
"time"
"github.com/gogo/protobuf/types"
"github.com/pachyderm/pachyderm/src/client"
)
// ListAllMyBucketsResult is an XML-encodable listing of repos as buckets
type ListAllMyBucketsResult struct {
Owner User `xml:"Owner"`
Buckets []Bucket `xml:"Buckets>Bucket"`
}
// Bucket is an XML-encodable repo, represented as an S3 bucket
type Bucket struct {
Name string `xml:"Name"`
CreationDate time.Time `xml:"CreationDate"`
}
type rootHandler struct {
pc *client.APIClient
}
func newRootHandler(pc *client.APIClient) rootHandler {
return rootHandler{pc: pc}
}
func (h rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
repos, err := h.pc.ListRepo()
if err != nil {
internalError(w, r, err)
return
}
result := ListAllMyBucketsResult{
Owner: defaultUser,
}
for _, repo := range repos {
t, err := types.TimestampFromProto(repo.Created)
if err != nil {
internalError(w, r, err)
return
}
for _, branch := range repo.Branches {
result.Buckets = append(result.Buckets, Bucket{
Name: fmt.Sprintf("%s.%s", branch.Name, branch.Repo.Name),
CreationDate: t,
})
}
}
writeXML(w, r, http.StatusOK, &result)
}