mirror of
https://github.com/docker/docs.git
synced 2026-11-05 00:14:17 +03:00
Merge pull request #713 from twistlock/list_targets_basic_auth
Enable basic authentication for list command
This commit is contained in:
@@ -666,8 +666,16 @@ func tokenAuth(trustServerURL string, baseTransport *http.Transport, gun string,
|
||||
}
|
||||
tokenHandler := auth.NewTokenHandler(authTransport, ps, gun, actions...)
|
||||
basicHandler := auth.NewBasicHandler(ps)
|
||||
modifier := transport.RequestModifier(auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
|
||||
return transport.NewTransport(baseTransport, modifier), nil
|
||||
|
||||
modifier := auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler)
|
||||
|
||||
if !readOnly {
|
||||
return newAuthRoundTripper(transport.NewTransport(baseTransport, modifier)), nil
|
||||
}
|
||||
|
||||
// Try to authenticate read only repositories using basic username/password authentication
|
||||
return newAuthRoundTripper(transport.NewTransport(baseTransport, modifier),
|
||||
transport.NewTransport(baseTransport, auth.NewAuthorizer(challengeManager, auth.NewTokenHandler(authTransport, passwordStore{anonymous: false}, gun, actions...)))), nil
|
||||
}
|
||||
|
||||
func getRemoteTrustServer(config *viper.Viper) string {
|
||||
@@ -703,3 +711,34 @@ func getTrustPinning(config *viper.Viper) (trustpinning.TrustPinConfig, error) {
|
||||
Certs: resultCertMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// authRoundTripper tries to authenticate the requests via multiple HTTP transactions (until first succeed)
|
||||
type authRoundTripper struct {
|
||||
trippers []http.RoundTripper
|
||||
}
|
||||
|
||||
func newAuthRoundTripper(trippers ...http.RoundTripper) http.RoundTripper {
|
||||
return &authRoundTripper{trippers: trippers}
|
||||
}
|
||||
|
||||
func (a *authRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
|
||||
var resp *http.Response
|
||||
// Try all run all transactions
|
||||
for _, t := range a.trippers {
|
||||
var err error
|
||||
resp, err = t.RoundTrip(req)
|
||||
// Reject on error
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// Stop when request is authorized/unknown error
|
||||
if resp.StatusCode != http.StatusUnauthorized {
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Return the last response
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user