Merge pull request #907 from dotcloud/go1.1_cookie_jar-feature

* Runtime: use go 1.1 cookiejar and remove ResetClient
This commit is contained in:
Guillaume J. Charmes 2013-06-20 10:48:36 -07:00
Родитель d8f56352da 5f93aa0ecf
Коммит 21a5a6202d
2 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -7,10 +7,10 @@ import (
"fmt"
"github.com/dotcloud/docker/auth"
"github.com/dotcloud/docker/utils"
"github.com/shin-/cookiejar"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"strconv"
"strings"
@ -453,11 +453,6 @@ func (r *Registry) SearchRepositories(term string) (*SearchResults, error) {
return result, err
}
func (r *Registry) ResetClient(authConfig *auth.AuthConfig) {
r.authConfig = authConfig
r.client.Jar = cookiejar.NewCookieJar()
}
func (r *Registry) GetAuthConfig(withPasswd bool) *auth.AuthConfig {
password := ""
if withPasswd {
@ -493,18 +488,18 @@ type Registry struct {
authConfig *auth.AuthConfig
}
func NewRegistry(root string, authConfig *auth.AuthConfig) *Registry {
func NewRegistry(root string, authConfig *auth.AuthConfig) (r *Registry, err error) {
httpTransport := &http.Transport{
DisableKeepAlives: true,
Proxy: http.ProxyFromEnvironment,
}
r := &Registry{
r = &Registry{
authConfig: authConfig,
client: &http.Client{
Transport: httpTransport,
},
}
r.client.Jar = cookiejar.NewCookieJar()
return r
r.client.Jar, err = cookiejar.New(nil)
return r, err
}

Просмотреть файл

@ -55,8 +55,11 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
}
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
results, err := registry.NewRegistry(srv.runtime.root, nil).SearchRepositories(term)
r, err := registry.NewRegistry(srv.runtime.root, nil)
if err != nil {
return nil, err
}
results, err := r.SearchRepositories(term)
if err != nil {
return nil, err
}
@ -450,12 +453,15 @@ func (srv *Server) poolRemove(kind, key string) error {
}
func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
r, err := registry.NewRegistry(srv.runtime.root, authConfig)
if err != nil {
return err
}
if err := srv.poolAdd("pull", name+":"+tag); err != nil {
return err
}
defer srv.poolRemove("pull", name+":"+tag)
r := registry.NewRegistry(srv.runtime.root, authConfig)
out = utils.NewWriteFlusher(out)
if endpoint != "" {
if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
@ -654,8 +660,10 @@ func (srv *Server) ImagePush(name, endpoint string, out io.Writer, sf *utils.Str
out = utils.NewWriteFlusher(out)
img, err := srv.runtime.graph.Get(name)
r := registry.NewRegistry(srv.runtime.root, authConfig)
r, err2 := registry.NewRegistry(srv.runtime.root, authConfig)
if err2 != nil {
return err2
}
if err != nil {
out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name])))
// If it fails, try to get the repository