2016-12-16 22:03:20 +00:00
|
|
|
package lfsapi
|
|
|
|
|
2016-12-16 22:43:05 +00:00
|
|
|
import (
|
2016-12-22 22:31:48 +00:00
|
|
|
"fmt"
|
2016-12-20 17:02:25 +00:00
|
|
|
"sync"
|
2016-12-16 22:43:05 +00:00
|
|
|
|
2017-01-06 15:14:09 +00:00
|
|
|
"github.com/ThomsonReutersEikon/go-ntlm/ntlm"
|
2018-09-19 15:05:48 +00:00
|
|
|
"github.com/git-lfs/git-lfs/creds"
|
2016-12-16 22:47:02 +00:00
|
|
|
"github.com/git-lfs/git-lfs/errors"
|
2018-09-06 21:42:41 +00:00
|
|
|
"github.com/git-lfs/git-lfs/lfshttp"
|
2016-12-16 22:43:05 +00:00
|
|
|
)
|
2016-12-16 22:03:20 +00:00
|
|
|
|
|
|
|
type Client struct {
|
2016-12-19 21:38:06 +00:00
|
|
|
Endpoints EndpointFinder
|
2018-09-19 15:05:48 +00:00
|
|
|
Credentials creds.CredentialHelper
|
2016-12-20 17:02:25 +00:00
|
|
|
|
2017-01-06 15:14:09 +00:00
|
|
|
ntlmSessions map[string]ntlm.ClientSession
|
|
|
|
ntlmMu sync.Mutex
|
|
|
|
|
2018-09-19 15:05:48 +00:00
|
|
|
credContext *creds.CredentialHelperContext
|
2018-06-28 18:01:29 +00:00
|
|
|
|
2018-09-06 21:42:41 +00:00
|
|
|
client *lfshttp.Client
|
2016-12-16 22:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 21:42:41 +00:00
|
|
|
func NewClient(ctx lfshttp.Context) (*Client, error) {
|
2017-10-25 21:33:20 +00:00
|
|
|
if ctx == nil {
|
2018-09-06 21:42:41 +00:00
|
|
|
ctx = lfshttp.NewContext(nil, nil, nil)
|
2016-12-20 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 22:05:08 +00:00
|
|
|
gitEnv := ctx.GitEnv()
|
|
|
|
osEnv := ctx.OSEnv()
|
2016-12-19 22:05:35 +00:00
|
|
|
|
2018-09-06 21:42:41 +00:00
|
|
|
httpClient, err := lfshttp.NewClient(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, fmt.Sprintf("error creating http client"))
|
2017-03-24 17:37:23 +00:00
|
|
|
}
|
2017-03-23 19:48:52 +00:00
|
|
|
|
2016-12-20 17:45:22 +00:00
|
|
|
c := &Client{
|
2018-09-19 14:05:24 +00:00
|
|
|
Endpoints: NewEndpointFinder(ctx),
|
|
|
|
client: httpClient,
|
2018-09-19 15:05:48 +00:00
|
|
|
credContext: creds.NewCredentialHelperContext(gitEnv, osEnv),
|
2016-12-20 17:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
2016-12-19 22:05:35 +00:00
|
|
|
}
|