diff options
author | Anthony Weems <amlweems@gmail.com> | 2017-01-17 11:17:11 -0600 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-01-17 18:17:11 +0100 |
commit | 6593c757346f9817a770ff0ea091cce3e8243070 (patch) | |
tree | 6fbb72583931b0386e382177970650a9cdbca4eb /plumbing/transport/http | |
parent | 241e8ba00ac9533299d62dc38684305af2b6c301 (diff) | |
download | go-git-6593c757346f9817a770ff0ea091cce3e8243070.tar.gz |
transport: remove SetAuth, fixes #206 (#210)
* remove SetAuth functions, implement at NewUploadPackSession/NewReceivePackSession level.
* propagate transport.Auth from Fetch/Pull/Clone options to the transport API.
Diffstat (limited to 'plumbing/transport/http')
-rw-r--r-- | plumbing/transport/http/common.go | 18 | ||||
-rw-r--r-- | plumbing/transport/http/common_test.go | 11 | ||||
-rw-r--r-- | plumbing/transport/http/receive_pack.go | 4 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack.go | 22 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack_test.go | 2 |
5 files changed, 26 insertions, 31 deletions
diff --git a/plumbing/transport/http/common.go b/plumbing/transport/http/common.go index 957fd07..a26cf0c 100644 --- a/plumbing/transport/http/common.go +++ b/plumbing/transport/http/common.go @@ -35,16 +35,16 @@ func NewClient(c *http.Client) transport.Transport { } } -func (c *client) NewUploadPackSession(ep transport.Endpoint) ( +func (c *client) NewUploadPackSession(ep transport.Endpoint, auth transport.AuthMethod) ( transport.UploadPackSession, error) { - return newUploadPackSession(c.c, ep), nil + return newUploadPackSession(c.c, ep, auth) } -func (c *client) NewReceivePackSession(ep transport.Endpoint) ( +func (c *client) NewReceivePackSession(ep transport.Endpoint, auth transport.AuthMethod) ( transport.ReceivePackSession, error) { - return newReceivePackSession(c.c, ep), nil + return newReceivePackSession(c.c, ep, auth) } type session struct { @@ -54,16 +54,6 @@ type session struct { advRefs *packp.AdvRefs } -func (s *session) SetAuth(auth transport.AuthMethod) error { - a, ok := auth.(AuthMethod) - if !ok { - return transport.ErrInvalidAuthMethod - } - - s.auth = a - return nil -} - func (*session) Close() error { return nil } diff --git a/plumbing/transport/http/common_test.go b/plumbing/transport/http/common_test.go index 217999d..1fd0dd5 100644 --- a/plumbing/transport/http/common_test.go +++ b/plumbing/transport/http/common_test.go @@ -13,7 +13,8 @@ import ( func Test(t *testing.T) { TestingT(t) } type ClientSuite struct { - Endpoint transport.Endpoint + Endpoint transport.Endpoint + EmptyAuth transport.AuthMethod } var _ = Suite(&ClientSuite{}) @@ -76,9 +77,8 @@ func (s *ClientSuite) testNewHTTPError(c *C, code int, msg string) { func (s *ClientSuite) TestSetAuth(c *C) { auth := &BasicAuth{} - r, err := DefaultClient.NewUploadPackSession(s.Endpoint) + r, err := DefaultClient.NewUploadPackSession(s.Endpoint, auth) c.Assert(err, IsNil) - r.SetAuth(auth) c.Assert(auth, Equals, r.(*upSession).auth) } @@ -88,7 +88,6 @@ func (*mockAuth) Name() string { return "" } func (*mockAuth) String() string { return "" } func (s *ClientSuite) TestSetAuthWrongType(c *C) { - r, err := DefaultClient.NewUploadPackSession(s.Endpoint) - c.Assert(err, IsNil) - c.Assert(r.SetAuth(&mockAuth{}), Equals, transport.ErrInvalidAuthMethod) + _, err := DefaultClient.NewUploadPackSession(s.Endpoint, &mockAuth{}) + c.Assert(err, Equals, transport.ErrInvalidAuthMethod) } diff --git a/plumbing/transport/http/receive_pack.go b/plumbing/transport/http/receive_pack.go index a8384c7..7a37049 100644 --- a/plumbing/transport/http/receive_pack.go +++ b/plumbing/transport/http/receive_pack.go @@ -14,8 +14,8 @@ type rpSession struct { *session } -func newReceivePackSession(c *http.Client, ep transport.Endpoint) transport.ReceivePackSession { - return &rpSession{&session{}} +func newReceivePackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.ReceivePackSession, error) { + return &rpSession{&session{}}, nil } func (s *rpSession) AdvertisedReferences() (*packp.AdvRefs, error) { diff --git a/plumbing/transport/http/upload_pack.go b/plumbing/transport/http/upload_pack.go index 26257f5..e828857 100644 --- a/plumbing/transport/http/upload_pack.go +++ b/plumbing/transport/http/upload_pack.go @@ -19,16 +19,22 @@ type upSession struct { *session } -func newUploadPackSession(c *http.Client, - ep transport.Endpoint) transport.UploadPackSession { +func newUploadPackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) { + s := &session{ + auth: basicAuthFromEndpoint(ep), + client: c, + endpoint: ep, + } + if auth != nil { + a, ok := auth.(AuthMethod) + if !ok { + return nil, transport.ErrInvalidAuthMethod + } - return &upSession{ - session: &session{ - auth: basicAuthFromEndpoint(ep), - client: c, - endpoint: ep, - }, + s.auth = a } + + return &upSession{session: s}, nil } func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) { diff --git a/plumbing/transport/http/upload_pack_test.go b/plumbing/transport/http/upload_pack_test.go index d3e4989..13b7f75 100644 --- a/plumbing/transport/http/upload_pack_test.go +++ b/plumbing/transport/http/upload_pack_test.go @@ -35,7 +35,7 @@ func (s *UploadPackSuite) SetUpSuite(c *C) { // Overwritten, different behaviour for HTTP. func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) { - r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint) + r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint, s.EmptyAuth) c.Assert(err, IsNil) info, err := r.AdvertisedReferences() c.Assert(err, Equals, transport.ErrAuthorizationRequired) |