Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit c17627c

Browse files
authored
Merge pull request #504 from dummy-ai/v4
Add AuthMethod based on HTTP Authorization header
2 parents d3c7400 + c8cc3d5 commit c17627c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

plumbing/revlist/revlist.go

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ func Objects(
2424
seen := hashListToSet(ignore)
2525
result := make(map[plumbing.Hash]bool)
2626

27+
cleanerFunc := func(h plumbing.Hash) {
28+
seen[h] = true
29+
}
30+
31+
for _, h := range ignore {
32+
processObject(s, h, hashListToSet([]plumbing.Hash{}), cleanerFunc)
33+
}
34+
2735
walkerFunc := func(h plumbing.Hash) {
2836
if !seen[h] {
2937
result[h] = true

plumbing/transport/http/common.go

+28
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@ type AuthMethod interface {
145145
setAuth(r *http.Request)
146146
}
147147

148+
// TokenAuthMethod is concrete implementation of common.AuthMethod for HTTP services
149+
// Allow Bearer Token used in git authentication.
150+
type TokenAuth struct {
151+
token string
152+
}
153+
154+
// NewTokenAuth returns a tokenAuth on the given authrorization token.
155+
func NewTokenAuth(token string) *TokenAuth {
156+
return &TokenAuth{token}
157+
}
158+
159+
func (a *TokenAuth) setAuth(r *http.Request) {
160+
if a == nil {
161+
return
162+
}
163+
164+
r.Header.Set("Authorization", a.token)
165+
}
166+
167+
// Name is name of the auth
168+
func (a *TokenAuth) Name() string {
169+
return "http-token-auth"
170+
}
171+
172+
func (a *TokenAuth) String() string {
173+
return fmt.Sprintf("%s...", a.token[:10])
174+
}
175+
148176
func basicAuthFromEndpoint(ep transport.Endpoint) *BasicAuth {
149177
u := ep.User()
150178
if u == "" {

0 commit comments

Comments
 (0)