Rename credentials package to auth to reflect more general nature

This commit is contained in:
Steve Streeting 2016-05-16 15:29:44 +01:00
parent 7858714b29
commit 8b096333d3
8 changed files with 29 additions and 29 deletions

@ -1,4 +1,4 @@
package credentials
package auth
import (
"bytes"

@ -1,4 +1,4 @@
package credentials
package auth
import (
"encoding/base64"

@ -1,4 +1,4 @@
package credentials
package auth
import (
"bytes"

@ -1,4 +1,4 @@
package credentials
package auth
import (
"path/filepath"

@ -16,8 +16,8 @@ import (
"strings"
"github.com/github/git-lfs/api"
"github.com/github/git-lfs/auth"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/credentials"
"github.com/github/git-lfs/errutil"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/httputil"
@ -405,7 +405,7 @@ func doApiBatchRequest(req *http.Request) (*http.Response, []*api.ObjectResource
// doStorageREquest runs the request to the storage API from a link provided by
// the "actions" or "_links" properties an LFS API response.
func doStorageRequest(req *http.Request) (*http.Response, error) {
creds, err := credentials.GetCreds(req)
creds, err := auth.GetCreds(req)
if err != nil {
return nil, err
}
@ -424,7 +424,7 @@ func doAPIRequest(req *http.Request, useCreds bool) (*http.Response, error) {
// doHttpRequest runs the given HTTP request. LFS or Storage API requests should
// use doApiBatchRequest() or doStorageRequest() instead.
func doHttpRequest(req *http.Request, creds credentials.Creds) (*http.Response, error) {
func doHttpRequest(req *http.Request, creds auth.Creds) (*http.Response, error) {
var (
res *http.Response
err error
@ -468,9 +468,9 @@ func doHttpRequest(req *http.Request, creds credentials.Creds) (*http.Response,
}
func doApiRequestWithRedirects(req *http.Request, via []*http.Request, useCreds bool) (*http.Response, error) {
var creds credentials.Creds
var creds auth.Creds
if useCreds {
c, err := credentials.GetCreds(req)
c, err := auth.GetCreds(req)
if err != nil {
return nil, err
}
@ -524,8 +524,8 @@ func doApiRequestWithRedirects(req *http.Request, via []*http.Request, useCreds
return res, nil
}
func handleResponse(res *http.Response, creds credentials.Creds) error {
credentials.SaveCredentials(creds, res)
func handleResponse(res *http.Response, creds auth.Creds) error {
auth.SaveCredentials(creds, res)
if res.StatusCode < 400 {
return nil
@ -599,7 +599,7 @@ func newApiRequest(method, oid string) (*http.Request, error) {
}
endpoint := config.Config.Endpoint(operation)
res, err := credentials.SshAuthenticate(endpoint, operation, oid)
res, err := auth.SshAuthenticate(endpoint, operation, oid)
if err != nil {
tracerx.Printf("ssh: attempted with %s. Error: %s",
endpoint.SshUserAndHost, err.Error(),
@ -643,7 +643,7 @@ func newClientRequest(method, rawurl string, header map[string]string) (*http.Re
func newBatchApiRequest(operation string) (*http.Request, error) {
endpoint := config.Config.Endpoint(operation)
res, err := credentials.SshAuthenticate(endpoint, operation, "")
res, err := auth.SshAuthenticate(endpoint, operation, "")
if err != nil {
tracerx.Printf("ssh: %s attempted with %s. Error: %s",
operation, endpoint.SshUserAndHost, err.Error(),

@ -9,12 +9,12 @@ import (
"strings"
"testing"
"github.com/github/git-lfs/credentials"
"github.com/github/git-lfs/auth"
)
var (
TestCredentialsFunc credentials.CredentialFunc
origCredentialsFunc credentials.CredentialFunc
TestCredentialsFunc auth.CredentialFunc
origCredentialsFunc auth.CredentialFunc
)
func tempdir(t *testing.T) string {
@ -36,8 +36,8 @@ func expectedAuth(t *testing.T, server *httptest.Server) string {
}
func init() {
TestCredentialsFunc = func(input credentials.Creds, subCommand string) (credentials.Creds, error) {
output := make(credentials.Creds)
TestCredentialsFunc = func(input auth.Creds, subCommand string) (auth.Creds, error) {
output := make(auth.Creds)
for key, value := range input {
output[key] = value
}
@ -51,10 +51,10 @@ func init() {
// Override the credentials func for testing
func SetupTestCredentialsFunc() {
origCredentialsFunc = credentials.SetCredentialsFunc(TestCredentialsFunc)
origCredentialsFunc = auth.SetCredentialsFunc(TestCredentialsFunc)
}
// Put the original credentials func back
func RestoreCredentialsFunc() {
credentials.SetCredentialsFunc(origCredentialsFunc)
auth.SetCredentialsFunc(origCredentialsFunc)
}

@ -12,13 +12,13 @@ import (
"strings"
"sync/atomic"
"github.com/github/git-lfs/auth"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/credentials"
"github.com/github/git-lfs/httputil"
"github.com/github/git-lfs/vendor/_nuts/github.com/ThomsonReutersEikon/go-ntlm/ntlm"
)
func ntlmClientSession(c *config.Configuration, creds credentials.Creds) (ntlm.ClientSession, error) {
func ntlmClientSession(c *config.Configuration, creds auth.Creds) (ntlm.ClientSession, error) {
if c.NtlmSession != nil {
return c.NtlmSession, nil
}
@ -54,7 +54,7 @@ func DoNTLMRequest(request *http.Request, retry bool) (*http.Response, error) {
//If the status is 401 then we need to re-authenticate, otherwise it was successful
if res.StatusCode == 401 {
creds, err := credentials.GetCreds(request)
creds, err := auth.GetCreds(request)
if err != nil {
return nil, err
}
@ -84,7 +84,7 @@ func DoNTLMRequest(request *http.Request, retry bool) (*http.Response, error) {
return DoNTLMRequest(challengeReq, false)
}
credentials.SaveCredentials(creds, res)
auth.SaveCredentials(creds, res)
return res, nil
}
@ -110,7 +110,7 @@ func negotiate(request *http.Request, message string) ([]byte, error) {
return ret, nil
}
func challenge(request *http.Request, challengeBytes []byte, creds credentials.Creds) (*http.Response, error) {
func challenge(request *http.Request, challengeBytes []byte, creds auth.Creds) (*http.Response, error) {
challenge, err := ntlm.ParseChallengeMessage(challengeBytes)
if err != nil {
return nil, err

@ -8,8 +8,8 @@ import (
"strings"
"testing"
"github.com/github/git-lfs/auth"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/credentials"
"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
)
@ -18,12 +18,12 @@ func TestNtlmClientSession(t *testing.T) {
//Make sure to clear ntlmSession so test order doesn't matter.
config.Config.NtlmSession = nil
creds := credentials.Creds{"username": "MOOSEDOMAIN\\canadian", "password": "MooseAntlersYeah"}
creds := auth.Creds{"username": "MOOSEDOMAIN\\canadian", "password": "MooseAntlersYeah"}
_, err := ntlmClientSession(config.Config, creds)
assert.Equal(t, err, nil)
//The second call should ignore creds and give the session we just created.
badCreds := credentials.Creds{"username": "badusername", "password": "MooseAntlersYeah"}
badCreds := auth.Creds{"username": "badusername", "password": "MooseAntlersYeah"}
_, err = ntlmClientSession(config.Config, badCreds)
assert.Equal(t, err, nil)
@ -36,7 +36,7 @@ func TestNtlmClientSessionBadCreds(t *testing.T) {
//Make sure to clear ntlmSession so test order doesn't matter.
config.Config.NtlmSession = nil
creds := credentials.Creds{"username": "badusername", "password": "MooseAntlersYeah"}
creds := auth.Creds{"username": "badusername", "password": "MooseAntlersYeah"}
_, err := ntlmClientSession(config.Config, creds)
assert.NotEqual(t, err, nil)