1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

URL schemes of both Registry and Index are now consistent

This commit is contained in:
Sam Alba 2013-06-27 17:55:17 -07:00
parent 1a201d2433
commit 3175e56ad0
3 changed files with 14 additions and 6 deletions

View file

@ -74,7 +74,6 @@ func decodeAuth(authStr string) (*AuthConfig, error) {
}
password := strings.Trim(arr[1], "\x00")
return &AuthConfig{Username: arr[0], Password: password}, nil
}
// load up the auth config information and return values

View file

@ -18,6 +18,14 @@ import (
var ErrAlreadyExists = errors.New("Image already exists")
func UrlScheme() string {
u, err := url.Parse(auth.IndexServerAddress())
if err != nil {
return "https"
}
return u.Scheme
}
func doWithCookies(c *http.Client, req *http.Request) (*http.Response, error) {
for _, cookie := range c.Jar.Cookies(req.URL) {
req.AddCookie(cookie)
@ -155,7 +163,7 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [
repository = "library/" + repository
}
for _, host := range registries {
endpoint := fmt.Sprintf("https://%s/v1/repositories/%s/tags", host, repository)
endpoint := fmt.Sprintf("%s://%s/v1/repositories/%s/tags", UrlScheme(), host, repository)
req, err := r.opaqueRequest("GET", endpoint, nil)
if err != nil {
return nil, err
@ -249,7 +257,7 @@ func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) {
// Push a local image to the registry
func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, registry string, token []string) error {
registry = "https://" + registry + "/v1"
registry = fmt.Sprintf("%s://%s/v1", UrlScheme(), registry)
// FIXME: try json with UTF8
req, err := http.NewRequest("PUT", registry+"/images/"+imgData.ID+"/json", strings.NewReader(string(jsonRaw)))
if err != nil {
@ -285,7 +293,7 @@ func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, regis
}
func (r *Registry) PushImageLayerRegistry(imgId string, layer io.Reader, registry string, token []string) error {
registry = "https://" + registry + "/v1"
registry = fmt.Sprintf("%s://%s/v1", UrlScheme(), registry)
req, err := http.NewRequest("PUT", registry+"/images/"+imgId+"/layer", layer)
if err != nil {
return err
@ -323,7 +331,7 @@ func (r *Registry) opaqueRequest(method, urlStr string, body io.Reader) (*http.R
func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token []string) error {
// "jsonify" the string
revision = "\"" + revision + "\""
registry = "https://" + registry + "/v1"
registry = fmt.Sprintf("%s://%s/v1", UrlScheme(), registry)
req, err := r.opaqueRequest("PUT", registry+"/repositories/"+remote+"/tags/"+tag, strings.NewReader(revision))
if err != nil {

View file

@ -392,7 +392,8 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, local, re
out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.ID, img.Tag, remote))
success := false
for _, ep := range repoData.Endpoints {
if err := srv.pullImage(r, out, img.ID, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
ep = fmt.Sprintf("%s://%s/v1", registry.UrlScheme(), ep)
if err := srv.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
continue
}