git-lfs/lfsapi/lfsapi.go
Preben Ingvaldsen 1026ff073c creds: Add new NetrcCredentialHelper
This commit adds a new credential helper, NetrcCredentialHelper,
to retrieve credentials from a .netrc file. This replaces the
old .netrc authorization behaviour, which was done directly from
the `doWithAuth()` code.

Additionally, this commit moves all of the `.netrc` functionality
out of `lfsapi` and into `creds`. This was done both because
`creds` is now the logical place for the `.netrc` functionality,
and to prevent an import cycle between `creds` and `lfsapi`.
2018-10-08 16:18:06 -07:00

46 lines
899 B
Go

package lfsapi
import (
"fmt"
"sync"
"github.com/ThomsonReutersEikon/go-ntlm/ntlm"
"github.com/git-lfs/git-lfs/creds"
"github.com/git-lfs/git-lfs/errors"
"github.com/git-lfs/git-lfs/lfshttp"
)
type Client struct {
Endpoints EndpointFinder
Credentials creds.CredentialHelper
ntlmSessions map[string]ntlm.ClientSession
ntlmMu sync.Mutex
credContext *creds.CredentialHelperContext
client *lfshttp.Client
}
func NewClient(ctx lfshttp.Context) (*Client, error) {
if ctx == nil {
ctx = lfshttp.NewContext(nil, nil, nil)
}
gitEnv := ctx.GitEnv()
osEnv := ctx.OSEnv()
httpClient, err := lfshttp.NewClient(ctx)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("error creating http client"))
}
c := &Client{
Endpoints: NewEndpointFinder(ctx),
client: httpClient,
credContext: creds.NewCredentialHelperContext(gitEnv, osEnv),
}
return c, nil
}