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 (
"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 {

View File

@ -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{