1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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
commit 21a5a6202d
2 changed files with 18 additions and 15 deletions

View file

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

View file

@ -55,8 +55,11 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
} }
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) { func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
r, err := registry.NewRegistry(srv.runtime.root, nil)
results, err := registry.NewRegistry(srv.runtime.root, nil).SearchRepositories(term) if err != nil {
return nil, err
}
results, err := r.SearchRepositories(term)
if err != nil { if err != nil {
return nil, err 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 { 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 { if err := srv.poolAdd("pull", name+":"+tag); err != nil {
return err return err
} }
defer srv.poolRemove("pull", name+":"+tag) defer srv.poolRemove("pull", name+":"+tag)
r := registry.NewRegistry(srv.runtime.root, authConfig)
out = utils.NewWriteFlusher(out) out = utils.NewWriteFlusher(out)
if endpoint != "" { if endpoint != "" {
if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil { 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) out = utils.NewWriteFlusher(out)
img, err := srv.runtime.graph.Get(name) 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 { if err != nil {
out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name]))) 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 // If it fails, try to get the repository