diff --git a/api.go b/api.go index 0debbe94f3..8b6d0280e7 100644 --- a/api.go +++ b/api.go @@ -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") diff --git a/commands.go b/commands.go index 16340d74ae..3d3728ac9e 100644 --- a/commands.go +++ b/commands.go @@ -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 {