From 131b608aeb1d9fb3d2b88cc5f81fbdd99433ca84 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 15 May 2015 16:50:17 -0700 Subject: [PATCH] Create client transport package Signed-off-by: Derek McGowan (github: dmcgowan) --- docs/client/repository.go | 9 +++++---- docs/client/{ => transport}/authchallenge.go | 2 +- docs/client/{ => transport}/authchallenge_test.go | 2 +- docs/client/{ => transport}/http_reader.go | 2 +- docs/client/{ => transport}/session.go | 2 +- docs/client/{ => transport}/session_test.go | 8 +++++++- docs/client/{ => transport}/transport.go | 2 +- 7 files changed, 17 insertions(+), 10 deletions(-) rename docs/client/{ => transport}/authchallenge.go (99%) rename docs/client/{ => transport}/authchallenge_test.go (98%) rename docs/client/{ => transport}/http_reader.go (99%) rename docs/client/{ => transport}/session.go (99%) rename docs/client/{ => transport}/session_test.go (97%) rename docs/client/{ => transport}/transport.go (99%) diff --git a/docs/client/repository.go b/docs/client/repository.go index 61dcf0f4..788e7904 100644 --- a/docs/client/repository.go +++ b/docs/client/repository.go @@ -18,16 +18,17 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/context" "github.com/docker/distribution/registry/api/v2" + "github.com/docker/distribution/registry/client/transport" "github.com/docker/distribution/registry/storage/cache" ) -// NewRepository creates a new Repository for the given repository name and endpoint -func NewRepository(ctx context.Context, name, endpoint string, transport http.RoundTripper) (distribution.Repository, error) { +// NewRepository creates a new Repository for the given repository name and base URL +func NewRepository(ctx context.Context, name, baseURL string, transport http.RoundTripper) (distribution.Repository, error) { if err := v2.ValidateRespositoryName(name); err != nil { return nil, err } - ub, err := v2.NewURLBuilderFromString(endpoint) + ub, err := v2.NewURLBuilderFromString(baseURL) if err != nil { return nil, err } @@ -292,7 +293,7 @@ func (ls *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.Rea return nil, err } - return NewHTTPReadSeeker(ls.repository.client, blobURL, stat.Length), nil + return transport.NewHTTPReadSeeker(ls.repository.client, blobURL, stat.Length), nil } func (ls *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error { diff --git a/docs/client/authchallenge.go b/docs/client/transport/authchallenge.go similarity index 99% rename from docs/client/authchallenge.go rename to docs/client/transport/authchallenge.go index 49cf270e..fffd560b 100644 --- a/docs/client/authchallenge.go +++ b/docs/client/transport/authchallenge.go @@ -1,4 +1,4 @@ -package client +package transport import ( "net/http" diff --git a/docs/client/authchallenge_test.go b/docs/client/transport/authchallenge_test.go similarity index 98% rename from docs/client/authchallenge_test.go rename to docs/client/transport/authchallenge_test.go index 802c94f3..45c932b9 100644 --- a/docs/client/authchallenge_test.go +++ b/docs/client/transport/authchallenge_test.go @@ -1,4 +1,4 @@ -package client +package transport import ( "net/http" diff --git a/docs/client/http_reader.go b/docs/client/transport/http_reader.go similarity index 99% rename from docs/client/http_reader.go rename to docs/client/transport/http_reader.go index 22f9bfbc..de728a96 100644 --- a/docs/client/http_reader.go +++ b/docs/client/transport/http_reader.go @@ -1,4 +1,4 @@ -package client +package transport import ( "bufio" diff --git a/docs/client/session.go b/docs/client/transport/session.go similarity index 99% rename from docs/client/session.go rename to docs/client/transport/session.go index 41bb4f31..670be1ba 100644 --- a/docs/client/session.go +++ b/docs/client/transport/session.go @@ -1,4 +1,4 @@ -package client +package transport import ( "encoding/json" diff --git a/docs/client/session_test.go b/docs/client/transport/session_test.go similarity index 97% rename from docs/client/session_test.go rename to docs/client/transport/session_test.go index cf8e546e..374d6e79 100644 --- a/docs/client/session_test.go +++ b/docs/client/transport/session_test.go @@ -1,4 +1,4 @@ -package client +package transport import ( "encoding/base64" @@ -11,6 +11,12 @@ import ( "github.com/docker/distribution/testutil" ) +func testServer(rrm testutil.RequestResponseMap) (string, func()) { + h := testutil.NewHandler(rrm) + s := httptest.NewServer(h) + return s.URL, s.Close +} + type testAuthenticationWrapper struct { headers http.Header authCheck func(string) bool diff --git a/docs/client/transport.go b/docs/client/transport/transport.go similarity index 99% rename from docs/client/transport.go rename to docs/client/transport/transport.go index 0b241619..c8cfbb19 100644 --- a/docs/client/transport.go +++ b/docs/client/transport/transport.go @@ -1,4 +1,4 @@ -package client +package transport import ( "io"