api,transfer: inject custom *config.Configuration throughout

This commit is contained in:
Taylor Blau 2016-08-10 11:33:48 -06:00
parent 075fc1ec0b
commit ca28d936cb
7 changed files with 13 additions and 17 deletions

@ -66,7 +66,7 @@ func Batch(cfg *config.Configuration, objects []*ObjectResource, operation strin
return nil, "", errutil.Error(err)
}
req, err := NewBatchRequest(operation)
req, err := NewBatchRequest(cfg, operation)
if err != nil {
return nil, "", errutil.Error(err)
}
@ -78,7 +78,7 @@ func Batch(cfg *config.Configuration, objects []*ObjectResource, operation strin
tracerx.Printf("api: batch %d files", len(objects))
res, bresp, err := DoBatchRequest(req)
res, bresp, err := DoBatchRequest(cfg, req)
if err != nil {
@ -143,7 +143,7 @@ func DownloadCheck(cfg *config.Configuration, oid string) (*ObjectResource, erro
return nil, errutil.Error(err)
}
res, obj, err := DoLegacyRequest(req)
res, obj, err := DoLegacyRequest(cfg, req)
if err != nil {
return nil, err
}
@ -181,7 +181,7 @@ func UploadCheck(cfg *config.Configuration, oid string, size int64) (*ObjectReso
req.Body = tools.NewReadSeekCloserWrapper(bytes.NewReader(by))
tracerx.Printf("api: uploading (%s)", oid)
res, obj, err := DoLegacyRequest(req)
res, obj, err := DoLegacyRequest(cfg, req)
if err != nil {
if errutil.IsAuthError(err) {

@ -395,7 +395,7 @@ func TestSuccessfulUploadWithVerify(t *testing.T) {
}
t.Fatal(err)
}
api.VerifyUpload(o)
api.VerifyUpload(cfg, o)
if !postCalled {
t.Errorf("POST not called")
@ -571,7 +571,7 @@ func TestUploadVerifyError(t *testing.T) {
}
t.Fatal(err)
}
err = api.VerifyUpload(o)
err = api.VerifyUpload(cfg, o)
if err == nil {
t.Fatal("verify should fail")
}

@ -18,8 +18,7 @@ const (
)
// doLegacyApiRequest runs the request to the LFS legacy API.
func DoLegacyRequest(req *http.Request) (*http.Response, *ObjectResource, error) {
cfg := config.Config
func DoLegacyRequest(cfg *config.Configuration, req *http.Request) (*http.Response, *ObjectResource, error) {
via := make([]*http.Request, 0, 4)
res, err := httputil.DoHttpRequestWithRedirects(cfg, req, via, true)
if err != nil {
@ -51,8 +50,7 @@ type batchResponse struct {
// 401, the repo will be marked as having private access and the request will be
// re-run. When the repo is marked as having private access, credentials will
// be retrieved.
func DoBatchRequest(req *http.Request) (*http.Response, *batchResponse, error) {
cfg := config.Config
func DoBatchRequest(cfg *config.Configuration, req *http.Request) (*http.Response, *batchResponse, error) {
res, err := DoRequest(req, cfg.PrivateAccess(auth.GetOperationForRequest(req)))
if err != nil {
@ -117,8 +115,7 @@ func NewRequest(cfg *config.Configuration, method, oid string) (*http.Request, e
return req, nil
}
func NewBatchRequest(operation string) (*http.Request, error) {
cfg := config.Config
func NewBatchRequest(cfg *config.Configuration, operation string) (*http.Request, error) {
res, endpoint, err := auth.SshAuthenticate(cfg, operation, "")
if err != nil {
tracerx.Printf("ssh: %s attempted with %s. Error: %s",

@ -13,7 +13,7 @@ import (
)
// VerifyUpload calls the "verify" API link relation on obj if it exists
func VerifyUpload(obj *ObjectResource) error {
func VerifyUpload(cfg *config.Configuration, obj *ObjectResource) error {
// Do we need to do verify?
if _, ok := obj.Rel("verify"); !ok {
return nil
@ -38,7 +38,6 @@ func VerifyUpload(obj *ObjectResource) error {
return err
}
cfg := config.Config
httputil.LogTransfer(cfg, "lfs.data.verify", res)
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()

@ -116,7 +116,7 @@ func (a *basicUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb Transfe
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
return api.VerifyUpload(t.Object)
return api.VerifyUpload(config.Config, t.Object)
}
// startCallbackReader is a reader wrapper which calls a function as soon as the

@ -319,7 +319,7 @@ func (a *customAdapter) DoTransfer(ctx interface{}, t *Transfer, cb TransferProg
return fmt.Errorf("Failed to copy downloaded file: %v", err)
}
} else if a.direction == Upload {
if err = api.VerifyUpload(t.Object); err != nil {
if err = api.VerifyUpload(config.Config, t.Object); err != nil {
return err
}
}

@ -153,7 +153,7 @@ func (a *tusUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb TransferP
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
return api.VerifyUpload(t.Object)
return api.VerifyUpload(config.Config, t.Object)
}
func init() {