Move authConfig to a Parameter on postImagePush, too

This commit is contained in:
Marco Hennings 2013-08-23 09:38:33 +02:00
parent fcee6056dc
commit da3bb9a7c6
2 changed files with 22 additions and 6 deletions

23
api.go
View File

@ -2,8 +2,8 @@ package docker
import (
"code.google.com/p/go.net/websocket"
"encoding/json"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/dotcloud/docker/auth"
"github.com/dotcloud/docker/utils"
@ -491,12 +491,27 @@ func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http
metaHeaders[k] = v
}
}
if err := json.NewDecoder(r.Body).Decode(authConfig); err != nil {
return err
}
if err := parseForm(r); err != nil {
return err
}
authConfig := &auth.AuthConfig{}
authEncoded := r.Form.Get("authConfig")
if authEncoded != "" {
// the new format is to handle the authConfg as a parameter
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
// for a pull it is not an error if no auth was given
// to increase compatibilit to existing api it is defaulting to be empty
authConfig = &auth.AuthConfig{}
}
} else {
// the old format is supported for compatibility if there was no authConfig parameter
if err := json.NewDecoder(r.Body).Decode(authConfig); err != nil {
return err
}
}
if vars == nil {
return fmt.Errorf("Missing parameter")

View File

@ -841,8 +841,9 @@ func (cli *DockerCli) CmdPush(args ...string) error {
if err != nil {
return err
}
v.Set("authConfig", base64.URLEncoding.EncodeToString(buf))
return cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), bytes.NewBuffer(buf), cli.out)
return cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), nil, cli.out)
}
if err := push(authConfig); err != nil {
@ -897,7 +898,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
}
v.Set("authConfig", base64.URLEncoding.EncodeToString(buf))
return cli.stream("POST", "/images/create?"+v.Encode(), bytes.NewBuffer(buf), cli.out)
return cli.stream("POST", "/images/create?"+v.Encode(), nil, cli.out)
}
if err := pull(authConfig); err != nil {