2015-07-29 18:12:01 +00: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 02:07:28 +00:00
|
|
|
const challengeHeader = "Docker-Distribution-Api-Version"
|
2015-07-29 18:12:01 +00: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-03-04 08:34:17 +00:00
|
|
|
func (c credentials) RefreshToken(u *url.URL, service string) string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c credentials) SetRefreshToken(u *url.URL, service, token string) {
|
|
|
|
}
|
|
|
|
|
2016-02-17 18:42:34 +00:00
|
|
|
// configureAuth stores credentials for challenge responses
|
2016-02-11 02:07:28 +00:00
|
|
|
func configureAuth(username, password string) (auth.CredentialStore, error) {
|
2015-07-29 18:12:01 +00: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
|
|
|
|
}
|