aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.go
diff options
context:
space:
mode:
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
}