diff options
author | Santiago M. Mola <santi@mola.io> | 2017-01-04 11:18:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 11:18:41 +0100 |
commit | 841abfb7dc640755c443432064252907e3e55c95 (patch) | |
tree | 8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /plumbing/transport/http | |
parent | 90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff) | |
download | go-git-841abfb7dc640755c443432064252907e3e55c95.tar.gz |
server: add git server implementation (#190)
* server: add generic server implementation (transport-independent),
both for git-upload-pack and git-receive-pack.
* server: move internal functions to internal/common.
* cli: add git-receive-pack and git-upload-pack implementations.
* format/packfile: add UpdateObjectStorage function, extracted from
Remote.
* transport: implement tranport RPC-like, only with git-upload-pack and
git-receive-pack methods. Client renamed to Transport.
* storer: add storer.Storer interface.
* protocol/packp: add UploadPackResponse constructor with packfile.
* protocol/packp: fix UploadPackResponse encoding, add tests.
* protocol/packp/capability: implement All.
Diffstat (limited to 'plumbing/transport/http')
-rw-r--r-- | plumbing/transport/http/common.go | 14 | ||||
-rw-r--r-- | plumbing/transport/http/common_test.go | 8 | ||||
-rw-r--r-- | plumbing/transport/http/receive_pack.go | 30 | ||||
-rw-r--r-- | plumbing/transport/http/send_pack.go | 30 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack.go (renamed from plumbing/transport/http/fetch_pack.go) | 18 | ||||
-rw-r--r-- | plumbing/transport/http/upload_pack_test.go (renamed from plumbing/transport/http/fetch_pack_test.go) | 23 |
6 files changed, 62 insertions, 61 deletions
diff --git a/plumbing/transport/http/common.go b/plumbing/transport/http/common.go index aa3425e..957fd07 100644 --- a/plumbing/transport/http/common.go +++ b/plumbing/transport/http/common.go @@ -25,7 +25,7 @@ var DefaultClient = NewClient(nil) // Note that for HTTP client cannot distinguist between private repositories and // unexistent repositories on GitHub. So it returns `ErrAuthorizationRequired` // for both. -func NewClient(c *http.Client) transport.Client { +func NewClient(c *http.Client) transport.Transport { if c == nil { return &client{http.DefaultClient} } @@ -35,16 +35,16 @@ func NewClient(c *http.Client) transport.Client { } } -func (c *client) NewFetchPackSession(ep transport.Endpoint) ( - transport.FetchPackSession, error) { +func (c *client) NewUploadPackSession(ep transport.Endpoint) ( + transport.UploadPackSession, error) { - return newFetchPackSession(c.c, ep), nil + return newUploadPackSession(c.c, ep), nil } -func (c *client) NewSendPackSession(ep transport.Endpoint) ( - transport.SendPackSession, error) { +func (c *client) NewReceivePackSession(ep transport.Endpoint) ( + transport.ReceivePackSession, error) { - return newSendPackSession(c.c, ep), nil + return newReceivePackSession(c.c, ep), nil } type session struct { diff --git a/plumbing/transport/http/common_test.go b/plumbing/transport/http/common_test.go index 432bd07..217999d 100644 --- a/plumbing/transport/http/common_test.go +++ b/plumbing/transport/http/common_test.go @@ -26,7 +26,7 @@ func (s *ClientSuite) SetUpSuite(c *C) { c.Assert(err, IsNil) } -func (s *FetchPackSuite) TestNewClient(c *C) { +func (s *UploadPackSuite) TestNewClient(c *C) { roundTripper := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } @@ -76,10 +76,10 @@ func (s *ClientSuite) testNewHTTPError(c *C, code int, msg string) { func (s *ClientSuite) TestSetAuth(c *C) { auth := &BasicAuth{} - r, err := DefaultClient.NewFetchPackSession(s.Endpoint) + r, err := DefaultClient.NewUploadPackSession(s.Endpoint) c.Assert(err, IsNil) r.SetAuth(auth) - c.Assert(auth, Equals, r.(*fetchPackSession).auth) + c.Assert(auth, Equals, r.(*upSession).auth) } type mockAuth struct{} @@ -88,7 +88,7 @@ func (*mockAuth) Name() string { return "" } func (*mockAuth) String() string { return "" } func (s *ClientSuite) TestSetAuthWrongType(c *C) { - r, err := DefaultClient.NewFetchPackSession(s.Endpoint) + r, err := DefaultClient.NewUploadPackSession(s.Endpoint) c.Assert(err, IsNil) c.Assert(r.SetAuth(&mockAuth{}), Equals, transport.ErrInvalidAuthMethod) } diff --git a/plumbing/transport/http/receive_pack.go b/plumbing/transport/http/receive_pack.go new file mode 100644 index 0000000..a8384c7 --- /dev/null +++ b/plumbing/transport/http/receive_pack.go @@ -0,0 +1,30 @@ +package http + +import ( + "errors" + "net/http" + + "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" + "gopkg.in/src-d/go-git.v4/plumbing/transport" +) + +var errReceivePackNotSupported = errors.New("receive-pack not supported yet") + +type rpSession struct { + *session +} + +func newReceivePackSession(c *http.Client, ep transport.Endpoint) transport.ReceivePackSession { + return &rpSession{&session{}} +} + +func (s *rpSession) AdvertisedReferences() (*packp.AdvRefs, error) { + + return nil, errReceivePackNotSupported +} + +func (s *rpSession) ReceivePack(*packp.ReferenceUpdateRequest) ( + *packp.ReportStatus, error) { + + return nil, errReceivePackNotSupported +} diff --git a/plumbing/transport/http/send_pack.go b/plumbing/transport/http/send_pack.go deleted file mode 100644 index 43464ae..0000000 --- a/plumbing/transport/http/send_pack.go +++ /dev/null @@ -1,30 +0,0 @@ -package http - -import ( - "errors" - "net/http" - - "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" - "gopkg.in/src-d/go-git.v4/plumbing/transport" -) - -var errSendPackNotSupported = errors.New("send-pack not supported yet") - -type sendPackSession struct { - *session -} - -func newSendPackSession(c *http.Client, ep transport.Endpoint) transport.SendPackSession { - return &sendPackSession{&session{}} -} - -func (s *sendPackSession) AdvertisedReferences() (*packp.AdvRefs, error) { - - return nil, errSendPackNotSupported -} - -func (s *sendPackSession) SendPack(*packp.ReferenceUpdateRequest) ( - *packp.ReportStatus, error) { - - return nil, errSendPackNotSupported -} diff --git a/plumbing/transport/http/fetch_pack.go b/plumbing/transport/http/upload_pack.go index 0c85be4..26257f5 100644 --- a/plumbing/transport/http/fetch_pack.go +++ b/plumbing/transport/http/upload_pack.go @@ -15,14 +15,14 @@ import ( "gopkg.in/src-d/go-git.v4/utils/ioutil" ) -type fetchPackSession struct { +type upSession struct { *session } -func newFetchPackSession(c *http.Client, - ep transport.Endpoint) transport.FetchPackSession { +func newUploadPackSession(c *http.Client, + ep transport.Endpoint) transport.UploadPackSession { - return &fetchPackSession{ + return &upSession{ session: &session{ auth: basicAuthFromEndpoint(ep), client: c, @@ -31,7 +31,7 @@ func newFetchPackSession(c *http.Client, } } -func (s *fetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) { +func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) { if s.advRefs != nil { return s.advRefs, nil } @@ -73,7 +73,7 @@ func (s *fetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) { return ar, nil } -func (s *fetchPackSession) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) { +func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) { if req.IsEmpty() { return nil, transport.ErrEmptyUploadPackRequest } @@ -111,11 +111,11 @@ func (s *fetchPackSession) FetchPack(req *packp.UploadPackRequest) (*packp.Uploa } // Close does nothing. -func (s *fetchPackSession) Close() error { +func (s *upSession) Close() error { return nil } -func (s *fetchPackSession) doRequest(method, url string, content *bytes.Buffer) (*http.Response, error) { +func (s *upSession) doRequest(method, url string, content *bytes.Buffer) (*http.Response, error) { var body io.Reader if content != nil { body = content @@ -143,7 +143,7 @@ func (s *fetchPackSession) doRequest(method, url string, content *bytes.Buffer) } // it requires a bytes.Buffer, because we need to know the length -func (s *fetchPackSession) applyHeadersToRequest(req *http.Request, content *bytes.Buffer) { +func (s *upSession) applyHeadersToRequest(req *http.Request, content *bytes.Buffer) { req.Header.Add("User-Agent", "git/1.0") req.Header.Add("Host", s.endpoint.Host) diff --git a/plumbing/transport/http/fetch_pack_test.go b/plumbing/transport/http/upload_pack_test.go index 6c40e60..d3e4989 100644 --- a/plumbing/transport/http/fetch_pack_test.go +++ b/plumbing/transport/http/upload_pack_test.go @@ -11,37 +11,38 @@ import ( . "gopkg.in/check.v1" ) -type FetchPackSuite struct { - test.FetchPackSuite +type UploadPackSuite struct { + test.UploadPackSuite } -var _ = Suite(&FetchPackSuite{}) +var _ = Suite(&UploadPackSuite{}) -func (s *FetchPackSuite) SetUpSuite(c *C) { - s.FetchPackSuite.Client = DefaultClient +func (s *UploadPackSuite) SetUpSuite(c *C) { + s.UploadPackSuite.Client = DefaultClient ep, err := transport.NewEndpoint("https://github.com/git-fixtures/basic.git") c.Assert(err, IsNil) - s.FetchPackSuite.Endpoint = ep + s.UploadPackSuite.Endpoint = ep ep, err = transport.NewEndpoint("https://github.com/git-fixtures/empty.git") c.Assert(err, IsNil) - s.FetchPackSuite.EmptyEndpoint = ep + s.UploadPackSuite.EmptyEndpoint = ep ep, err = transport.NewEndpoint("https://github.com/git-fixtures/non-existent.git") c.Assert(err, IsNil) - s.FetchPackSuite.NonExistentEndpoint = ep + s.UploadPackSuite.NonExistentEndpoint = ep } -func (s *FetchPackSuite) TestInfoNotExists(c *C) { - r, err := s.Client.NewFetchPackSession(s.NonExistentEndpoint) +// Overwritten, different behaviour for HTTP. +func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) { + r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint) c.Assert(err, IsNil) info, err := r.AdvertisedReferences() c.Assert(err, Equals, transport.ErrAuthorizationRequired) c.Assert(info, IsNil) } -func (s *FetchPackSuite) TestuploadPackRequestToReader(c *C) { +func (s *UploadPackSuite) TestuploadPackRequestToReader(c *C) { r := packp.NewUploadPackRequest() r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) r.Wants = append(r.Wants, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) |