forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectprovider.go
49 lines (41 loc) · 1.36 KB
/
objectprovider.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
package mocktc
import (
"net/http"
"github.com/gorilla/mux"
"github.com/taskcluster/taskcluster/v54/clients/client-go/tcobject"
"github.com/taskcluster/taskcluster/v54/internal/mocktc/tc"
)
type ObjectProvider struct {
object tc.Object
}
func NewObjectProvider(object tc.Object) *ObjectProvider {
return &ObjectProvider{
object: object,
}
}
func (op *ObjectProvider) RegisterService(r *mux.Router) {
s := r.PathPrefix("/api/object/v1").Subrouter()
s.HandleFunc("/upload/{name}", op.CreateUpload).Methods("PUT")
s.HandleFunc("/finish-upload/{name}", op.FinishUpload).Methods("POST")
s.HandleFunc("/start-download/{name}", op.StartDownload).Methods("PUT")
}
func (op *ObjectProvider) CreateUpload(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
var payload tcobject.CreateUploadRequest
Marshal(r, &payload)
out, err := op.object.CreateUpload(vars["name"], &payload)
JSON(w, out, err)
}
func (op *ObjectProvider) FinishUpload(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
var payload tcobject.FinishUploadRequest
Marshal(r, &payload)
NoBody(w, op.object.FinishUpload(vars["name"], &payload))
}
func (op *ObjectProvider) StartDownload(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
var payload tcobject.DownloadObjectRequest
Marshal(r, &payload)
out, err := op.object.StartDownload(vars["name"], &payload)
JSON(w, out, err)
}