summaryrefslogtreecommitdiff
path: root/registry/service.go
diff options
context:
space:
mode:
authorVincent Demeester <vincent@sbr.pm>2016-03-14 15:49:44 +0100
committerVincent Demeester <vincent@sbr.pm>2016-03-14 15:49:44 +0100
commitb9361f02da25108af75238093959634e433d72a0 (patch)
treed323c36677854d2054a1b7a0a5fd3b2477e6a60e /registry/service.go
parentf480c696251906d86c800b5cf3660c48335e361c (diff)
parent76cd0f681184afc44302b954a0775b0cfd748c4f (diff)
downloaddocker-b9361f02da25108af75238093959634e433d72a0.tar.gz
Merge pull request #20970 from dmcgowan/login-oauth
OAuth support for registries
Diffstat (limited to 'registry/service.go')
-rw-r--r--registry/service.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/registry/service.go b/registry/service.go
index 1439e9d7f6..acafc34b60 100644
--- a/registry/service.go
+++ b/registry/service.go
@@ -2,6 +2,7 @@ package registry
import (
"crypto/tls"
+ "fmt"
"net/http"
"net/url"
"strings"
@@ -34,10 +35,19 @@ func (s *Service) ServiceConfig() *registrytypes.ServiceConfig {
// 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 {
@@ -46,7 +56,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
}
@@ -55,10 +65,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