forked from TrueCloudLab/distribution
Adds support for v2 registry login
summary of changes: registry/auth.go - More logging around the login functions - split Login() out to handle different code paths for v1 (unchanged logic) and v2 (does not currently do account creation) - handling for either basic or token based login attempts registry/authchallenge.go - New File - credit to Brian Bland <brian.bland@docker.com> (github: BrianBland) - handles parsing of WWW-Authenticate response headers registry/endpoint.go - EVEN MOAR LOGGING - Many edits throught to make the coad less dense. Sparse code is more readable code. - slit Ping() out to handle different code paths for v1 (unchanged logic) and v2. - Updated Endpoint struct type to include an entry for authorization challenges discovered during ping of a v2 registry. - If registry endpoint version is unknown, v2 code path is first attempted, then fallback to v1 upon failure. registry/service.go - STILL MOAR LOGGING - simplified the logic around starting the 'auth' job. registry/session.go - updated use of a registry.Endpoint struct field. registry/token.go - New File - Handles getting token from the parameters of a token auth challenge. - Modified from function written by Brian Bland (see above credit). registry/types.go - Removed 'DefaultAPIVersion' in lieu of 'APIVersionUnknown = 0'` Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
This commit is contained in:
parent
1f98347924
commit
6b400cd63c
8 changed files with 484 additions and 63 deletions
|
@ -1,6 +1,7 @@
|
|||
package registry
|
||||
|
||||
import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/engine"
|
||||
)
|
||||
|
||||
|
@ -38,28 +39,39 @@ func (s *Service) Install(eng *engine.Engine) error {
|
|||
// and returns OK if authentication was sucessful.
|
||||
// It can be used to verify the validity of a client's credentials.
|
||||
func (s *Service) Auth(job *engine.Job) engine.Status {
|
||||
var authConfig = new(AuthConfig)
|
||||
var (
|
||||
authConfig = new(AuthConfig)
|
||||
endpoint *Endpoint
|
||||
index *IndexInfo
|
||||
status string
|
||||
err error
|
||||
)
|
||||
|
||||
job.GetenvJson("authConfig", authConfig)
|
||||
|
||||
if authConfig.ServerAddress != "" {
|
||||
index, err := ResolveIndexInfo(job, authConfig.ServerAddress)
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
if !index.Official {
|
||||
endpoint, err := NewEndpoint(index)
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
authConfig.ServerAddress = endpoint.String()
|
||||
}
|
||||
addr := authConfig.ServerAddress
|
||||
if addr == "" {
|
||||
// Use the official registry address if not specified.
|
||||
addr = IndexServerAddress()
|
||||
}
|
||||
|
||||
status, err := Login(authConfig, HTTPRequestFactory(nil))
|
||||
if err != nil {
|
||||
if index, err = ResolveIndexInfo(job, addr); err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
|
||||
if endpoint, err = NewEndpoint(index); err != nil {
|
||||
log.Errorf("unable to get new registry endpoint: %s", err)
|
||||
return job.Error(err)
|
||||
}
|
||||
|
||||
authConfig.ServerAddress = endpoint.String()
|
||||
|
||||
if status, err = Login(authConfig, endpoint, HTTPRequestFactory(nil)); err != nil {
|
||||
log.Errorf("unable to login against registry endpoint %s: %s", endpoint, err)
|
||||
return job.Error(err)
|
||||
}
|
||||
|
||||
log.Infof("successful registry login for endpoint %s: %s", endpoint, status)
|
||||
job.Printf("%s\n", status)
|
||||
|
||||
return engine.StatusOK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue