فهرست منبع

Move authConfig to a Parameter on postImagePush, too

Marco Hennings 12 سال پیش
والد
کامیت
da3bb9a7c6
2فایلهای تغییر یافته به همراه22 افزوده شده و 6 حذف شده
  1. 19 4
      api.go
  2. 3 2
      commands.go

+ 19 - 4
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")

+ 3 - 2
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 {