2015-07-29 20:12:01 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/distribution/registry/client/auth"
|
|
|
|
)
|
|
|
|
|
|
|
|
const tokenURL = "https://auth.docker.io/token"
|
2016-02-11 03:07:28 +01:00
|
|
|
const challengeHeader = "Docker-Distribution-Api-Version"
|
2015-07-29 20:12:01 +02:00
|
|
|
|
|
|
|
type userpass struct {
|
|
|
|
username string
|
|
|
|
password string
|
|
|
|
}
|
|
|
|
|
|
|
|
type credentials struct {
|
|
|
|
creds map[string]userpass
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c credentials) Basic(u *url.URL) (string, string) {
|
|
|
|
up := c.creds[u.String()]
|
|
|
|
|
|
|
|
return up.username, up.password
|
|
|
|
}
|
|
|
|
|
2016-02-17 19:42:34 +01:00
|
|
|
// configureAuth stores credentials for challenge responses
|
2016-02-11 03:07:28 +01:00
|
|
|
func configureAuth(username, password string) (auth.CredentialStore, error) {
|
2015-07-29 20:12:01 +02:00
|
|
|
creds := map[string]userpass{
|
|
|
|
tokenURL: {
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return credentials{creds: creds}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ping(manager auth.ChallengeManager, endpoint, versionHeader string) error {
|
|
|
|
resp, err := http.Get(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if err := manager.AddResponse(resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|