* Runtime: use go 1.1 cookiejar and remove ResetClient
Guillaume J. Charmes authored on 2013/06/21 02:48:36... | ... |
@@ -7,10 +7,10 @@ import ( |
7 | 7 |
"fmt" |
8 | 8 |
"github.com/dotcloud/docker/auth" |
9 | 9 |
"github.com/dotcloud/docker/utils" |
10 |
- "github.com/shin-/cookiejar" |
|
11 | 10 |
"io" |
12 | 11 |
"io/ioutil" |
13 | 12 |
"net/http" |
13 |
+ "net/http/cookiejar" |
|
14 | 14 |
"net/url" |
15 | 15 |
"strconv" |
16 | 16 |
"strings" |
... | ... |
@@ -453,11 +453,6 @@ func (r *Registry) SearchRepositories(term string) (*SearchResults, error) { |
453 | 453 |
return result, err |
454 | 454 |
} |
455 | 455 |
|
456 |
-func (r *Registry) ResetClient(authConfig *auth.AuthConfig) { |
|
457 |
- r.authConfig = authConfig |
|
458 |
- r.client.Jar = cookiejar.NewCookieJar() |
|
459 |
-} |
|
460 |
- |
|
461 | 456 |
func (r *Registry) GetAuthConfig(withPasswd bool) *auth.AuthConfig { |
462 | 457 |
password := "" |
463 | 458 |
if withPasswd { |
... | ... |
@@ -493,18 +488,18 @@ type Registry struct { |
493 | 493 |
authConfig *auth.AuthConfig |
494 | 494 |
} |
495 | 495 |
|
496 |
-func NewRegistry(root string, authConfig *auth.AuthConfig) *Registry { |
|
496 |
+func NewRegistry(root string, authConfig *auth.AuthConfig) (r *Registry, err error) { |
|
497 | 497 |
httpTransport := &http.Transport{ |
498 | 498 |
DisableKeepAlives: true, |
499 | 499 |
Proxy: http.ProxyFromEnvironment, |
500 | 500 |
} |
501 | 501 |
|
502 |
- r := &Registry{ |
|
502 |
+ r = &Registry{ |
|
503 | 503 |
authConfig: authConfig, |
504 | 504 |
client: &http.Client{ |
505 | 505 |
Transport: httpTransport, |
506 | 506 |
}, |
507 | 507 |
} |
508 |
- r.client.Jar = cookiejar.NewCookieJar() |
|
509 |
- return r |
|
508 |
+ r.client.Jar, err = cookiejar.New(nil) |
|
509 |
+ return r, err |
|
510 | 510 |
} |
... | ... |
@@ -55,8 +55,11 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error { |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) { |
58 |
- |
|
59 |
- results, err := registry.NewRegistry(srv.runtime.root, nil).SearchRepositories(term) |
|
58 |
+ r, err := registry.NewRegistry(srv.runtime.root, nil) |
|
59 |
+ if err != nil { |
|
60 |
+ return nil, err |
|
61 |
+ } |
|
62 |
+ results, err := r.SearchRepositories(term) |
|
60 | 63 |
if err != nil { |
61 | 64 |
return nil, err |
62 | 65 |
} |
... | ... |
@@ -450,12 +453,15 @@ func (srv *Server) poolRemove(kind, key string) error { |
450 | 450 |
} |
451 | 451 |
|
452 | 452 |
func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error { |
453 |
+ r, err := registry.NewRegistry(srv.runtime.root, authConfig) |
|
454 |
+ if err != nil { |
|
455 |
+ return err |
|
456 |
+ } |
|
453 | 457 |
if err := srv.poolAdd("pull", name+":"+tag); err != nil { |
454 | 458 |
return err |
455 | 459 |
} |
456 | 460 |
defer srv.poolRemove("pull", name+":"+tag) |
457 | 461 |
|
458 |
- r := registry.NewRegistry(srv.runtime.root, authConfig) |
|
459 | 462 |
out = utils.NewWriteFlusher(out) |
460 | 463 |
if endpoint != "" { |
461 | 464 |
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 |
654 | 654 |
|
655 | 655 |
out = utils.NewWriteFlusher(out) |
656 | 656 |
img, err := srv.runtime.graph.Get(name) |
657 |
- r := registry.NewRegistry(srv.runtime.root, authConfig) |
|
658 |
- |
|
657 |
+ r, err2 := registry.NewRegistry(srv.runtime.root, authConfig) |
|
658 |
+ if err2 != nil { |
|
659 |
+ return err2 |
|
660 |
+ } |
|
659 | 661 |
if err != nil { |
660 | 662 |
out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name]))) |
661 | 663 |
// If it fails, try to get the repository |