Skip to content

Commit 8169ce8

Browse files
committed
Merge pull request #37 from github/newbatchapi
Support new batch API
2 parents 31dbd5b + b39a365 commit 8169ce8

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

harbour_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestGetMetaAuthed(t *testing.T) {
8585
t.Fatalf("expected to see a size of `%d`, got: `%d`", contentSize, meta.Size)
8686
}
8787

88-
download := meta.Links["download"]
88+
download := meta.Actions["download"]
8989
if download.Href != "http://localhost:8080/bilbo/repo/objects/"+contentOid {
9090
t.Fatalf("expected download link, got %s", download.Href)
9191
}
@@ -140,11 +140,11 @@ func TestPostAuthedNewObject(t *testing.T) {
140140
t.Fatalf("expected to see a size of `1234`, got: `%d`", meta.Size)
141141
}
142142

143-
if download, ok := meta.Links["download"]; ok {
143+
if download, ok := meta.Actions["download"]; ok {
144144
t.Fatalf("expected POST to not contain a download link, got %s", download.Href)
145145
}
146146

147-
upload, ok := meta.Links["upload"]
147+
upload, ok := meta.Actions["upload"]
148148
if !ok {
149149
t.Fatal("expected upload link to be present")
150150
}
@@ -186,12 +186,12 @@ func TestPostAuthedExistingObject(t *testing.T) {
186186
t.Fatalf("expected to see a size of `%d`, got: `%d`", contentSize, meta.Size)
187187
}
188188

189-
download := meta.Links["download"]
189+
download := meta.Actions["download"]
190190
if download.Href != "http://localhost:8080/bilbo/repo/objects/"+contentOid {
191191
t.Fatalf("expected download link, got %s", download.Href)
192192
}
193193

194-
upload, ok := meta.Links["upload"]
194+
upload, ok := meta.Actions["upload"]
195195
if !ok {
196196
t.Fatalf("expected upload link to be present")
197197
}

server.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"net/http"
1010
"strings"
11+
"time"
1112

1213
"github.com/gorilla/context"
1314
"github.com/gorilla/mux"
@@ -25,7 +26,8 @@ type RequestVars struct {
2526
}
2627

2728
type BatchVars struct {
28-
Objects []*RequestVars `json:"objects"`
29+
Operation string `json:"operation"`
30+
Objects []*RequestVars `json:"objects"`
2931
}
3032

3133
// MetaObject is object metadata as seen by the object and metadata stores.
@@ -37,9 +39,15 @@ type MetaObject struct {
3739

3840
// Representation is object medata as seen by clients of the lfs server.
3941
type Representation struct {
40-
Oid string `json:"oid"`
41-
Size int64 `json:"size"`
42-
Links map[string]*link `json:"_links"`
42+
Oid string `json:"oid"`
43+
Size int64 `json:"size"`
44+
Actions map[string]*link `json:"actions"`
45+
Error *ObjectError `json:"error,omitempty"`
46+
}
47+
48+
type ObjectError struct {
49+
Code int `json:"code"`
50+
Message string `json:"message"`
4351
}
4452

4553
// ObjectLink builds a URL linking to the object.
@@ -55,8 +63,9 @@ func (v *RequestVars) ObjectLink() string {
5563

5664
// link provides a structure used to build a hypermedia representation of an HTTP link.
5765
type link struct {
58-
Href string `json:"href"`
59-
Header map[string]string `json:"header,omitempty"`
66+
Href string `json:"href"`
67+
Header map[string]string `json:"header,omitempty"`
68+
ExpiresAt time.Time `json:"expires_at,omitempty"`
6069
}
6170

6271
// App links a Router, ContentStore, and MetaStore to provide the LFS server.
@@ -239,9 +248,9 @@ func (a *App) PutHandler(w http.ResponseWriter, r *http.Request) {
239248
// for json encoding
240249
func (a *App) Represent(rv *RequestVars, meta *MetaObject, download, upload bool) *Representation {
241250
rep := &Representation{
242-
Oid: meta.Oid,
243-
Size: meta.Size,
244-
Links: make(map[string]*link),
251+
Oid: meta.Oid,
252+
Size: meta.Size,
253+
Actions: make(map[string]*link),
245254
}
246255

247256
header := make(map[string]string)
@@ -250,11 +259,11 @@ func (a *App) Represent(rv *RequestVars, meta *MetaObject, download, upload bool
250259
header["Authorization"] = rv.Authorization
251260
}
252261
if download {
253-
rep.Links["download"] = &link{Href: rv.ObjectLink(), Header: header}
262+
rep.Actions["download"] = &link{Href: rv.ObjectLink(), Header: header}
254263
}
255264

256265
if upload {
257-
rep.Links["upload"] = &link{Href: rv.ObjectLink(), Header: header}
266+
rep.Actions["upload"] = &link{Href: rv.ObjectLink(), Header: header}
258267
}
259268
return rep
260269
}

0 commit comments

Comments
 (0)