github.com/npaton/distribution@v2.3.1-rc.0+incompatible/registry/proxy/proxyauth.go (about) 1 package proxy 2 3 import ( 4 "net/http" 5 "net/url" 6 7 "github.com/docker/distribution/registry/client/auth" 8 ) 9 10 const tokenURL = "https://auth.docker.io/token" 11 const challengeHeader = "Docker-Distribution-Api-Version" 12 13 type userpass struct { 14 username string 15 password string 16 } 17 18 type credentials struct { 19 creds map[string]userpass 20 } 21 22 func (c credentials) Basic(u *url.URL) (string, string) { 23 up := c.creds[u.String()] 24 25 return up.username, up.password 26 } 27 28 // configureAuth stores credentials for challenge responses 29 func configureAuth(username, password string) (auth.CredentialStore, error) { 30 creds := map[string]userpass{ 31 tokenURL: { 32 username: username, 33 password: password, 34 }, 35 } 36 return credentials{creds: creds}, nil 37 } 38 39 func ping(manager auth.ChallengeManager, endpoint, versionHeader string) error { 40 resp, err := http.Get(endpoint) 41 if err != nil { 42 return err 43 } 44 defer resp.Body.Close() 45 46 if err := manager.AddResponse(resp); err != nil { 47 return err 48 } 49 50 return nil 51 }