diff options
author | Derek McGowan <derek@mcgstyle.net> | 2016-02-23 15:18:04 -0800 |
---|---|---|
committer | Derek McGowan <derek@mcgstyle.net> | 2016-03-09 13:47:57 -0800 |
commit | e896d1d7c4459c4b357efdd780e9fb9dd9bc90e0 (patch) | |
tree | 985e911106061937e2d418c689ce76717932f9e2 /registry/service.go | |
parent | 5730259f324a59a6dddf63a950ab8eb9cde3ca0c (diff) | |
download | docker-e896d1d7c4459c4b357efdd780e9fb9dd9bc90e0.tar.gz |
Add support for identity token with token handler
Use token handler options for initialization.
Update auth endpoint to set identity token in response.
Update credential store to match distribution interface changes.
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
Diffstat (limited to 'registry/service.go')
-rw-r--r-- | registry/service.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/registry/service.go b/registry/service.go index 2124da6d9f..830c2bf69a 100644 --- a/registry/service.go +++ b/registry/service.go @@ -2,6 +2,7 @@ package registry import ( "crypto/tls" + "fmt" "net/http" "net/url" "strings" @@ -29,10 +30,19 @@ func NewService(options *Options) *Service { // Auth contacts the public registry with the provided credentials, // and returns OK if authentication was successful. // It can be used to verify the validity of a client's credentials. -func (s *Service) Auth(authConfig *types.AuthConfig, userAgent string) (status string, err error) { - endpoints, err := s.LookupPushEndpoints(authConfig.ServerAddress) +func (s *Service) Auth(authConfig *types.AuthConfig, userAgent string) (status, token string, err error) { + serverAddress := authConfig.ServerAddress + if !strings.HasPrefix(serverAddress, "https://") && !strings.HasPrefix(serverAddress, "http://") { + serverAddress = "https://" + serverAddress + } + u, err := url.Parse(serverAddress) + if err != nil { + return "", "", fmt.Errorf("unable to parse server address: %v", err) + } + + endpoints, err := s.LookupPushEndpoints(u.Host) if err != nil { - return "", err + return "", "", err } for _, endpoint := range endpoints { @@ -41,7 +51,7 @@ func (s *Service) Auth(authConfig *types.AuthConfig, userAgent string) (status s login = loginV1 } - status, err = login(authConfig, endpoint, userAgent) + status, token, err = login(authConfig, endpoint, userAgent) if err == nil { return } @@ -50,10 +60,10 @@ func (s *Service) Auth(authConfig *types.AuthConfig, userAgent string) (status s logrus.Infof("Error logging in to %s endpoint, trying next endpoint: %v", endpoint.Version, err) continue } - return "", err + return "", "", err } - return "", err + return "", "", err } // splitReposSearchTerm breaks a search term into an index name and remote name |