aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/git_upload_pack.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-11-05 19:08:20 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-11-05 20:55:46 +0100
commit6be0bc1233b1a31e749354f1d54104b49d5bf19b (patch)
treea9fd259944a42322050247ed6b5393150f2c4cb8 /clients/http/git_upload_pack.go
parenta80d56b21142096f458758405736f3d567c175f5 (diff)
downloadgo-git-6be0bc1233b1a31e749354f1d54104b49d5bf19b.tar.gz
clients: new AuthMethod and ConnectWithAuth
Diffstat (limited to 'clients/http/git_upload_pack.go')
-rw-r--r--clients/http/git_upload_pack.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 6960be1..217e4aa 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -15,6 +15,7 @@ type GitUploadPackService struct {
Client *http.Client
endpoint common.Endpoint
+ auth HTTPAuthMethod
}
func NewGitUploadPackService() *GitUploadPackService {
@@ -29,6 +30,18 @@ func (s *GitUploadPackService) Connect(url common.Endpoint) error {
return nil
}
+func (s *GitUploadPackService) ConnectWithAuth(url common.Endpoint, auth common.AuthMethod) error {
+ httpAuth, ok := auth.(HTTPAuthMethod)
+ if !ok {
+ return InvalidAuthMethodErr
+ }
+
+ s.endpoint = url
+ s.auth = httpAuth
+
+ return nil
+}
+
func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
url := fmt.Sprintf("%s/info/refs?service=%s", s.endpoint, common.GitUploadPackServiceName)
res, err := s.doRequest("GET", url, nil)
@@ -69,8 +82,10 @@ func (s *GitUploadPackService) doRequest(method, url string, content *strings.Re
}
s.applyHeadersToRequest(req, content)
+ s.applyAuthToRequest(req)
res, err := s.Client.Do(req)
+
if err != nil {
return nil, core.NewUnexpectedError(err)
}
@@ -94,3 +109,11 @@ func (s *GitUploadPackService) applyHeadersToRequest(req *http.Request, content
req.Header.Add("Content-Length", string(content.Len()))
}
}
+
+func (s *GitUploadPackService) applyAuthToRequest(req *http.Request) {
+ if s.auth == nil {
+ return
+ }
+
+ s.auth.setAuth(req)
+}