aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.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/common.go
parenta80d56b21142096f458758405736f3d567c175f5 (diff)
downloadgo-git-6be0bc1233b1a31e749354f1d54104b49d5bf19b.tar.gz
clients: new AuthMethod and ConnectWithAuth
Diffstat (limited to 'clients/http/common.go')
-rw-r--r--clients/http/common.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/clients/http/common.go b/clients/http/common.go
index 15338a8..fc3a236 100644
--- a/clients/http/common.go
+++ b/clients/http/common.go
@@ -1,6 +1,7 @@
package http
import (
+ "errors"
"fmt"
"net/http"
@@ -8,6 +9,38 @@ import (
"gopkg.in/src-d/go-git.v2/core"
)
+var InvalidAuthMethodErr = errors.New("invalid http auth method: a http.HTTPAuthMethod should be provided.")
+
+type HTTPAuthMethod interface {
+ common.AuthMethod
+ setAuth(r *http.Request)
+}
+
+type BasicAuth struct {
+ username, password string
+}
+
+func NewBasicAuth(username, password string) *BasicAuth {
+ return &BasicAuth{username, password}
+}
+
+func (a *BasicAuth) setAuth(r *http.Request) {
+ r.SetBasicAuth(a.username, a.password)
+}
+
+func (a *BasicAuth) Name() string {
+ return "http-basic-auth"
+}
+
+func (a *BasicAuth) String() string {
+ masked := "*******"
+ if a.password == "" {
+ masked = "<empty>"
+ }
+
+ return fmt.Sprintf("%s - %s:%s", a.Name(), a.username, masked)
+}
+
type HTTPError struct {
Response *http.Response
}