浏览代码

Use base64 encoding

shin- 12 年之前
父节点
当前提交
dd4aab8411
共有 2 个文件被更改,包括 13 次插入9 次删除
  1. 11 7
      api.go
  2. 2 2
      commands.go

+ 11 - 7
api.go

@@ -2,6 +2,7 @@ package docker
 
 import (
 	"code.google.com/p/go.net/websocket"
+	"encoding/base64"
 	"encoding/json"
 	"fmt"
 	"github.com/dotcloud/docker/auth"
@@ -394,10 +395,11 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht
 	tag := r.Form.Get("tag")
 	repo := r.Form.Get("repo")
 
-	authJson := r.Header.Get("X-Registry-Auth")
+	authEncoded := r.Header.Get("X-Registry-Auth")
 	authConfig := &auth.AuthConfig{}
-	if authJson != "" {
-		if err := json.NewDecoder(strings.NewReader(authJson)).Decode(authConfig); err != nil {
+	if authEncoded != "" {
+		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 compatibility with the existing api it is defaulting to be empty
 			authConfig = &auth.AuthConfig{}
@@ -493,10 +495,12 @@ func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http
 	}
 	authConfig := &auth.AuthConfig{}
 
-	authJson := r.Header.Get("X-Registry-Auth")
-	if authJson != "" {
-		if err := json.NewDecoder(strings.NewReader(authJson)).Decode(authConfig); err != nil {
-			// to increase compatibility with the existing api it is defaulting to be empty
+	authEncoded := r.Header.Get("X-Registry-Auth")
+	if authEncoded != "" {
+		// the new format is to handle the authConfig as a header
+		authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
+		if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
+			// to increase compatibility to existing api it is defaulting to be empty
 			authConfig = &auth.AuthConfig{}
 		}
 	} else {

+ 2 - 2
commands.go

@@ -842,7 +842,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
 			return err
 		}
 		registryAuthHeader := []string{
-			string(buf),
+			base64.URLEncoding.EncodeToString(buf),
 		}
 
 		return cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), nil, cli.out, map[string][]string{
@@ -901,7 +901,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
 			return err
 		}
 		registryAuthHeader := []string{
-			string(buf),
+			base64.URLEncoding.EncodeToString(buf),
 		}
 
 		return cli.stream("POST", "/images/create?"+v.Encode(), nil, cli.out, map[string][]string{