Refactor authorization challenges to its own package
Split challenges into its own package. Avoids possible import cycle with challenges from client. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
02f4195788
commit
a1a73884f9
8 changed files with 42 additions and 37 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/registry/client/auth"
|
||||
"github.com/docker/distribution/registry/client/auth/challenge"
|
||||
)
|
||||
|
||||
const challengeHeader = "Docker-Distribution-Api-Version"
|
||||
|
@ -62,7 +63,7 @@ func getAuthURLs(remoteURL string) ([]string, error) {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
for _, c := range auth.ResponseChallenges(resp) {
|
||||
for _, c := range challenge.ResponseChallenges(resp) {
|
||||
if strings.EqualFold(c.Scheme, "bearer") {
|
||||
authURLs = append(authURLs, c.Parameters["realm"])
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ func getAuthURLs(remoteURL string) ([]string, error) {
|
|||
return authURLs, nil
|
||||
}
|
||||
|
||||
func ping(manager auth.ChallengeManager, endpoint, versionHeader string) error {
|
||||
func ping(manager challenge.Manager, endpoint, versionHeader string) error {
|
||||
resp, err := http.Get(endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/docker/distribution/manifest/schema1"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/distribution/registry/client/auth"
|
||||
"github.com/docker/distribution/registry/client/auth/challenge"
|
||||
"github.com/docker/distribution/registry/proxy/scheduler"
|
||||
"github.com/docker/distribution/registry/storage"
|
||||
"github.com/docker/distribution/registry/storage/cache/memory"
|
||||
|
@ -77,7 +78,7 @@ func (m *mockChallenger) credentialStore() auth.CredentialStore {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *mockChallenger) challengeManager() auth.ChallengeManager {
|
||||
func (m *mockChallenger) challengeManager() challenge.Manager {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/distribution/registry/client"
|
||||
"github.com/docker/distribution/registry/client/auth"
|
||||
"github.com/docker/distribution/registry/client/auth/challenge"
|
||||
"github.com/docker/distribution/registry/client/transport"
|
||||
"github.com/docker/distribution/registry/proxy/scheduler"
|
||||
"github.com/docker/distribution/registry/storage"
|
||||
|
@ -102,7 +103,7 @@ func NewRegistryPullThroughCache(ctx context.Context, registry distribution.Name
|
|||
remoteURL: *remoteURL,
|
||||
authChallenger: &remoteAuthChallenger{
|
||||
remoteURL: *remoteURL,
|
||||
cm: auth.NewSimpleChallengeManager(),
|
||||
cm: challenge.NewSimpleManager(),
|
||||
cs: cs,
|
||||
},
|
||||
}, nil
|
||||
|
@ -177,14 +178,14 @@ func (pr *proxyingRegistry) BlobStatter() distribution.BlobStatter {
|
|||
// authChallenger encapsulates a request to the upstream to establish credential challenges
|
||||
type authChallenger interface {
|
||||
tryEstablishChallenges(context.Context) error
|
||||
challengeManager() auth.ChallengeManager
|
||||
challengeManager() challenge.Manager
|
||||
credentialStore() auth.CredentialStore
|
||||
}
|
||||
|
||||
type remoteAuthChallenger struct {
|
||||
remoteURL url.URL
|
||||
sync.Mutex
|
||||
cm auth.ChallengeManager
|
||||
cm challenge.Manager
|
||||
cs auth.CredentialStore
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ func (r *remoteAuthChallenger) credentialStore() auth.CredentialStore {
|
|||
return r.cs
|
||||
}
|
||||
|
||||
func (r *remoteAuthChallenger) challengeManager() auth.ChallengeManager {
|
||||
func (r *remoteAuthChallenger) challengeManager() challenge.Manager {
|
||||
return r.cm
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue