Use base64 encoding

This commit is contained in:
shin- 2013-08-30 22:49:37 +02:00 committed by Marco Hennings
parent d04beb7f43
commit dd4aab8411
2 changed files with 13 additions and 9 deletions

18
api.go
View File

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

View File

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